S
- the type of stateE
- the type of eventpublic class DistributedStateMachine<S,E> extends LifecycleObjectSupport implements StateMachine<S,E>
DistributedStateMachine
is wrapping a real StateMachine
and works
together with a StateMachineEnsemble
order to provide a distributed state
machine.
Every distributed state machine will enter its initial state regardless of
a distributed state status.Constructor and Description |
---|
DistributedStateMachine(StateMachineEnsemble<S,E> ensemble,
StateMachine<S,E> delegate)
Instantiates a new distributed state machine.
|
Modifier and Type | Method and Description |
---|---|
void |
addStateListener(StateMachineListener<S,E> listener)
Adds the state listener.
|
protected reactor.core.publisher.Mono<java.lang.Void> |
doPreStartReactively()
Subclasses may implement this for pre start logic.
|
protected reactor.core.publisher.Mono<java.lang.Void> |
doPreStopReactively()
Subclasses may implement this for pre stop logic.
|
ExtendedState |
getExtendedState()
Gets the state machine extended state.
|
java.lang.String |
getId()
Gets the region and state machine id.
|
State<S,E> |
getInitialState()
Gets the initial state
S . |
State<S,E> |
getState()
Gets the current
State . |
StateMachineAccessor<S,E> |
getStateMachineAccessor()
Gets the state machine accessor.
|
java.util.Collection<State<S,E>> |
getStates()
Gets the
State s defined in this region. |
java.util.Collection<Transition<S,E>> |
getTransitions()
Gets a
Transition s for this region. |
java.util.UUID |
getUuid()
Gets the region and state machine unique id.
|
boolean |
hasStateMachineError()
Checks for state machine error.
|
boolean |
isComplete()
Checks if region complete.
|
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
void |
removeStateListener(StateMachineListener<S,E> listener)
Removes the state listener.
|
boolean |
sendEvent(E event)
Send an event
E to the region. |
boolean |
sendEvent(org.springframework.messaging.Message<E> event)
Send an event
E wrapped with a Message to the region. |
reactor.core.publisher.Flux<StateMachineEventResult<S,E>> |
sendEvent(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
|
reactor.core.publisher.Mono<java.util.List<StateMachineEventResult<S,E>>> |
sendEventCollect(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
|
reactor.core.publisher.Flux<StateMachineEventResult<S,E>> |
sendEvents(reactor.core.publisher.Flux<org.springframework.messaging.Message<E>> events)
|
void |
setStateMachineError(java.lang.Exception exception)
Sets the state machine error.
|
java.lang.String |
toString() |
afterPropertiesSet, destroy, doDestroy, doPostStartReactively, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, setAutoStartup, setBeanFactory, setPhase, start, startReactively, stop, stopReactively
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
startReactively, stopReactively
public DistributedStateMachine(StateMachineEnsemble<S,E> ensemble, StateMachine<S,E> delegate)
ensemble
- the state machine ensembledelegate
- the delegating state machineprotected void onInit() throws java.lang.Exception
LifecycleObjectSupport
InitializingBean
phase.onInit
in class LifecycleObjectSupport
java.lang.Exception
- exceptionprotected reactor.core.publisher.Mono<java.lang.Void> doPreStartReactively()
LifecycleObjectSupport
doPreStartReactively
in class LifecycleObjectSupport
protected reactor.core.publisher.Mono<java.lang.Void> doPreStopReactively()
LifecycleObjectSupport
doPreStopReactively
in class LifecycleObjectSupport
public boolean sendEvent(org.springframework.messaging.Message<E> event)
Region
E
wrapped with a Message
to the region.
NOTE: this method is now deprecated in favour of a reactive methods.
public boolean sendEvent(E event)
Region
E
to the region.
NOTE: this method is now deprecated in favour of a reactive methods.
public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvent(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
Region
Mono
of event and return a Flux
of
StateMachineEventResult
s. Events are consumed after returned results
are consumed.public reactor.core.publisher.Mono<java.util.List<StateMachineEventResult<S,E>>> sendEventCollect(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
Region
Mono
of event and return a Mono
of collected
StateMachineEventResult
s as a list. Events are consumed after
returned results are consumed.sendEventCollect
in interface Region<S,E>
event
- the eventpublic reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvents(reactor.core.publisher.Flux<org.springframework.messaging.Message<E>> events)
Region
Flux
of events and return a Flux
of
StateMachineEventResult
s. Events are consumed after returned results
are consumed.sendEvents
in interface Region<S,E>
events
- the eventspublic State<S,E> getState()
Region
State
.public java.util.Collection<State<S,E>> getStates()
Region
State
s defined in this region. Returned collection is
an unmodifiable copy because states in a state machine are immutable.public java.util.Collection<Transition<S,E>> getTransitions()
Region
Transition
s for this region.getTransitions
in interface Region<S,E>
public boolean isComplete()
Region
isComplete
in interface Region<S,E>
public void setStateMachineError(java.lang.Exception exception)
StateMachine
setStateMachineError
in interface StateMachine<S,E>
exception
- the new state machine errorpublic boolean hasStateMachineError()
StateMachine
hasStateMachineError
in interface StateMachine<S,E>
public void addStateListener(StateMachineListener<S,E> listener)
Region
addStateListener
in interface Region<S,E>
listener
- the listenerpublic void removeStateListener(StateMachineListener<S,E> listener)
Region
removeStateListener
in interface Region<S,E>
listener
- the listenerpublic State<S,E> getInitialState()
StateMachine
S
.getInitialState
in interface StateMachine<S,E>
public ExtendedState getExtendedState()
StateMachine
getExtendedState
in interface StateMachine<S,E>
public StateMachineAccessor<S,E> getStateMachineAccessor()
StateMachine
getStateMachineAccessor
in interface StateMachine<S,E>
public java.util.UUID getUuid()
Region
public java.lang.String getId()
Region
public java.lang.String toString()
toString
in class java.lang.Object