Package com.couchbase.client.core.state
Class AbstractStateMachine<S extends Enum>
- java.lang.Object
-
- com.couchbase.client.core.state.AbstractStateMachine<S>
-
- All Implemented Interfaces:
Stateful<S>
- Direct Known Subclasses:
AbstractDynamicService
,AbstractEndpoint
,AbstractStateZipper
,CouchbaseNode
,PooledService
public class AbstractStateMachine<S extends Enum> extends Object implements Stateful<S>
AbstractStateful
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.- Since:
- 1.0
- Author:
- Michael Nitschinger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractStateMachine(S initialState)
Creates a new state machine.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasSubscribers()
Returns true if there are subscribers observing the state stream.boolean
isState(S state)
Check if the given state is the same as the current one.S
state()
Returns the current state.rx.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.
-
-
-
Constructor Detail
-
AbstractStateMachine
protected AbstractStateMachine(S initialState)
Creates a new state machine.- Parameters:
initialState
- the initial state of the state machine.
-
-
Method Detail
-
states
public final rx.Observable<S> states()
Description copied from interface:Stateful
Returns a infinite observable which gets updated when the state of the component changes.
-
isState
public final boolean isState(S state)
Description copied from interface:Stateful
Check if the given state is the same as the current one.
-
hasSubscribers
public boolean hasSubscribers()
Description copied from interface:Stateful
Returns true if there are subscribers observing the state stream.- Specified by:
hasSubscribers
in interfaceStateful<S extends Enum>
- Returns:
- true if at least one does, false otherwise.
-
transitionState
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.- Parameters:
newState
- the states to transition into.
-
-