|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.transaction.locking.DefaultHierarchicalLockManager<M>
public class DefaultHierarchicalLockManager<M>
Default implementation of the HierarchicalLockManager.
It splits the path into segments and non-exclusively locks each segment
beginning from the root. The final segment - which is supposed to be the
resource to be locked itself - can either be locked exclusively or
non-exclusively. Too choose between the two, provide the flag in
lockInHierarchy(Object, String, boolean).
This implementation needs an ordinary lock manager that
it delegates all locking calls to.
This implementation is thread-safe.
| Constructor Summary | |
|---|---|
DefaultHierarchicalLockManager(String rootPath,
LockManager<Object,M> lm)
|
|
| Method Summary | |
|---|---|
void |
endWork()
Ends a block of work that has been started in LockManager.startWork(long, TimeUnit). |
void |
lock(M managedResource,
Object key,
boolean exclusive)
Locks a resource denoted by a key and a resource manager. |
void |
lockInHierarchy(M resourceManager,
String path,
boolean exclusive)
Locks a specific resource denoted by a resource manager it holds and a path. |
void |
startWork(long timeout,
TimeUnit unit)
Starts a block of work for which a certain set of locks is required. |
boolean |
tryLock(M managedResource,
Object key,
boolean exclusive)
Tries to acquire a lock on a resource denoted by a key and a resource manager. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultHierarchicalLockManager(String rootPath,
LockManager<Object,M> lm)
| Method Detail |
|---|
public void lockInHierarchy(M resourceManager,
String path,
boolean exclusive)
throws LockException
HierarchicalLockManager
lockInHierarchy in interface HierarchicalLockManager<Object,M>resourceManager - resource manager that tries to acquire a lockpath - the complete path to the resource to be lockedexclusive - true if this lock shall be acquired in
exclusive mode, false if it can be shared by
other threads
LockException - if the lock could not be acquired, possibly because of a
timeout or a deadlockpublic void endWork()
LockManagerLockManager.startWork(long, TimeUnit). All locks acquired will be released.
All registered locks will be unregistered from this lock manager.
endWork in interface LockManager<Object,M>
public void lock(M managedResource,
Object key,
boolean exclusive)
throws LockException
LockManager
lock in interface LockManager<Object,M>managedResource - resource manager that tries to acquire a lockkey - the key for the resource to be lockedexclusive - true if this lock shall be acquired in
exclusive mode, false if it can be shared by
other threads
LockException - if the lock could not be acquired, possibly because of a
timeout or a deadlock
public void startWork(long timeout,
TimeUnit unit)
LockManager
startWork in interface LockManager<Object,M>timeout - the maximum time for the whole work to take before it times
outunit - the time unit of the timeout argument
public boolean tryLock(M managedResource,
Object key,
boolean exclusive)
LockManager
tryLock in interface LockManager<Object,M>managedResource - resource manager that tries to acquire a lockkey - the key for the resource to be lockedexclusive - true if this lock shall be acquired in
exclusive mode, false if it can be shared by
other threads
true if the lock was acquired, false
otherwise
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||