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, 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 and 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.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

    Constructors
    Constructor and Description
    `RWOLockManager()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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)`
    `List<RWOLockManager.LockState<OBJECT,CONTEXT>>` | `getLockStates()`
    `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)`
    `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, 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)

    - #### getLockStates

          public 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

Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html