|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.cache.lock.IdentityLock
public class 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(IsolationLevel level)
For testing only |
|
IdentityLock(TreeCache cache)
Constructs a new lock. |
|
IdentityLock(TreeCache cache,
Fqn fqn)
Constructs a new lock. |
Method Summary | |
---|---|
boolean |
acquireReadLock(java.lang.Object caller,
long timeout)
Acquire a read lock with a timeout period of timeout milliseconds. |
boolean |
acquireWriteLock(java.lang.Object caller,
long timeout)
Acquire a write lock with a timeout of timeout milliseconds. |
Fqn |
getFqn()
Returns the FQN for this lock, may be null . |
java.util.Set |
getReaderOwners()
Return a copy of the reader lock owner in List. |
java.lang.Object |
getWriterOwner()
Return the writer lock owner object. |
boolean |
isLocked()
Check if there is a read or write lock |
boolean |
isOwner(java.lang.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(java.lang.Object caller)
Release the lock held by the owner. |
void |
releaseAll()
Release all locks associated with this instance. |
void |
releaseForce()
Same as releaseAll now. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean print_lock_details)
|
void |
toString(java.lang.StringBuffer sb)
|
void |
toString(java.lang.StringBuffer sb,
boolean print_lock_details)
|
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)
cache
- cache for deciding lock strategyfqn
- ignored.public IdentityLock(TreeCache cache)
cache
- cache for deciding lock strategy
TODO remove this constructorpublic IdentityLock(IsolationLevel level)
Method Detail |
---|
public Fqn getFqn()
null
.
public java.util.Set getReaderOwners()
public java.lang.Object getWriterOwner()
public boolean acquireWriteLock(java.lang.Object caller, long timeout) throws LockingException, TimeoutException, java.lang.InterruptedException
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.
caller
- Can't be null.timeout
-
LockingException
TimeoutException
java.lang.InterruptedException
public boolean acquireReadLock(java.lang.Object caller, long timeout) throws LockingException, TimeoutException, java.lang.InterruptedException
timeout
milliseconds.
caller
- Can't be null.timeout
-
LockingException
TimeoutException
java.lang.InterruptedException
public void release(java.lang.Object caller)
caller
- Can't be null.public void releaseAll()
public void releaseForce()
public boolean isReadLocked()
public boolean isWriteLocked()
public boolean isLocked()
public boolean isOwner(java.lang.Object o)
o
- public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean print_lock_details)
public void toString(java.lang.StringBuffer sb)
public void toString(java.lang.StringBuffer sb, boolean print_lock_details)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |