|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.jboss.cache.lock.NodeLock |
---|
NodeLock.LockType |
Constructor Summary | |
---|---|
IdentityLock(IsolationLevel level,
NodeSPI node)
Creates a new IdentityLock based on the lock level in force. |
|
IdentityLock(NodeSPI node)
Creates a new Identity lock based on the lock level set in the LockStrategyFactory |
Method Summary | |
---|---|
boolean |
acquire(java.lang.Object caller,
long timeout,
NodeLock.LockType lock_type)
|
java.util.Set<NodeLock> |
acquireAll(java.lang.Object caller,
long timeout,
NodeLock.LockType lock_type)
Recursively acquire locks for this node and all subnodes. |
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 this lock, may be null . |
Node |
getNode()
Returns the node 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 |
printLockInfo(java.lang.StringBuffer sb,
int indent)
|
void |
release(java.lang.Object caller)
Release the lock held by the owner. |
void |
releaseAll()
Release all locks associated with this instance. |
void |
releaseAll(java.lang.Object owner)
Releases all locks with this owner. |
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(NodeSPI node)
LockStrategyFactory
public IdentityLock(IsolationLevel level, NodeSPI node)
level
- Method Detail |
---|
public Node getNode()
null
.
public Fqn getFqn()
null
.
public java.util.Set getReaderOwners()
getReaderOwners
in interface NodeLock
public java.lang.Object getWriterOwner()
getWriterOwner
in interface NodeLock
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.
acquireWriteLock
in interface NodeLock
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.
acquireReadLock
in interface NodeLock
caller
- Can't be null.timeout
-
LockingException
TimeoutException
java.lang.InterruptedException
public void release(java.lang.Object caller)
release
in interface NodeLock
caller
- Can't be null.public void releaseAll()
releaseAll
in interface NodeLock
public void releaseForce()
public boolean isReadLocked()
isReadLocked
in interface NodeLock
public boolean isWriteLocked()
isWriteLocked
in interface NodeLock
public boolean isLocked()
isLocked
in interface NodeLock
public boolean isOwner(java.lang.Object o)
isOwner
in interface NodeLock
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)
public boolean acquire(java.lang.Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, java.lang.InterruptedException
acquire
in interface NodeLock
LockingException
TimeoutException
java.lang.InterruptedException
public java.util.Set<NodeLock> acquireAll(java.lang.Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, java.lang.InterruptedException
NodeLock
acquireAll
in interface NodeLock
caller
- lock ownertimeout
- time to waitlock_type
- type of lock
LockingException
TimeoutException
java.lang.InterruptedException
public void releaseAll(java.lang.Object owner)
NodeLock
releaseAll
in interface NodeLock
public void printLockInfo(java.lang.StringBuffer sb, int indent)
printLockInfo
in interface NodeLock
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |