public class AbstractStateMachine<S extends Enum> extends Object implements Stateful<S>
Abstract Stateful
implementation which acts like a simple state machine.
This class is thread safe, so state transitions can be issued from any thread without any further synchronization.
Modifier | Constructor and Description |
---|---|
protected |
AbstractStateMachine(S initialState)
Creates a new state machine.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isState(S state)
Check if the given state is the same as the current one.
|
S |
state()
Returns the current state.
|
Observable<S> |
states()
Returns a infinite observable which gets updated when the state of the component changes.
|
protected void |
transitionState(S newState)
Transition into a new state.
|
protected AbstractStateMachine(S initialState)
Creates a new state machine.
initialState
- the initial state of the state machine.public final Observable<S> states()
Stateful
Returns a infinite observable which gets updated when the state of the component changes.
states
in interface Stateful<S extends Enum>
Observable
updated with state transitions.public final boolean isState(S state)
Stateful
Check if the given state is the same as the current one.
protected void transitionState(S newState)
Transition into a new state.
This method is intentionally not public, because the subclass should only be responsible for the actual transitions, the other components only react on those transitions eventually.
newState
- the states to transition into.Copyright © 2014 Couchbase, Inc.