Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.utils

public final Class StateHolder<E>

extends Object
Class Inheritance
Imports
java.util.Collection, .Iterator, java.util.concurrent.ConcurrentLinkedQueue, .Future, java.util.concurrent.locks.ReentrantReadWriteLock, java.util.logging.Level, .Logger, org.glassfish.grizzly.CompletionHandler, .Grizzly, org.glassfish.grizzly.impl.FutureImpl, .ReadyFutureImpl, .SafeFutureImpl, org.glassfish.grizzly.localization.LogMessages, org.glassfish.grizzly.utils.conditions.Condition

Class, which holds the state. Provides API for state change notification, state read/write access locking.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private static final Logger
private final Collection<StateHolder.ConditionElement<E>>
private final ReentrantReadWriteLock
private volatile E

Constructor Summary

AccessConstructor and Description
public
StateHolder()

Constructs StateHolder.

public
StateHolder(E initialState)

Constructs StateHolder.

Method Summary

Modifier and TypeMethod and Description
public E

Returns:

state
getState
()

Gets current state Current StateHolder locking mode will be used

public ReentrantReadWriteLock

Returns:

locker
getStateLocker
()

Gets Read/Write locker, which is used by this StateHolder

protected void
public Future<E>

Returns:

ConditionListener, if current state doesn't match the condition and listener was registered, null if current state matches the condition. In both cases listener will be notified
notifyWhenConditionMatchState
(Condition
Condition, the listener is interested in
condition
,
CompletionHandler<E>
that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners
completionHandler
)

Register listener, which will be notified, when state will match the condition.

public Future<E>

Returns:

ConditionListener, if current state is not equal to required and listener was registered, null if current state is equal to required. In both cases listener will be notified
notifyWhenStateIsEqual
(final E
State, listener is interested in
state
,
final CompletionHandler<E>
that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners
completionHandler
)

Register listener, which will be notified, when state will be equal to passed one.

public Future<E>

Returns:

ConditionListener, if current state is equal to required and listener was registered, null if current state is not equal to required. In both cases listener will be notified
notifyWhenStateIsNotEqual
(final E
State, listener is interested in
state
,
final CompletionHandler<E>
that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners
completionHandler
)

Register listener, which will be notified, when state will become not equal to passed one.

public void
setState(E state)

Sets current state Current StateHolder locking mode will be used

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_loggerback to summary
private static final Logger _logger
conditionListenersback to summary
private final Collection<StateHolder.ConditionElement<E>> conditionListeners
readWriteLockback to summary
private final ReentrantReadWriteLock readWriteLock
stateback to summary
private volatile E state

Constructor Detail

StateHolderback to summary
public StateHolder()

Constructs StateHolder.

StateHolderback to summary
public StateHolder(E initialState)

Constructs StateHolder.

Method Detail

getStateback to summary
public E getState()

Gets current state Current StateHolder locking mode will be used

Returns:E

state

getStateLockerback to summary
public ReentrantReadWriteLock getStateLocker()

Gets Read/Write locker, which is used by this StateHolder

Returns:ReentrantReadWriteLock

locker

notifyConditionListenersback to summary
protected void notifyConditionListeners()
notifyWhenConditionMatchStateback to summary
public Future<E> notifyWhenConditionMatchState(Condition condition, CompletionHandler<E> completionHandler)

Register listener, which will be notified, when state will match the condition. Once listener will be notified - it will be removed from this StateHolder's listener set.

Parameters
condition:Condition

Condition, the listener is interested in

completionHandler:CompletionHandler<E>

that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners

Returns:Future<E>

ConditionListener, if current state doesn't match the condition and listener was registered, null if current state matches the condition. In both cases listener will be notified

notifyWhenStateIsEqualback to summary
public Future<E> notifyWhenStateIsEqual(final E state, final CompletionHandler<E> completionHandler)

Register listener, which will be notified, when state will be equal to passed one. Once listener will be notified - it will be removed from this StateHolder's listener set.

Parameters
state:E

State, listener is interested in

completionHandler:CompletionHandler<E>

that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners

Returns:Future<E>

ConditionListener, if current state is not equal to required and listener was registered, null if current state is equal to required. In both cases listener will be notified

notifyWhenStateIsNotEqualback to summary
public Future<E> notifyWhenStateIsNotEqual(final E state, final CompletionHandler<E> completionHandler)

Register listener, which will be notified, when state will become not equal to passed one. Once listener will be notified - it will be removed from this StateHolder's listener set.

Parameters
state:E

State, listener is interested in

completionHandler:CompletionHandler<E>

that will be notified. This StateHolder implementation works with Runnable, Callable, CountDownLatch, Object listeners

Returns:Future<E>

ConditionListener, if current state is equal to required and listener was registered, null if current state is not equal to required. In both cases listener will be notified

setStateback to summary
public void setState(E state)

Sets current state Current StateHolder locking mode will be used

org.glassfish.grizzly.utils back to summary

protected final Class StateHolder.ConditionElement<E>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final CompletionHandler<E>
private final Condition
private final FutureImpl<E>

Constructor Summary

AccessConstructor and Description
public
ConditionElement(Condition condition, FutureImpl<E> future, CompletionHandler<E> completionHandler)

Method Summary

Modifier and TypeMethod and Description
public CompletionHandler<E>
public Condition
public FutureImpl<E>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

completionHandlerback to summary
private final CompletionHandler<E> completionHandler
conditionback to summary
private final Condition condition
futureback to summary
private final FutureImpl<E> future

Constructor Detail

ConditionElementback to summary
public ConditionElement(Condition condition, FutureImpl<E> future, CompletionHandler<E> completionHandler)

Method Detail

getCompletionHandlerback to summary
public CompletionHandler<E> getCompletionHandler()
getConditionback to summary
public Condition getCondition()
getFutureback to summary
public FutureImpl<E> getFuture()