Class AbstractStateMachine<S,E>
java.lang.Object
org.springframework.statemachine.support.LifecycleObjectSupport
org.springframework.statemachine.support.StateMachineObjectSupport<S,E>
org.springframework.statemachine.support.AbstractStateMachine<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.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,ReactiveStateMachineAccess<S,,E> StateMachineAccess<S,,E> Region<S,,E> StateMachine<S,,E> StateMachineReactiveLifecycle
- Direct Known Subclasses:
ObjectStateMachine
public abstract class AbstractStateMachine<S,E>
extends StateMachineObjectSupport<S,E>
implements StateMachine<S,E>, StateMachineAccess<S,E>
Base implementation of a
StateMachine loosely modelled from UML state
machine.-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.statemachine.support.StateMachineObjectSupport
StateMachineObjectSupport.StateMachineListenerRelay -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionAbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState) Instantiates a new abstract state machine.AbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState, ExtendedState extendedState) Instantiates a new abstract state machine.AbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState, Transition<S, E> initialTransition, org.springframework.messaging.Message<E> initialEvent, ExtendedState extendedState, UUID uuid) Instantiates a new abstract state machine. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(StateMachineListener<S, E> listener) Adds the state listener.voidaddStateMachineInterceptor(StateMachineInterceptor<S, E> interceptor) Adds the state machine interceptor.voidaddStateMachineMonitor(StateMachineMonitor<S, E> monitor) Adds the state machine monitor.protected voidSubclasses may implement this for destroy logic.protected reactor.core.publisher.Mono<Void>Subclasses may implement this for post start logic.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.protected reactor.core.publisher.Mono<Void>executeTriggerlessTransitions(StateMachine<S, E> stateMachine, StateContext<S, E> stateContext, State<S, E> state) 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.protected StateMachineExecutor<S,E> Collection<State<S,E>> Gets theStates defined in this machine.Gets aTransitions for this region.getUuid()Gets the region and state machine unique id.booleanChecks for state machine error.booleanChecks if region complete.protected voidnotifyEventNotAccepted(StateContext<S, E> stateContext) protected voidonInit()Subclasses may implement this for initialization logic.voidremoveStateListener(StateMachineListener<S, E> listener) Removes the state listener.voidresetStateMachine(StateMachineContext<S, E> stateMachineContext) Reset state machine.reactor.core.publisher.Mono<Void>resetStateMachineReactively(StateMachineContext<S, E> stateMachineContext) Reset state machine reactively.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) voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) voidsetForwardedInitialEvent(org.springframework.messaging.Message<E> message) Set initial forwarded event which is used for passing in event and its headers for actions executed when sub state is entered via initial transition.voidsetHistoryState(PseudoState<S, E> history) voidSets the machine id.voidsetInitialEnabled(boolean enabled) Sets if initial state is enabled when a state machine is using sub states.voidsetParentMachine(StateMachine<S, E> parentMachine) Sets the parent machine.voidsetRelay(StateMachine<S, E> stateMachine) Sets the relay state machine.voidsetStateMachineError(Exception exception) Sets the state machine error.voidsetTransitionConflightPolicy(TransitionConflictPolicy transitionConflictPolicy) Sets the transition conflict policy.toString()Methods inherited from class org.springframework.statemachine.support.StateMachineObjectSupport
doStart, getBeanName, getStateListener, getStateMachineEventPublisher, getStateMachineInterceptors, getStateMachineMonitor, notifyActionMonitor, notifyExtendedStateChanged, notifyStateChanged, notifyStateEntered, notifyStateExited, notifyStateMachineError, notifyStateMachineStarted, notifyStateMachineStopped, notifyTransition, notifyTransitionEnd, notifyTransitionMonitor, notifyTransitionStart, setBeanName, setContextEventsEnabled, setStateMachineEventPublisher, setStateMachineInterceptorsMethods inherited from class org.springframework.statemachine.support.LifecycleObjectSupport
afterPropertiesSet, destroy, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, setAutoStartup, 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
-
AbstractStateMachine
public AbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState) Instantiates a new abstract state machine.- Parameters:
states- the states of this machinetransitions- the transitions of this machineinitialState- the initial state of this machine
-
AbstractStateMachine
public AbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState, ExtendedState extendedState) Instantiates a new abstract state machine.- Parameters:
states- the states of this machinetransitions- the transitions of this machineinitialState- the initial state of this machineextendedState- the extended state of this machine
-
AbstractStateMachine
public AbstractStateMachine(Collection<State<S, E>> states, Collection<Transition<S, E>> transitions, State<S, E> initialState, Transition<S, E> initialTransition, org.springframework.messaging.Message<E> initialEvent, ExtendedState extendedState, UUID uuid) Instantiates a new abstract state machine.- Parameters:
states- the states of this machinetransitions- the transitions of this machineinitialState- the initial state of this machineinitialTransition- the initial transitioninitialEvent- the initial event of this machineextendedState- the extended state of this machineuuid- the given uuid for this machine
-
-
Method Details
-
getState
Description copied from interface:RegionGets the currentState. -
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
-
setHistoryState
- Parameters:
history- to set internal history state.
-
getHistoryState
- Returns:
- history state attribute.
-
sendEvent
Description copied from interface:RegionSend an eventEwrapped with aMessageto the region.NOTE: this method is now deprecated in favour of a reactive methods.
-
notifyEventNotAccepted
- Overrides:
notifyEventNotAcceptedin classStateMachineObjectSupport<S,E>
-
sendEvent
Description copied from interface:RegionSend an eventEto the region.NOTE: this method is now deprecated in favour of a reactive methods.
-
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
-
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
-
onInit
Description copied from class:LifecycleObjectSupportSubclasses may implement this for initialization logic. Called during theInitializingBeanphase.- Overrides:
onInitin classLifecycleObjectSupport- Throws:
Exception- exception
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Overrides:
setBeanFactoryin classLifecycleObjectSupport- Throws:
org.springframework.beans.BeansException
-
doPreStartReactively
Description copied from class:LifecycleObjectSupportSubclasses may implement this for pre start logic.- Overrides:
doPreStartReactivelyin classLifecycleObjectSupport- Returns:
- the mono for completion
-
doPostStartReactively
Description copied from class:LifecycleObjectSupportSubclasses may implement this for post start logic.- Overrides:
doPostStartReactivelyin 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
-
doDestroy
protected void doDestroy()Description copied from class:LifecycleObjectSupportSubclasses may implement this for destroy logic.- Overrides:
doDestroyin classLifecycleObjectSupport
-
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
-
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
-
getStates
Gets theStates defined in this machine. 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
-
setInitialEnabled
public void setInitialEnabled(boolean enabled) Description copied from interface:StateMachineAccessSets if initial state is enabled when a state machine is using sub states.- Specified by:
setInitialEnabledin interfaceStateMachineAccess<S,E> - Parameters:
enabled- the new initial enabled
-
getStateMachineAccessor
Description copied from interface:StateMachineGets the state machine accessor.- Specified by:
getStateMachineAccessorin interfaceStateMachine<S,E> - Returns:
- the state machine accessor
-
setRelay
Description copied from interface:StateMachineAccessSets the relay state machine.- Specified by:
setRelayin interfaceStateMachineAccess<S,E> - Parameters:
stateMachine- the state machine
-
setParentMachine
Description copied from interface:StateMachineAccessSets the parent machine.- Specified by:
setParentMachinein interfaceStateMachineAccess<S,E> - Parameters:
parentMachine- the state machine
-
setForwardedInitialEvent
Description copied from interface:StateMachineAccessSet initial forwarded event which is used for passing in event and its headers for actions executed when sub state is entered via initial transition.- Specified by:
setForwardedInitialEventin interfaceStateMachineAccess<S,E> - Parameters:
message- the forwarded message
-
setTransitionConflightPolicy
Sets the transition conflict policy.- Parameters:
transitionConflictPolicy- the new transition conflict policy
-
toString
-
resetStateMachine
Description copied from interface:StateMachineAccessReset state machine.- Specified by:
resetStateMachinein interfaceStateMachineAccess<S,E> - Parameters:
stateMachineContext- the state machine context- See Also:
-
resetStateMachineReactively
public reactor.core.publisher.Mono<Void> resetStateMachineReactively(StateMachineContext<S, E> stateMachineContext) Description copied from interface:ReactiveStateMachineAccessReset state machine reactively.- Specified by:
resetStateMachineReactivelyin interfaceReactiveStateMachineAccess<S,E> - Parameters:
stateMachineContext- the state machine context- Returns:
- mono for completion
-
addStateMachineInterceptor
Description copied from interface:StateMachineAccessAdds the state machine interceptor.- Specified by:
addStateMachineInterceptorin interfaceStateMachineAccess<S,E> - Parameters:
interceptor- the interceptor
-
addStateMachineMonitor
Description copied from interface:StateMachineAccessAdds the state machine monitor.- Specified by:
addStateMachineMonitorin interfaceStateMachineAccess<S,E> - Parameters:
monitor- the monitor
-
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. -
setId
Sets the machine id.- Parameters:
id- the new machine id
-
executeTriggerlessTransitions
protected reactor.core.publisher.Mono<Void> executeTriggerlessTransitions(StateMachine<S, E> stateMachine, StateContext<S, E> stateContext, State<S, E> state) -
getStateMachineExecutor
-