O - The type of the objects to be locked being compared with
Object.equals(Object).public class ObjectEqualityLockManager<O>
extends java.lang.Object
ObjectLockManager using
the current thread for locking and using object equality for the locked
objects.| Modifier and Type | Field and Description |
|---|---|
protected ObjectLockManager<O,java.lang.Thread> |
olm
The object lock manager to which all calls will be forwarded.
|
| Constructor and Description |
|---|
ObjectEqualityLockManager(java.lang.String lockType,
boolean optimistic,
java.util.logging.Logger logger)
Creates a new
ObjectLockManager using the current thread for
locking and using object equality for the locked objects. |
ObjectEqualityLockManager(java.lang.String lockType,
java.util.logging.Logger logger)
Creates a new
ObjectLockManager with pessimistic locking using
the current thread for locking and using object equality for the locked
objects. |
| Modifier and Type | Method and Description |
|---|---|
void |
getLockForObject(boolean writeLock,
O lockedObject)
Locks the designated object by the current thread.
|
void |
getLockForObject(boolean writeLock,
O lockedObject,
long timeout)
Locks the designated object by the current thread.
|
boolean |
hasLock(boolean writeLock,
O lockedObject)
Checks whether the designated object is locked for reading or writing by
the current thread.
|
void |
unlockObject(boolean writeLock,
O lockedObject)
Unlocks the designated object by the current thread.
|
protected final ObjectLockManager<O,java.lang.Thread> olm
public ObjectEqualityLockManager(java.lang.String lockType,
java.util.logging.Logger logger)
throws java.lang.reflect.InvocationTargetException
ObjectLockManager with pessimistic locking using
the current thread for locking and using object equality for the locked
objects.lockType - The type of locks managed by the created object. This is
for user information only.logger - The logger for log messages.java.lang.reflect.InvocationTargetException - If there are problems instantiating the
lock count manager or the reentrant lock, an
InvocationTargetException will be thrown. This
prevents problems at runtime when actually retrieving a lock
(which requires creating the corresponding objects).public ObjectEqualityLockManager(java.lang.String lockType,
boolean optimistic,
java.util.logging.Logger logger)
throws java.lang.reflect.InvocationTargetException
ObjectLockManager using the current thread for
locking and using object equality for the locked objects.lockType - The type of locks managed by the created object. This is
for user information only.optimistic - Whether to use optimistic locking which prevents
synchronisation but may create unneeded objects. This is suggested
with not much lock contention.logger - The logger for log messages.java.lang.reflect.InvocationTargetException - If there are problems instantiating the
lock count manager or the reentrant lock, an
InvocationTargetException will be thrown. This
prevents problems at runtime when actually retrieving a lock
(which requires creating the corresponding objects).public void getLockForObject(boolean writeLock,
O lockedObject)
throws java.lang.InterruptedException
writeLock - Whether to acquire a write lock.lockedObject - The object to lock.java.lang.InterruptedException - If the thread is interrupted while waiting for
the lock, an InterruptedException will be thrown.java.lang.RuntimeException - If the provided lock count manager can not be
instantiated, a RuntimeException will be thrown.public void getLockForObject(boolean writeLock,
O lockedObject,
long timeout)
throws java.lang.InterruptedException,
java.util.concurrent.TimeoutException
writeLock - Whether to acquire a write lock.lockedObject - The object to lock.timeout - The time to wait for the lock. A timeout <= 0 means to wait
forever (or until the lock is granted).java.lang.InterruptedException - If the thread is interrupted while waiting for
the lock, an InterruptedException will be thrown.java.util.concurrent.TimeoutException - If the designated timeout elapsed before the lock
can be acquired, a TimeoutException will be thrown.java.lang.RuntimeException - If the provided lock or the lock count manager can
not be instantiated, a RuntimeException will be
thrown.public boolean hasLock(boolean writeLock,
O lockedObject)
writeLock - Whether the locking object is to be checked for having a
write lock on the designated locked object.lockedObject - The object to check for the lock lock.public void unlockObject(boolean writeLock,
O lockedObject)
throws LockException
writeLock - Whether to release the write lock.lockedObject - The object to unlock.LockException - If the locked object has not locked at all or not by
the designated locking object, a LockException will
be thrown.