Package org.eclipse.net4j.util.concurrent

## 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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `RWOLockManager.LockState<OBJECT,​CONTEXT>` | 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`

  - ### 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

    Constructors
    Constructor | Description
    --- | ---
    `RWOLockManager()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected void` | `changeContext​(CONTEXT oldContext, CONTEXT newContext)` |
    `protected java.util.Map<CONTEXT,​java.util.Set<RWOLockManager.LockState<OBJECT,​CONTEXT>>>` | `createContextToLocksMap()` |
    `protected java.util.Map<OBJECT,​RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `createObjectToLocksMap()` |
    `protected long` | `currentTimeMillis()` |
    `protected java.util.Map<CONTEXT,​java.util.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)` |
    `java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `getLockStates()` |
    `protected java.util.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, java.util.Collection<? extends OBJECT> objectsToLock, long timeout)` |
    `void` | `lock​(IRWLockManager.LockType type, CONTEXT context, OBJECT objectToLock, long timeout)` |
    `java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `lock2​(IRWLockManager.LockType type, CONTEXT context, java.util.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)` |
    `static void` | `setUnlockAll​(boolean on)` |
    `void` | `unlock​(CONTEXT context)` | Attempts to release all locks(read and write) for a given context.
    `void` | `unlock​(IRWLockManager.LockType type, CONTEXT context, java.util.Collection<? extends OBJECT> objectsToUnlock)` | Attempts to release for a given locktype, context and objects.
    `java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `unlock2​(CONTEXT context)` | Removes all locks owned by the given context on any objects.
    `java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `unlock2​(CONTEXT context, java.util.Collection<? extends OBJECT> objectsToUnlock)` | Removes all locks owned by the given context.
    `java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>>` | `unlock2​(IRWLockManager.LockType type, CONTEXT context, java.util.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, 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`

- - ### Constructor Detail

    - #### RWOLockManager

          public RWOLockManager()

  - ### Method Detail

    - #### lock

          public void lock​(IRWLockManager.LockType type,
                           CONTEXT context,
                           java.util.Collection<? extends OBJECT> objectsToLock,
                           long timeout)
                    throws java.lang.InterruptedException

      Specified by:
        `lock` in interface `IRWLockManager<OBJECT,​CONTEXT>`
      Throws:
        `java.lang.InterruptedException`

    - #### lock2

          public java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>> lock2​(IRWLockManager.LockType type,
                                                                                      CONTEXT context,
                                                                                      java.util.Collection<? extends OBJECT> objectsToLock,
                                                                                      long timeout)
                                                                               throws java.lang.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:
        `java.lang.InterruptedException`

    - #### lock

          public void lock​(IRWLockManager.LockType type,
                           CONTEXT context,
                           OBJECT objectToLock,
                           long timeout)
                    throws java.lang.InterruptedException

      Specified by:
        `lock` in interface `IRWLockManager<OBJECT,​CONTEXT>`
      Throws:
        `java.lang.InterruptedException`

    - #### unlock

          public void unlock​(IRWLockManager.LockType type,
                             CONTEXT context,
                             java.util.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 java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>> unlock2​(CONTEXT context,
                                                                                        java.util.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 java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>> unlock2​(IRWLockManager.LockType type,
                                                                                        CONTEXT context,
                                                                                        java.util.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 java.util.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 java.util.Map<OBJECT,​RWOLockManager.LockState<OBJECT,​CONTEXT>> createObjectToLocksMap()

    - #### createContextToLocksMap

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

    - #### getObjectToLocksMap

          protected final java.util.Map<OBJECT,​RWOLockManager.LockState<OBJECT,​CONTEXT>> getObjectToLocksMap()

      All access to the returned map must be properly synchronized on this `RWOLockManager`.

    - #### getContextToLocksMap

          protected final java.util.Map<CONTEXT,​java.util.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)

    - #### getLockStates

          public java.util.List<RWOLockManager.LockState<OBJECT,​CONTEXT>> getLockStates()

      Since:
        3.5

    - #### setLockState

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

    - #### setUnlockAll

          public static void setUnlockAll​(boolean on)

      Since:
        3.7