@Deprecated public class IdentityLock extends Object implements NodeLock
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 and Description |
---|
IdentityLock(LockStrategyFactory factory,
NodeSPI node)
Deprecated.
Creates a new IdentityLock using the LockFactory passed in.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquire(Object caller,
long timeout,
LockType lock_type)
Deprecated.
|
Set<NodeLock> |
acquireAll(Object caller,
long timeout,
LockType lock_type)
Deprecated.
Recursively acquire locks for this node and all subnodes, including internal Fqns such as buddy backup subtrees.
|
Set<NodeLock> |
acquireAll(Object caller,
long timeout,
LockType lock_type,
boolean excludeInternalFqns)
Deprecated.
Same as the overloaded
NodeLock.acquire(Object, long, LockType) except that you can
optionally specify that internal Fqns - such as buddy backup subtrees - can be excluded when acquiring locks. |
boolean |
acquireReadLock(Object caller,
long timeout)
Deprecated.
Acquire a read lock with a timeout period of
timeout milliseconds. |
boolean |
acquireWriteLock(Object caller,
long timeout)
Deprecated.
Acquire a write lock with a timeout of
timeout milliseconds. |
Fqn |
getFqn()
Deprecated.
Returns the FQN this lock, may be
null . |
LockMap |
getLockMap()
Deprecated.
|
Node |
getNode()
Deprecated.
Returns the node for this lock, may be
null . |
Collection<Object> |
getReaderOwners()
Deprecated.
Return a copy of the reader lock owner in List.
|
Object |
getWriterOwner()
Deprecated.
Return the writer lock owner object.
|
boolean |
isLocked()
Deprecated.
Check if there is a read or write lock
|
boolean |
isOwner(Object o)
Deprecated.
Am I a lock owner?
|
boolean |
isReadLocked()
Deprecated.
Check if there is a read lock.
|
boolean |
isWriteLocked()
Deprecated.
Check if there is a write lock.
|
void |
printLockInfo(StringBuilder sb,
int indent)
Deprecated.
|
void |
release(Object caller)
Deprecated.
Release the lock held by the owner.
|
void |
releaseAll()
Deprecated.
Release all locks associated with this instance.
|
void |
releaseAll(Object owner)
Deprecated.
Releases all locks with this owner.
|
void |
releaseForce()
Deprecated.
Same as releaseAll now.
|
String |
toString()
Deprecated.
|
String |
toString(boolean print_lock_details)
Deprecated.
|
void |
toString(StringBuilder sb)
Deprecated.
|
void |
toString(StringBuilder sb,
boolean print_lock_details)
Deprecated.
|
public IdentityLock(LockStrategyFactory factory, NodeSPI node)
factory
- to create lock strategiesnode
- to lockpublic Node getNode()
null
.public Fqn getFqn()
null
.public Collection<Object> getReaderOwners()
getReaderOwners
in interface NodeLock
public Object getWriterOwner()
getWriterOwner
in interface NodeLock
public LockMap getLockMap()
public boolean acquireWriteLock(Object caller, long timeout) throws LockingException, TimeoutException, 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
InterruptedException
public boolean acquireReadLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException
timeout
milliseconds.acquireReadLock
in interface NodeLock
caller
- Can't be null.timeout
- LockingException
TimeoutException
InterruptedException
public void release(Object caller)
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()
public boolean isOwner(Object o)
public String toString(boolean print_lock_details)
public void toString(StringBuilder sb)
public void toString(StringBuilder sb, boolean print_lock_details)
public boolean acquire(Object caller, long timeout, LockType lock_type) throws LockingException, TimeoutException, InterruptedException
acquire
in interface NodeLock
LockingException
TimeoutException
InterruptedException
public Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type) throws LockingException, TimeoutException, InterruptedException
NodeLock
acquireAll
in interface NodeLock
caller
- lock ownertimeout
- time to waitlock_type
- type of lockLockingException
TimeoutException
InterruptedException
public Set<NodeLock> acquireAll(Object caller, long timeout, LockType lock_type, boolean excludeInternalFqns) throws LockingException, TimeoutException, InterruptedException
NodeLock
NodeLock.acquire(Object, long, LockType)
except that you can
optionally specify that internal Fqns - such as buddy backup subtrees - can be excluded when acquiring locks.acquireAll
in interface NodeLock
caller
- lock ownertimeout
- time to waitlock_type
- type of lockexcludeInternalFqns
- if true, locks on internal fqns are not acquired.LockingException
TimeoutException
InterruptedException
public void releaseAll(Object owner)
NodeLock
releaseAll
in interface NodeLock
public void printLockInfo(StringBuilder sb, int indent)
printLockInfo
in interface NodeLock
Copyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.