Package com.couchbase.client.core.util
Class SingleStateful<S>
- java.lang.Object
-
- com.couchbase.client.core.util.SingleStateful<S>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Doesn't have to be called, added for good measure.boolean
compareAndTransition(S expectedState, S newState)
If the expected state is in place the new one is applied and consumers notified.static <S> SingleStateful<S>
fromInitial(S initialState)
Creates a new stateful component with an initial state.static <S> SingleStateful<S>
fromInitial(S initialState, BiConsumer<S,S> beforeTransitionCallback)
Creates a new stateful component with an initial state.S
state()
Returns the current state of the stateful component.Flux<S>
states()
Returns a stream of states for this component as they change.void
transition(S newState)
Transition into a new state, notifying consumers.
-
-
-
Method Detail
-
fromInitial
public static <S> SingleStateful<S> fromInitial(S initialState)
Creates a new stateful component with an initial state.- Parameters:
initialState
- the initial state of the component.- Returns:
- an initialized stateful component with the state provided.
-
fromInitial
public static <S> SingleStateful<S> fromInitial(S initialState, BiConsumer<S,S> beforeTransitionCallback)
Creates a new stateful component with an initial state.- Parameters:
initialState
- the initial state of the component.- Returns:
- an initialized stateful component with the state provided.
-
state
public S state()
Description copied from interface:Stateful
Returns the current state of the stateful component.
-
states
public Flux<S> states()
Description copied from interface:Stateful
Returns a stream of states for this component as they change.
-
transition
public void transition(S newState)
Transition into a new state, notifying consumers.Note that if the new state is identical to the old state no transition will be performed.
- Parameters:
newState
- the new state to apply.
-
compareAndTransition
public boolean compareAndTransition(S expectedState, S newState)
If the expected state is in place the new one is applied and consumers notified.- Parameters:
expectedState
- the old expected state.newState
- the new state to apply.- Returns:
- true if the comparison has been successful.
-
close
public void close()
Doesn't have to be called, added for good measure.
-
-