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.- Author:
- Janne Valkealahti
-
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
ConstructorDescriptionAbstractStateMachine
(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 TypeMethodDescriptionvoid
addStateListener
(StateMachineListener<S, E> listener) Adds the state listener.void
addStateMachineInterceptor
(StateMachineInterceptor<S, E> interceptor) Adds the state machine interceptor.void
addStateMachineMonitor
(StateMachineMonitor<S, E> monitor) Adds the state machine monitor.protected void
Subclasses 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 theState
s defined in this machine.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
notifyEventNotAccepted
(StateContext<S, E> stateContext) protected void
onInit()
Subclasses may implement this for initialization logic.void
removeStateListener
(StateMachineListener<S, E> listener) Removes the state listener.void
resetStateMachine
(StateMachineContext<S, E> stateMachineContext) Reset state machine.reactor.core.publisher.Mono<Void>
resetStateMachineReactively
(StateMachineContext<S, E> stateMachineContext) Reset state machine reactively.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
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) void
setForwardedInitialEvent
(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.void
setHistoryState
(PseudoState<S, E> history) void
Sets the machine id.void
setInitialEnabled
(boolean enabled) Sets if initial state is enabled when a state machine is using sub states.void
setParentMachine
(StateMachine<S, E> parentMachine) Sets the parent machine.void
setRelay
(StateMachine<S, E> stateMachine) Sets the relay state machine.void
setStateMachineError
(Exception exception) Sets the state machine error.void
setTransitionConflightPolicy
(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, setStateMachineInterceptors
Methods inherited from class org.springframework.statemachine.support.LifecycleObjectSupport
afterPropertiesSet, destroy, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, setAutoStartup, 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
-
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:Region
Gets the currentState
. -
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
-
setHistoryState
- Parameters:
history
- to set internal history state.
-
getHistoryState
- Returns:
- history state attribute.
-
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.
-
notifyEventNotAccepted
- Overrides:
notifyEventNotAccepted
in classStateMachineObjectSupport<S,
E>
-
sendEvent
Description copied from interface:Region
Send an eventE
to 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: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
-
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
-
onInit
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for initialization logic. Called during theInitializingBean
phase.- Overrides:
onInit
in classLifecycleObjectSupport
- Throws:
Exception
- exception
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
- Overrides:
setBeanFactory
in classLifecycleObjectSupport
- Throws:
org.springframework.beans.BeansException
-
doPreStartReactively
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for pre start logic.- Overrides:
doPreStartReactively
in classLifecycleObjectSupport
- Returns:
- the mono for completion
-
doPostStartReactively
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for post start logic.- Overrides:
doPostStartReactively
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
-
doDestroy
protected void doDestroy()Description copied from class:LifecycleObjectSupport
Subclasses may implement this for destroy logic.- Overrides:
doDestroy
in classLifecycleObjectSupport
-
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
-
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
-
getStates
Gets theState
s defined in this machine. 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
-
setInitialEnabled
public void setInitialEnabled(boolean enabled) Description copied from interface:StateMachineAccess
Sets if initial state is enabled when a state machine is using sub states.- Specified by:
setInitialEnabled
in interfaceStateMachineAccess<S,
E> - Parameters:
enabled
- the new initial enabled
-
getStateMachineAccessor
Description copied from interface:StateMachine
Gets the state machine accessor.- Specified by:
getStateMachineAccessor
in interfaceStateMachine<S,
E> - Returns:
- the state machine accessor
-
setRelay
Description copied from interface:StateMachineAccess
Sets the relay state machine.- Specified by:
setRelay
in interfaceStateMachineAccess<S,
E> - Parameters:
stateMachine
- the state machine
-
setParentMachine
Description copied from interface:StateMachineAccess
Sets the parent machine.- Specified by:
setParentMachine
in interfaceStateMachineAccess<S,
E> - Parameters:
parentMachine
- the state machine
-
setForwardedInitialEvent
Description copied from interface:StateMachineAccess
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.- Specified by:
setForwardedInitialEvent
in 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:StateMachineAccess
Reset state machine.- Specified by:
resetStateMachine
in 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:ReactiveStateMachineAccess
Reset state machine reactively.- Specified by:
resetStateMachineReactively
in interfaceReactiveStateMachineAccess<S,
E> - Parameters:
stateMachineContext
- the state machine context- Returns:
- mono for completion
-
addStateMachineInterceptor
Description copied from interface:StateMachineAccess
Adds the state machine interceptor.- Specified by:
addStateMachineInterceptor
in interfaceStateMachineAccess<S,
E> - Parameters:
interceptor
- the interceptor
-
addStateMachineMonitor
Description copied from interface:StateMachineAccess
Adds the state machine monitor.- Specified by:
addStateMachineMonitor
in interfaceStateMachineAccess<S,
E> - Parameters:
monitor
- the monitor
-
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. -
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
-