public abstract class AbstractState<T,E extends Throwable> extends Object implements IStatefulObject<T,E>
IStatefulObject. The state type is parameterized
(typically an enumeration).IStatefulObject,
Listener for state modifications| Constructor and Description |
|---|
AbstractState(T initialState)
Constructor for AbstractState.
|
AbstractState(T initialState,
T errorState)
Creates a state with a error state.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addStateListener(StateListener<T> listener)
Adds on-event state listener.
|
void |
addStateNotifiable(StateListener<T> listener)
Add post-event notification listener.
|
protected T |
attemptSetState(Set<T> prerequisiteState,
T newState)
Attempts to change the state.
|
protected void |
clearError()
clearError.
|
E |
getError()
Get error state or null.
|
T |
getState()
getState.
|
boolean |
hasError()
hasError.
|
protected boolean |
isStateTransitionAllowed(T oldState,
T newState)
Checks whether state transition is allowed.
|
protected void |
onListenerException(RuntimeException rte)
Override this.
|
protected void |
onStateTransition(T oldState,
T newState)
Override this.
|
void |
removeStateListener(StateListener<T> listener)
removeStateListener.
|
void |
removeStateNotifiable(StateListener<T> listener)
removeStateNotifiable.
|
protected void |
setError(E error)
setError.
|
protected boolean |
setState(T state)
Setter for the field
state. |
protected T |
setState(T state,
Executor listenerExecutor,
Set<T> prerequisiteStates)
Set state.
|
protected void |
throwIfError()
assertNoError.
|
T |
waitForState(Set<T> set)
Wait until state changes to one of the given states.
|
T |
waitForState(Set<T> set,
long timeout,
TimeUnit unit)
Wait until state changes to one of the given states or until time out occurs.
|
T |
waitForStateUninterruptibly(Set<T> set)
Wait until state changes to one of the given states.
|
public AbstractState(T initialState)
Constructor for AbstractState.
initialState - a StateType object.public void addStateListener(StateListener<T> listener)
addStateListener in interface IStatefulObject<T,E extends Throwable>listener - a StateListener object.public void addStateNotifiable(StateListener<T> listener)
addStateNotifiable in interface IStatefulObject<T,E extends Throwable>listener - a StateListener object.public E getError()
IStatefulObjectgetError in interface IStatefulObject<T,E extends Throwable>public T getState()
IStatefulObjectgetState.
getState in interface IStatefulObject<T,E extends Throwable>public boolean hasError()
hasError.
public void removeStateListener(StateListener<T> listener)
IStatefulObjectremoveStateListener.
removeStateListener in interface IStatefulObject<T,E extends Throwable>listener - a StateListener object.public void removeStateNotifiable(StateListener<T> listener)
IStatefulObjectremoveStateNotifiable.
removeStateNotifiable in interface IStatefulObject<T,E extends Throwable>listener - a StateListener object.public T waitForState(Set<T> set) throws InterruptedException, E extends Throwable
IStatefulObjectwaitForState in interface IStatefulObject<T,E extends Throwable>set - states that ends waitingInterruptedException - if any.E - if any.E extends Throwablepublic T waitForState(Set<T> set, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, E extends Throwable
IStatefulObjectwaitForState in interface IStatefulObject<T,E extends Throwable>set - a Set object.timeout - a long.unit - a TimeUnit object.InterruptedException - thread was interruptedTimeoutException - timeout occuredE - if any.E extends Throwablepublic T waitForStateUninterruptibly(Set<T> set) throws E extends Throwable
IStatefulObjectwaitForStateUninterruptibly in interface IStatefulObject<T,E extends Throwable>set - states that ends waitingE - if any.E extends Throwableprotected T attemptSetState(Set<T> prerequisiteState, T newState)
prerequisiteState - expected current statenewState - a StateType object.protected void clearError()
clearError.
protected boolean isStateTransitionAllowed(T oldState, T newState)
oldState - a StateType object.newState - a StateType object.protected void onListenerException(RuntimeException rte)
rte - a RuntimeException object.protected void onStateTransition(T oldState, T newState)
oldState - a StateType object.newState - a StateType object.protected void setError(E error)
setError.
error - a ErrorType object.protected boolean setState(T state)
Setter for the field state.
state - a StateType object.protected T setState(T state, Executor listenerExecutor, Set<T> prerequisiteStates)
state - a StateType object.listenerExecutor - executor for post listener handling or null for immediateprerequisiteStates - old state prerequisite or nullCopyright © 2026. All rights reserved.