|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.cache.lock.IdentityLock
Lock object which grants and releases locks, and associates locks with owners. The methods to acquire and release a lock require an owner (Object). When a lock is acquired, we store the current owner with the lock. When the same owner (but possibly running in a different thread) wants to acquire the lock, it is immediately granted. When an owner different from the one currently owning the lock wants to release the lock, we do nothing (no-op).
Consider the following example:
FIFOSemaphore lock=new FIFOSemaphore(1); lock.acquire(); lock.acquire(); lock.release();This would block on the second acquire() (although we currently already hold the lock) because the lock only has 1 permit. So IdentityLock will allow the following code to work properly:
IdentityLock lock=new IdentityLock(); lock.readLock().acquire(this, timeout); lock.writeLock().acquire(this, timeout); lock.release(this);If the owner is null, then the current thread is taken by default. This allow the following code to work:
IdentityLock lock=new IdentityLock(); lock.readLock().attempt(null, timeout); lock.writeLock().attempt(null, timeout); lock.release(null);
Object.equals(java.lang.Object)
. For
a use case see the examples in the testsuite.
Constructor Summary | |
IdentityLock(TreeCache cache,
Fqn fqn)
|
Method Summary | |
boolean |
acquireReadLock(Object owner,
long timeout)
Acquire a read lock with a timeout period of timeout milliseconds. |
boolean |
acquireWriteLock(Object owner,
long timeout)
Acquire a write lock with a timeout of timeout milliseconds. |
Fqn |
getFqn()
|
List |
getReaderOwners()
Return a copy of the reader lock owner in List. |
Object |
getWriterOwner()
Return the writer lock owner object. |
boolean |
isLocked()
Check if there is a read or write lock |
boolean |
isOwner(Object o)
Am I a lock owner? |
boolean |
isReadLocked()
Check if there is a read lock. |
boolean |
isWriteLocked()
Check if there is a write lock. |
void |
release(Object owner)
Release the lock held by the owner. |
void |
releaseAll()
Release all locks associated with this instance. |
void |
releaseForce()
Same as releaseAll now. |
String |
toString()
|
void |
toString(StringBuffer sb)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public IdentityLock(TreeCache cache, Fqn fqn)
Method Detail |
public Fqn getFqn()
public List getReaderOwners()
public Object getWriterOwner()
public boolean acquireWriteLock(Object owner, long timeout) throws LockingException, TimeoutException
timeout
milliseconds.
Note that if the current owner owns a read lock, it will be upgraded
automatically. However, if upgrade fails, i.e., timeout, the read lock will
be released automatically.
owner
- Can't be null.timeout
-
LockingException
TimeoutException
public boolean acquireReadLock(Object owner, long timeout) throws LockingException, TimeoutException
timeout
milliseconds.
owner
- Can't be null.timeout
-
LockingException
TimeoutException
public void release(Object owner)
owner
- Can't be null.public void releaseAll()
public void releaseForce()
public boolean isReadLocked()
public boolean isWriteLocked()
public boolean isLocked()
public boolean isOwner(Object o)
o
-
public String toString()
public void toString(StringBuffer sb)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |