Class DistributedStateMachine<S,E>
java.lang.Object
org.springframework.statemachine.support.LifecycleObjectSupport
org.springframework.statemachine.ensemble.DistributedStateMachine<S,E>
- Type Parameters:
S
- the type of stateE
- the type of event
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
,Region<S,
,E> StateMachine<S,
,E> StateMachineReactiveLifecycle
public 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.-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionDistributedStateMachine
(StateMachineEnsemble<S, E> ensemble, StateMachine<S, E> delegate) Instantiates a new distributed state machine. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStateListener
(StateMachineListener<S, E> listener) Adds the state listener.protected reactor.core.publisher.Mono<Void>
Subclasses may implement this for pre start logic.protected reactor.core.publisher.Mono<Void>
Subclasses may implement this for pre stop logic.Gets the state machine extended state.getId()
Gets the region and state machine id.Gets the initial stateS
.getState()
Gets the currentState
.Gets the state machine accessor.Collection<State<S,
E>> Gets theState
s defined in this region.Gets aTransition
s for this region.getUuid()
Gets the region and state machine unique id.boolean
Checks for state machine error.boolean
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
Send an eventE
to the region.boolean
Send an eventE
wrapped with aMessage
to the region.reactor.core.publisher.Flux<StateMachineEventResult<S,
E>> reactor.core.publisher.Mono<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
(Exception exception) Sets the state machine error.toString()
Methods inherited from class org.springframework.statemachine.support.LifecycleObjectSupport
afterPropertiesSet, destroy, doDestroy, doPostStartReactively, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, setAutoStartup, setBeanFactory, setPhase, start, startReactively, stop, stopReactively
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.context.SmartLifecycle
stop
Methods inherited from interface org.springframework.statemachine.support.StateMachineReactiveLifecycle
startReactively, stopReactively
-
Constructor Details
-
DistributedStateMachine
Instantiates a new distributed state machine.- Parameters:
ensemble
- the state machine ensembledelegate
- the delegating state machine
-
-
Method Details
-
onInit
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for initialization logic. Called during theInitializingBean
phase.- Overrides:
onInit
in classLifecycleObjectSupport
- Throws:
Exception
- exception
-
doPreStartReactively
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for pre start logic.- Overrides:
doPreStartReactively
in classLifecycleObjectSupport
- Returns:
- the mono for completion
-
doPreStopReactively
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for pre stop logic.- Overrides:
doPreStopReactively
in classLifecycleObjectSupport
- Returns:
- the mono for completion
-
sendEvent
Description copied from interface:Region
Send an eventE
wrapped with aMessage
to the region.NOTE: this method is now deprecated in favour of a reactive methods.
-
sendEvent
Description copied from interface:Region
Send an eventE
to the region.NOTE: this method is now deprecated in favour of a reactive methods.
-
sendEvent
public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvent(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event) Description copied from interface:Region
Send aMono
of event and return aFlux
ofStateMachineEventResult
s. Events are consumed after returned results are consumed. -
sendEventCollect
public reactor.core.publisher.Mono<List<StateMachineEventResult<S,E>>> sendEventCollect(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event) Description copied from interface:Region
Send aMono
of event and return aMono
of collectedStateMachineEventResult
s as a list. Events are consumed after returned results are consumed.- Specified by:
sendEventCollect
in interfaceRegion<S,
E> - Parameters:
event
- the event- Returns:
- the event results
-
sendEvents
public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvents(reactor.core.publisher.Flux<org.springframework.messaging.Message<E>> events) Description copied from interface:Region
Send aFlux
of events and return aFlux
ofStateMachineEventResult
s. Events are consumed after returned results are consumed.- Specified by:
sendEvents
in interfaceRegion<S,
E> - Parameters:
events
- the events- Returns:
- the event results
-
getState
Description copied from interface:Region
Gets the currentState
. -
getStates
Description copied from interface:Region
Gets theState
s defined in this region. Returned collection is an unmodifiable copy because states in a state machine are immutable. -
getTransitions
Description copied from interface:Region
Gets aTransition
s for this region.- Specified by:
getTransitions
in interfaceRegion<S,
E> - Returns:
- immutable copy of transitions
-
isComplete
public boolean isComplete()Description copied from interface:Region
Checks if region complete. Region is considered to be completed if it has reached its end state and no further event processing is happening.- Specified by:
isComplete
in interfaceRegion<S,
E> - Returns:
- true, if complete
-
setStateMachineError
Description copied from interface:StateMachine
Sets the state machine error.- Specified by:
setStateMachineError
in interfaceStateMachine<S,
E> - Parameters:
exception
- the new state machine error
-
hasStateMachineError
public boolean hasStateMachineError()Description copied from interface:StateMachine
Checks for state machine error.- Specified by:
hasStateMachineError
in interfaceStateMachine<S,
E> - Returns:
- true, if error has been set
-
addStateListener
Description copied from interface:Region
Adds the state listener.- Specified by:
addStateListener
in interfaceRegion<S,
E> - Parameters:
listener
- the listener
-
removeStateListener
Description copied from interface:Region
Removes the state listener.- Specified by:
removeStateListener
in interfaceRegion<S,
E> - Parameters:
listener
- the listener
-
getInitialState
Description copied from interface:StateMachine
Gets the initial stateS
.- Specified by:
getInitialState
in interfaceStateMachine<S,
E> - Returns:
- initial state
-
getExtendedState
Description copied from interface:StateMachine
Gets the state machine extended state.- Specified by:
getExtendedState
in interfaceStateMachine<S,
E> - Returns:
- extended state
-
getStateMachineAccessor
Description copied from interface:StateMachine
Gets the state machine accessor.- Specified by:
getStateMachineAccessor
in interfaceStateMachine<S,
E> - Returns:
- the state machine accessor
-
getUuid
Description copied from interface:Region
Gets the region and state machine unique id. -
getId
Description copied from interface:Region
Gets the region and state machine id. This identifier is provided for users disposal and can be set from a various ways to build a machines. -
toString
-