commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Hamid <ar...@cornell.edu>
Subject Transaction API, GenericLock, FileResourceManager
Date Fri, 24 Jun 2005 15:56:01 GMT
Hi all,

  I suspect I just reimplemented FileResourceManager, because I was not aware of it until
recently (despite using the org.apache.commons.transaction.locking package).  Basically I
created a hierarchical Node interface, with operations like: children() and read(), which
implicitly obtain a readlock; write(), which upgrades to a write lock; and close() which releases
the locks.

First, I'm wondering if there is a way to list a directory through the API, which itself requires
a read lock, or whether I must explicitly obtain the lock, and then perform the listing externally
(which is cumbersome).

Also, I'm curious as to the significance of the "owner" parameter to the lock API.  For instance,
I keep lock objects as a member field of Node implementations, using the unique path as a
resource id:

public class NodeImpl {
  private ReadWriteLock lock;
  private Node parent;
  public NodeImpl(Node parent, Path path, Store store) {
    lock = new ReadWriteLock(new StorePath(store, path), null);
  }
  public void open() {
    // should I send 'this' as owner?
    lock.acquireRead(this, Long.MAX_VALUE);
  }
  public void openForWriting() {
    // should I send 'this' as owner?
    lock.acquireWrite(this, Long.MAX_VALUE);
  }
  public void write() {
    parent.openForWriting();
    this.openForWriting();
    // .. do some writing ..
  }
  public void close() {
    lock.release();
  }
}

Now...what should the value of the "owner" object be?  Should it naively be the 'this' object?
 Or should it be the Thread.currentThread(), or is it completely irrelevant and only for informational
purposes?  As you can see, to perform any writing, I must also lock the parent node (for instance,
if the write creates a new file...we can't allow reads/listings to be happening).  However,
the parent node, in this implementation, will obtain the lock with an owner value of itself.
 Now, I intend Node usage to only be single-threaded anyway (the strategy being other threads
would obtain a distinct node object, and not share node objects accross threads)...but in
any case, is this still legitimate, or should I be obtaining the parent lock with some /other/
value of owner?  If I used distinct owners with that prevent the child not from acquiring
the lock, even though it is in its own thread?  The semantics of "owner" don't seem to be
very well documented.

Aaron

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message