org.eclipse.net4j.util.concurrent
Class RWOLockManager<OBJECT,CONTEXT>

java.lang.Object
  extended by org.eclipse.net4j.util.event.Notifier
      extended by org.eclipse.net4j.util.lifecycle.Lifecycle
          extended by org.eclipse.net4j.util.concurrent.RWOLockManager<OBJECT,CONTEXT>
All Implemented Interfaces:
IRWLockManager<OBJECT,CONTEXT>, IRWOLockManager<OBJECT,CONTEXT>, INotifier, 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 repsonsible for deciding whether or not a new lock can be granted, based on the locks already present.

Since:
3.2

Nested Class Summary
static class RWOLockManager.LockState<OBJECT,CONTEXT>
          Represents a combination of locks for one OBJECT.
 
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.concurrent.IRWLockManager
IRWLockManager.LockType
 
Nested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle
ILifecycle.DeferrableActivation
 
Field Summary
 
Fields inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle
USE_LABEL
 
Fields inherited from interface org.eclipse.net4j.util.concurrent.IRWLockManager
NO_WAIT, WAIT
 
Constructor Summary
RWOLockManager()
           
 
Method Summary
protected  void changeContext(CONTEXT oldContext, CONTEXT newContext)
           
protected  Map<CONTEXT,Set<RWOLockManager.LockState<OBJECT,CONTEXT>>> createContextToLocksMap()
           
protected  Map<OBJECT,RWOLockManager.LockState<OBJECT,CONTEXT>> createObjectToLocksMap()
           
protected  long currentTimeMillis()
           
protected  Map<CONTEXT,Set<RWOLockManager.LockState<OBJECT,CONTEXT>>> getContextToLocksMap()
          All access to the returned map must be properly synchronized on this RWOLockManager.
 RWOLockManager.LockState<OBJECT,CONTEXT> getLockState(OBJECT key)
           
protected  Map<OBJECT,RWOLockManager.LockState<OBJECT,CONTEXT>> getObjectToLocksMap()
          All access to the returned map must be properly synchronized on this RWOLockManager.
 boolean hasLock(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock)
           
 boolean hasLockByOthers(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock)
           
 void lock(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout)
           
 void lock(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock, long timeout)
           
 List<RWOLockManager.LockState<OBJECT,CONTEXT>> lock2(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToLock, long timeout)
          Adds locks of the given type, owned by the given context on the given objects.
 void setLockState(OBJECT key, RWOLockManager.LockState<OBJECT,CONTEXT> lockState)
           
 void unlock(CONTEXT context)
          Attempts to release all locks(read and write) for a given context.
 void unlock(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock)
          Attempts to release for a given locktype, context and objects.
 List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(CONTEXT context)
          Removes all locks owned by the given context on any objects.
 List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(CONTEXT context, Collection<? extends OBJECT> objectsToUnlock)
          Removes all locks owned by the given context.
 List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(IRWLockManager.LockType type, CONTEXT context, Collection<? extends OBJECT> objectsToUnlock)
          Removes all locks of the given type, owned by the given context on the given objects.
 
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, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListeners, lastListenerRemoved, 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
 

Constructor Detail

RWOLockManager

public RWOLockManager()
Method Detail

lock

public void lock(IRWLockManager.LockType type,
                 CONTEXT context,
                 Collection<? extends OBJECT> objectsToLock,
                 long timeout)
          throws InterruptedException
Specified by:
lock in interface IRWLockManager<OBJECT,CONTEXT>
Throws:
InterruptedException

lock2

public List<RWOLockManager.LockState<OBJECT,CONTEXT>> lock2(IRWLockManager.LockType type,
                                                            CONTEXT context,
                                                            Collection<? extends OBJECT> objectsToLock,
                                                            long timeout)
                                                     throws InterruptedException
Description copied from interface: IRWOLockManager
Adds locks of the given type, owned by the given context on the given objects.

Specified by:
lock2 in interface IRWOLockManager<OBJECT,CONTEXT>
Throws:
InterruptedException

lock

public void lock(IRWLockManager.LockType type,
                 CONTEXT context,
                 OBJECT objectToLock,
                 long timeout)
          throws InterruptedException
Specified by:
lock in interface IRWLockManager<OBJECT,CONTEXT>
Throws:
InterruptedException

unlock

public void unlock(IRWLockManager.LockType type,
                   CONTEXT context,
                   Collection<? extends OBJECT> objectsToUnlock)
Description copied from interface: IRWLockManager
Attempts to release for a given locktype, context and objects.

Specified by:
unlock in interface IRWLockManager<OBJECT,CONTEXT>

unlock2

public List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(CONTEXT context,
                                                              Collection<? extends OBJECT> objectsToUnlock)
Description copied from interface: IRWOLockManager
Removes all locks owned by the given context.

Specified by:
unlock2 in interface IRWOLockManager<OBJECT,CONTEXT>

unlock2

public List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(IRWLockManager.LockType type,
                                                              CONTEXT context,
                                                              Collection<? extends OBJECT> objectsToUnlock)
Description copied from interface: IRWOLockManager
Removes all locks of the given type, owned by the given context on the given objects.

Specified by:
unlock2 in interface IRWOLockManager<OBJECT,CONTEXT>

unlock

public void unlock(CONTEXT context)
Description copied from interface: IRWLockManager
Attempts to release all locks(read and write) for a given context.

Specified by:
unlock in interface IRWLockManager<OBJECT,CONTEXT>

unlock2

public List<RWOLockManager.LockState<OBJECT,CONTEXT>> unlock2(CONTEXT context)
Description copied from interface: IRWOLockManager
Removes all locks owned by the given context on any objects.

Specified by:
unlock2 in interface IRWOLockManager<OBJECT,CONTEXT>

hasLock

public boolean hasLock(IRWLockManager.LockType type,
                       CONTEXT context,
                       OBJECT objectToLock)
Specified by:
hasLock in interface IRWLockManager<OBJECT,CONTEXT>

hasLockByOthers

public boolean hasLockByOthers(IRWLockManager.LockType type,
                               CONTEXT context,
                               OBJECT objectToLock)
Specified by:
hasLockByOthers in interface IRWLockManager<OBJECT,CONTEXT>

changeContext

protected void changeContext(CONTEXT oldContext,
                             CONTEXT newContext)

currentTimeMillis

protected long currentTimeMillis()

createObjectToLocksMap

protected Map<OBJECT,RWOLockManager.LockState<OBJECT,CONTEXT>> createObjectToLocksMap()

createContextToLocksMap

protected Map<CONTEXT,Set<RWOLockManager.LockState<OBJECT,CONTEXT>>> createContextToLocksMap()

getObjectToLocksMap

protected final Map<OBJECT,RWOLockManager.LockState<OBJECT,CONTEXT>> getObjectToLocksMap()
All access to the returned map must be properly synchronized on this RWOLockManager.


getContextToLocksMap

protected final Map<CONTEXT,Set<RWOLockManager.LockState<OBJECT,CONTEXT>>> getContextToLocksMap()
All access to the returned map must be properly synchronized on this RWOLockManager.


getLockState

public RWOLockManager.LockState<OBJECT,CONTEXT> getLockState(OBJECT key)

setLockState

public void setLockState(OBJECT key,
                         RWOLockManager.LockState<OBJECT,CONTEXT> lockState)


Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) and others.