java.lang.Object
org.glassfish.grizzly.utils.StateHolder<E>
Class, which holds the state. Provides API for state change notification, state read/write access locking.
- Author:
- Alexey Stashok
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetState()
Gets current state Current StateHolder locking mode will be usedGets Read/Write locker, which is used by thisStateHolder
protected void
notifyWhenConditionMatchState
(Condition condition, CompletionHandler<E> completionHandler) Register listener, which will be notified, when state will match the condition.notifyWhenStateIsEqual
(E state, CompletionHandler<E> completionHandler) Register listener, which will be notified, when state will be equal to passed one.notifyWhenStateIsNotEqual
(E state, CompletionHandler<E> completionHandler) Register listener, which will be notified, when state will become not equal to passed one.void
Sets current state Current StateHolder locking mode will be used
-
Constructor Details
-
StateHolder
public StateHolder()ConstructsStateHolder
. -
StateHolder
ConstructsStateHolder
.
-
-
Method Details
-
getState
Gets current state Current StateHolder locking mode will be used- Returns:
- state
-
setState
Sets current state Current StateHolder locking mode will be used- Parameters:
state
-
-
getStateLocker
Gets Read/Write locker, which is used by thisStateHolder
- Returns:
- locker
-
notifyWhenStateIsEqual
Register listener, which will be notified, when state will be equal to passed one. Once listener will be notified - it will be removed from thisStateHolder
's listener set.- Parameters:
state
- State, listener is interested incompletionHandler
- that will be notified. ThisStateHolder
implementation works with Runnable, Callable, CountDownLatch, Object listeners- 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
-
notifyWhenStateIsNotEqual
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 thisStateHolder
's listener set.- Parameters:
state
- State, listener is interested incompletionHandler
- that will be notified. ThisStateHolder
implementation works with Runnable, Callable, CountDownLatch, Object listeners- 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
-
notifyWhenConditionMatchState
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 thisStateHolder
's listener set.- Parameters:
condition
- Condition, the listener is interested incompletionHandler
- that will be notified. ThisStateHolder
implementation works with Runnable, Callable, CountDownLatch, Object listeners- 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
-
notifyConditionListeners
protected void notifyConditionListeners()
-