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.- Author:
- Janne Valkealahti
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionDistributedStateMachine(StateMachineEnsemble<S, E> ensemble, StateMachine<S, E> delegate) Instantiates a new distributed state machine. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(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 theStates defined in this region.Gets aTransitions for this region.getUuid()Gets the region and state machine unique id.booleanChecks for state machine error.booleanChecks if region complete.protected voidonInit()Subclasses may implement this for initialization logic.voidremoveStateListener(StateMachineListener<S, E> listener) Removes the state listener.booleanSend an eventEto the region.booleanSend an eventEwrapped with aMessageto 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) voidsetStateMachineError(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, stopReactivelyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
stopMethods 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:LifecycleObjectSupportSubclasses may implement this for initialization logic. Called during theInitializingBeanphase.- Overrides:
onInitin classLifecycleObjectSupport- Throws:
Exception- exception
-
doPreStartReactively
Description copied from class:LifecycleObjectSupportSubclasses may implement this for pre start logic.- Overrides:
doPreStartReactivelyin classLifecycleObjectSupport- Returns:
- the mono for completion
-
doPreStopReactively
Description copied from class:LifecycleObjectSupportSubclasses may implement this for pre stop logic.- Overrides:
doPreStopReactivelyin classLifecycleObjectSupport- Returns:
- the mono for completion
-
sendEvent
Description copied from interface:RegionSend an eventEwrapped with aMessageto the region.NOTE: this method is now deprecated in favour of a reactive methods.
-
sendEvent
Description copied from interface:RegionSend an eventEto 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:RegionSend aMonoof event and return aFluxofStateMachineEventResults. 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:RegionSend aMonoof event and return aMonoof collectedStateMachineEventResults as a list. Events are consumed after returned results are consumed.- Specified by:
sendEventCollectin 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:RegionSend aFluxof events and return aFluxofStateMachineEventResults. Events are consumed after returned results are consumed.- Specified by:
sendEventsin interfaceRegion<S,E> - Parameters:
events- the events- Returns:
- the event results
-
getState
Description copied from interface:RegionGets the currentState. -
getStates
Description copied from interface:RegionGets theStates defined in this region. Returned collection is an unmodifiable copy because states in a state machine are immutable. -
getTransitions
Description copied from interface:RegionGets aTransitions for this region.- Specified by:
getTransitionsin interfaceRegion<S,E> - Returns:
- immutable copy of transitions
-
isComplete
public boolean isComplete()Description copied from interface:RegionChecks 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:
isCompletein interfaceRegion<S,E> - Returns:
- true, if complete
-
setStateMachineError
Description copied from interface:StateMachineSets the state machine error.- Specified by:
setStateMachineErrorin interfaceStateMachine<S,E> - Parameters:
exception- the new state machine error
-
hasStateMachineError
public boolean hasStateMachineError()Description copied from interface:StateMachineChecks for state machine error.- Specified by:
hasStateMachineErrorin interfaceStateMachine<S,E> - Returns:
- true, if error has been set
-
addStateListener
Description copied from interface:RegionAdds the state listener.- Specified by:
addStateListenerin interfaceRegion<S,E> - Parameters:
listener- the listener
-
removeStateListener
Description copied from interface:RegionRemoves the state listener.- Specified by:
removeStateListenerin interfaceRegion<S,E> - Parameters:
listener- the listener
-
getInitialState
Description copied from interface:StateMachineGets the initial stateS.- Specified by:
getInitialStatein interfaceStateMachine<S,E> - Returns:
- initial state
-
getExtendedState
Description copied from interface:StateMachineGets the state machine extended state.- Specified by:
getExtendedStatein interfaceStateMachine<S,E> - Returns:
- extended state
-
getStateMachineAccessor
Description copied from interface:StateMachineGets the state machine accessor.- Specified by:
getStateMachineAccessorin interfaceStateMachine<S,E> - Returns:
- the state machine accessor
-
getUuid
Description copied from interface:RegionGets the region and state machine unique id. -
getId
Description copied from interface:RegionGets 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
-