Package org.eclipse.net4j.util.concurrent

# Class DelegableReentrantLock

java.lang.Object
org.eclipse.net4j.util.concurrent.NonFairReentrantLock
org.eclipse.net4j.util.concurrent.DelegableReentrantLock

All Implemented Interfaces:
  `Serializable`, `Lock`, `IManagedContainerProvider`, `INotifier`, `IDeactivateable`, `ILifecycle`

public class DelegableReentrantLock extends NonFairReentrantLock implements ILifecycle, IManagedContainerProvider
A reentrant lock that can be delegated to other threads as detected by `delegate detectors`.

Delegate detectors can be registered programmatically or discovered in a `managed container`. The `plugin container` is used by default.

This class implements `ILifecycle` and must be `activated` before use. As a consequence, it also implements `INotifier`, but it does not send any events.

Since:
  3.6
Author:
  Eike Stepper
See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`DelegableReentrantLock.DelegateDetector`

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

## Constructor Summary

Constructors
Constructor
Description
`DelegableReentrantLock()`
Constructs a delegable reentrant lock that uses the `plugin container` to discover `delegate detectors`.
`DelegableReentrantLock(boolean usePluginContainer)`
Constructs a delegable reentrant lock that uses the `plugin container` to discover `delegate detectors` if the given flag is `true`.
`DelegableReentrantLock(IManagedContainer container)`
Constructs a delegable reentrant lock that uses the given `managed container` to discover `delegate detectors`.

## Method Summary

Modifier and Type
Method
Description
`final void`
`activate()`
`final void`
`addDelegateDetector(DelegableReentrantLock.DelegateDetector delegateDetector)`
`final void`
`addListener(IListener listener)`
Adds a listener to this notifier.
`final Exception`
`deactivate()`
`final IManagedContainer`
`getContainer()`
`final LifecycleState`
`getLifecycleState()`
`final IListener[]`
`getListeners()`
Returns the listeners that are registered with this notifier.
`final boolean`
`hasListeners()`
Returns `true` if one or more listeners are registered with this notifier, `false` otherwise.
`final boolean`
`isActive()`
`protected boolean`
`isDelegate(Thread thread, Thread owner)`
`protected boolean`
`isOwner(Thread thread, Thread owner)`
`final void`
`removeDelegateDetector(DelegableReentrantLock.DelegateDetector delegateDetector)`
`final void`
`removeListener(IListener listener)`
Removes a listener from this notifier.

### Methods inherited from class org.eclipse.net4j.util.concurrent.NonFairReentrantLock

`getHoldCount, getOwner, getQueuedThreads, getQueueLength, getWaitingThreads, getWaitQueueLength, hasQueuedThread, hasQueuedThreads, hasWaiters, isHeldByCurrentThread, isLocked, lock, lockInterruptibly, newCondition, toString, tryLock, tryLock, unlock`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### DelegableReentrantLock

public DelegableReentrantLock(IManagedContainer container)
Constructs a delegable reentrant lock that uses the given `managed container` to discover `delegate detectors`. If the given container is `null`, no container is used.

### DelegableReentrantLock

public DelegableReentrantLock(boolean usePluginContainer)
Constructs a delegable reentrant lock that uses the `plugin container` to discover `delegate detectors` if the given flag is `true`. Uses no container otherwise.

Since:
  3.29

### DelegableReentrantLock

public DelegableReentrantLock()
Constructs a delegable reentrant lock that uses the `plugin container` to discover `delegate detectors`.

## Method Details

### addDelegateDetector

public final void addDelegateDetector(DelegableReentrantLock.DelegateDetector delegateDetector)

Since:
  3.29

### removeDelegateDetector

public final void removeDelegateDetector(DelegableReentrantLock.DelegateDetector delegateDetector)

Since:
  3.29

### getContainer

public final IManagedContainer getContainer()

Specified by:
  `getContainer` in interface `IManagedContainerProvider`

### activate

public final void activate() throws LifecycleException

Specified by:
  `activate` in interface `ILifecycle`
Throws:
  `LifecycleException`

### deactivate

public final Exception deactivate()

Specified by:
  `deactivate` in interface `IDeactivateable`
Specified by:
  `deactivate` in interface `ILifecycle`

### getLifecycleState

public final LifecycleState getLifecycleState()

Specified by:
  `getLifecycleState` in interface `ILifecycle`

### isActive

public final boolean isActive()

Specified by:
  `isActive` in interface `ILifecycle`

### addListener

public final void addListener(IListener listener)
Description copied from interface: `INotifier`
Adds a listener to this notifier.

Depending on the implementation duplicate listeners may lead to duplicate event delivery or not. Implementors are encouraged to prevent events from being delivered more than once to the same listener,

Specified by:
  `addListener` in interface `INotifier`

### removeListener

public final void removeListener(IListener listener)
Description copied from interface: `INotifier`
Removes a listener from this notifier.

Specified by:
  `removeListener` in interface `INotifier`

### getListeners

public final IListener[] getListeners()
Description copied from interface: `INotifier`
Returns the listeners that are registered with this notifier.

Depending on the implementation duplicate listeners may be contained in the returned array.

Specified by:
  `getListeners` in interface `INotifier`

### hasListeners

public final boolean hasListeners()
Description copied from interface: `INotifier`
Returns `true` if one or more listeners are registered with this notifier, `false` otherwise.

Specified by:
  `hasListeners` in interface `INotifier`

### isOwner

protected boolean isOwner(Thread thread, Thread owner)

Overrides:
  `isOwner` in class `NonFairReentrantLock`

### isDelegate

protected boolean isDelegate(Thread thread, Thread owner)