Class RWOLockManager<OBJECT,CONTEXT>
java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.net4j.util.concurrent.RWOLockManager<OBJECT,CONTEXT>
- All Implemented Interfaces:
IRWLockManager<OBJECT,
,CONTEXT> IRWOLockManager<OBJECT,
,CONTEXT> INotifier
,INotifier.INotifier2
,IDeactivateable
,ILifecycle
,ILifecycle.DeferrableActivation
public class RWOLockManager<OBJECT,CONTEXT>
extends Lifecycle
implements IRWOLockManager<OBJECT,CONTEXT>
Keeps track of locks on objects. Locks are owned by contexts. A particular combination of locks and their owners, for
a given object, is represented by instances of the
RWOLockManager.LockState
class. This class is also responsible for
deciding whether or not a new lock can be granted, based on the locks already present.- Since:
- 3.2
- Author:
- Caspar De Groot, Eike Stepper
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Represents a combination of locks for one OBJECT.Nested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle
ILifecycle.DeferrableActivation
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier
INotifier.INotifier2
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.concurrent.IRWLockManager
IRWLockManager.LockType
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.concurrent.IRWOLockManager
IRWOLockManager.LockDeltaHandler<OBJECT,
CONTEXT> -
Field Summary
Modifier and TypeFieldDescriptionprotected final Access
protected final ReentrantReadWriteAccess
protected final Access
Fields inherited from interface org.eclipse.net4j.util.concurrent.IRWLockManager
NO_WAIT, WAIT
Fields inherited from interface org.eclipse.net4j.util.concurrent.IRWOLockManager
ALL_LOCK_TYPES, ALL_LOCKS, ALL_OBJECTS, NO_TIMEOUT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
changeContext
(CONTEXT oldContext, CONTEXT newContext) protected Map<OBJECT,
RWOLockManager.LockState<OBJECT, CONTEXT>> protected long
All access to the returned map must be properly synchronized on thisRWOLockManager
.getLockState
(OBJECT key) Deprecated.void
getLockStates
(Collection<OBJECT> keys, BiConsumer<OBJECT, RWOLockManager.LockState<OBJECT, CONTEXT>> consumer) void
getLockStates
(Consumer<RWOLockManager.LockState<OBJECT, CONTEXT>> consumer) long
protected final Map<OBJECT,
RWOLockManager.LockState<OBJECT, CONTEXT>> All access to the returned map must be properly synchronized on thisRWOLockManager
.boolean
hasLock
(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock) boolean
hasLockByOthers
(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock) long
lock
(CONTEXT context, Collection<? extends OBJECT> objects, IRWLockManager.LockType lockType, int count, long timeout, IRWOLockManager.LockDeltaHandler<OBJECT, CONTEXT> deltaHandler, Consumer<RWOLockManager.LockState<OBJECT, CONTEXT>> stateHandler) Adds locks of the given lockType, owned by the given context to the given objects.void
lock
(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout) Deprecated.void
lock
(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock, long timeout) Deprecated.lock2
(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout) Deprecated.void
setLockState
(OBJECT key, RWOLockManager.LockState<OBJECT, CONTEXT> lockState) Deprecated.static void
setUnlockAll
(boolean on) Deprecated.void
Deprecated.long
unlock
(CONTEXT context, Collection<? extends OBJECT> objects, IRWLockManager.LockType lockType, int count, IRWOLockManager.LockDeltaHandler<OBJECT, CONTEXT> deltaHandler, Consumer<RWOLockManager.LockState<OBJECT, CONTEXT>> stateHandler) Removes locks of the given lockType, owned by the given context from the given objects.void
unlock
(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.Deprecated.unlock2
(CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.unlock2
(IRWLockManager.LockType lockType, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.Methods inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle
activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doActivate, doAfterActivate, doBeforeActivate, doBeforeDeactivate, doDeactivate, dump, getLifecycleState, isActive, isDeferredActivation, toString
Methods inherited from class org.eclipse.net4j.util.event.Notifier
addListener, addUniqueListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.net4j.util.event.INotifier
addListener, getListeners, hasListeners, removeListener
-
Field Details
-
rwAccess
- Since:
- 3.16
-
read
- Since:
- 3.16
-
write
- Since:
- 3.16
-
-
Constructor Details
-
RWOLockManager
public RWOLockManager()
-
-
Method Details
-
getModCount
public long getModCount()- Specified by:
getModCount
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Category
- Read Access
-
lock
public long lock(CONTEXT context, Collection<? extends OBJECT> objects, IRWLockManager.LockType lockType, int count, long timeout, IRWOLockManager.LockDeltaHandler<OBJECT, CONTEXT> deltaHandler, Consumer<RWOLockManager.LockState<OBJECT, throws InterruptedException, TimeoutRuntimeExceptionCONTEXT>> stateHandler) Description copied from interface:IRWOLockManager
Adds locks of the given lockType, owned by the given context to the given objects.- Specified by:
lock
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Parameters:
context
- The lock context to add from theobjects
. Must not benull
.objects
- The objects to lock. Must not benull
.lockType
- The type of lock to add to theobjects
. Must not benull
.count
- The number of locks to add to each of theobjects
.timeout
- The period in milliseconds after that aTimeoutRuntimeException
is thrown if some or all of theobjects
could not be locked, orIRWOLockManager.NO_TIMEOUT
to attempt forever to acquire the requested locks.deltaHandler
- A handler that is notified with each delta in alock state
, ornull
if no such notification is needed. The handler is notified at most once per delta, but it can happen that the handler is notified before the lock operation finally fails with one of the specified exceptions. The notification handling should be fast because notifications occur while the calling thread is synchronized on this lock manager.stateHandler
- A handler that is notified with each newlock state
, ornull
if no such notification is needed.. The handler is notified at most once per lock state, but it can happen that the handler is notified before the lock operation finally fails with one of the specified exceptions. The notification handling should be fast because notifications occur while the calling thread is synchronized on this lock manager.- Returns:
- The new
modification count
. - Throws:
InterruptedException
- If the calling thread is interrupted.TimeoutRuntimeException
- If the timeout period has expired and some or all of theobjects
could not be locked.- Since:
- 3.16
- Category
- Write Access
-
unlock
public long unlock(CONTEXT context, Collection<? extends OBJECT> objects, IRWLockManager.LockType lockType, int count, IRWOLockManager.LockDeltaHandler<OBJECT, CONTEXT> deltaHandler, Consumer<RWOLockManager.LockState<OBJECT, CONTEXT>> stateHandler) Description copied from interface:IRWOLockManager
Removes locks of the given lockType, owned by the given context from the given objects.- Specified by:
unlock
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Parameters:
context
- The lock context to remove from theobjects
. Must not benull
.objects
- The objects to unlock, orIRWOLockManager.ALL_OBJECTS
to unlock all objects of thecontext
.lockType
- The type of lock to remove from theobjects
, orIRWOLockManager.ALL_LOCK_TYPES
to remove the locks of all types.count
- The number of locks to remove from each of theobjects
, orIRWOLockManager.ALL_LOCKS
to remove all locks.deltaHandler
- A handler that is notified with each delta in aRWOLockManager.LockState
, ornull
if no such notification is needed.stateHandler
- A handler that is notified with each newRWOLockManager.LockState
, ornull
if no such notification is needed.- Category
- Write Access
-
hasLock
- Specified by:
hasLock
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Category
- Read Access
-
hasLockByOthers
- Specified by:
hasLockByOthers
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Category
- Read Access
-
getLockState
- Category
- Read Access
-
getLockStates
public void getLockStates(Collection<OBJECT> keys, BiConsumer<OBJECT, RWOLockManager.LockState<OBJECT, CONTEXT>> consumer) - Since:
- 3.16
- Category
- Read Access
-
getLockStates
- Since:
- 3.16
- Category
- Read Access
-
changeContext
-
getObjectToLocksMap
All access to the returned map must be properly synchronized on thisRWOLockManager
. -
getContextToLocksMap
All access to the returned map must be properly synchronized on thisRWOLockManager
. -
createObjectToLocksMap
-
createContextToLocksMap
-
currentTimeMillis
protected long currentTimeMillis() -
getLockStates
Deprecated. -
setLockState
@Deprecated public void setLockState(OBJECT key, RWOLockManager.LockState<OBJECT, CONTEXT> lockState) Deprecated.- Category
- Write Access
-
lock
@Deprecated public void lock(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout) throws InterruptedException Deprecated.- Specified by:
lock
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Specified by:
lock
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Throws:
InterruptedException
-
lock2
@Deprecated public List<RWOLockManager.LockState<OBJECT,CONTEXT>> lock2(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout) throws InterruptedException Deprecated.- Specified by:
lock2
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Throws:
InterruptedException
-
lock
@Deprecated public void lock(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock, long timeout) throws InterruptedException Deprecated.- Specified by:
lock
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Specified by:
lock
in interfaceIRWOLockManager<OBJECT,
CONTEXT> - Throws:
InterruptedException
-
unlock
@Deprecated public void unlock(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.Description copied from interface:IRWLockManager
Attempts to release for a given lock type, context and objects.- Specified by:
unlock
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Specified by:
unlock
in interfaceIRWOLockManager<OBJECT,
CONTEXT>
-
unlock
Deprecated.Description copied from interface:IRWLockManager
Attempts to release all locks(read and write) for a given context.- Specified by:
unlock
in interfaceIRWLockManager<OBJECT,
CONTEXT> - Specified by:
unlock
in interfaceIRWOLockManager<OBJECT,
CONTEXT>
-
unlock2
Deprecated.- Specified by:
unlock2
in interfaceIRWOLockManager<OBJECT,
CONTEXT>
-
unlock2
@Deprecated public List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.- Specified by:
unlock2
in interfaceIRWOLockManager<OBJECT,
CONTEXT>
-
unlock2
@Deprecated public List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(IRWLockManager.LockType lockType, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock) Deprecated.- Specified by:
unlock2
in interfaceIRWOLockManager<OBJECT,
CONTEXT>
-
setUnlockAll
Deprecated.
-