S
- the type of stateE
- the type of eventpublic abstract class AbstractStateMachine<S,E> extends StateMachineObjectSupport<S,E> implements StateMachine<S,E>, StateMachineAccess<S,E>
StateMachine
loosely modelled from UML state
machine.StateMachineObjectSupport.StateMachineListenerRelay
Constructor and Description |
---|
AbstractStateMachine(java.util.Collection<State<S,E>> states,
java.util.Collection<Transition<S,E>> transitions,
State<S,E> initialState)
Instantiates a new abstract state machine.
|
AbstractStateMachine(java.util.Collection<State<S,E>> states,
java.util.Collection<Transition<S,E>> transitions,
State<S,E> initialState,
ExtendedState extendedState)
Instantiates a new abstract state machine.
|
AbstractStateMachine(java.util.Collection<State<S,E>> states,
java.util.Collection<Transition<S,E>> transitions,
State<S,E> initialState,
Transition<S,E> initialTransition,
org.springframework.messaging.Message<E> initialEvent,
ExtendedState extendedState,
java.util.UUID uuid)
Instantiates a new abstract state machine.
|
Modifier and Type | Method and Description |
---|---|
void |
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 |
doDestroy()
Subclasses may implement this for destroy logic.
|
protected reactor.core.publisher.Mono<java.lang.Void> |
doPostStartReactively()
Subclasses may implement this for post start logic.
|
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.
|
protected reactor.core.publisher.Mono<java.lang.Void> |
executeTriggerlessTransitions(StateMachine<S,E> stateMachine,
StateContext<S,E> stateContext,
State<S,E> state) |
ExtendedState |
getExtendedState()
Gets the state machine extended state.
|
PseudoState<S,E> |
getHistoryState() |
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.
|
protected StateMachineExecutor<S,E> |
getStateMachineExecutor() |
java.util.Collection<State<S,E>> |
getStates()
Gets the
State s defined in this machine. |
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 |
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<java.lang.Void> |
resetStateMachineReactively(StateMachineContext<S,E> stateMachineContext)
Reset state machine reactively.
|
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 |
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 |
setId(java.lang.String id)
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(java.lang.Exception exception)
Sets the state machine error.
|
void |
setTransitionConflightPolicy(TransitionConflictPolicy transitionConflictPolicy)
Sets the transition conflict policy.
|
java.lang.String |
toString() |
doStart, getBeanName, getStateListener, getStateMachineEventPublisher, getStateMachineInterceptors, getStateMachineMonitor, notifyActionMonitor, notifyExtendedStateChanged, notifyStateChanged, notifyStateEntered, notifyStateExited, notifyStateMachineError, notifyStateMachineStarted, notifyStateMachineStopped, notifyTransition, notifyTransitionEnd, notifyTransitionMonitor, notifyTransitionStart, setBeanName, setContextEventsEnabled, setStateMachineEventPublisher, setStateMachineInterceptors
afterPropertiesSet, destroy, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, setAutoStartup, setPhase, start, startReactively, stop, stopReactively
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
startReactively, stopReactively
public AbstractStateMachine(java.util.Collection<State<S,E>> states, java.util.Collection<Transition<S,E>> transitions, State<S,E> initialState)
states
- the states of this machinetransitions
- the transitions of this machineinitialState
- the initial state of this machinepublic AbstractStateMachine(java.util.Collection<State<S,E>> states, java.util.Collection<Transition<S,E>> transitions, State<S,E> initialState, ExtendedState extendedState)
states
- the states of this machinetransitions
- the transitions of this machineinitialState
- the initial state of this machineextendedState
- the extended state of this machinepublic AbstractStateMachine(java.util.Collection<State<S,E>> states, java.util.Collection<Transition<S,E>> transitions, State<S,E> initialState, Transition<S,E> initialTransition, org.springframework.messaging.Message<E> initialEvent, ExtendedState extendedState, java.util.UUID uuid)
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 machinepublic State<S,E> getState()
Region
State
.public State<S,E> getInitialState()
StateMachine
S
.getInitialState
in interface StateMachine<S,E>
public ExtendedState getExtendedState()
StateMachine
getExtendedState
in interface StateMachine<S,E>
public void setHistoryState(PseudoState<S,E> history)
history
- to set internal history state.public PseudoState<S,E> getHistoryState()
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.
protected void notifyEventNotAccepted(StateContext<S,E> stateContext)
notifyEventNotAccepted
in class StateMachineObjectSupport<S,E>
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>> 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 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 eventprotected void onInit() throws java.lang.Exception
LifecycleObjectSupport
InitializingBean
phase.onInit
in class LifecycleObjectSupport
java.lang.Exception
- exceptionpublic void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
setBeanFactory
in interface org.springframework.beans.factory.BeanFactoryAware
setBeanFactory
in class LifecycleObjectSupport
org.springframework.beans.BeansException
protected reactor.core.publisher.Mono<java.lang.Void> doPreStartReactively()
LifecycleObjectSupport
doPreStartReactively
in class LifecycleObjectSupport
protected reactor.core.publisher.Mono<java.lang.Void> doPostStartReactively()
LifecycleObjectSupport
doPostStartReactively
in class LifecycleObjectSupport
protected reactor.core.publisher.Mono<java.lang.Void> doPreStopReactively()
LifecycleObjectSupport
doPreStopReactively
in class LifecycleObjectSupport
protected void doDestroy()
LifecycleObjectSupport
doDestroy
in class LifecycleObjectSupport
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 boolean isComplete()
Region
isComplete
in interface Region<S,E>
public java.util.Collection<State<S,E>> getStates()
State
s defined in this machine. 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 void setInitialEnabled(boolean enabled)
StateMachineAccess
setInitialEnabled
in interface StateMachineAccess<S,E>
enabled
- the new initial enabledpublic StateMachineAccessor<S,E> getStateMachineAccessor()
StateMachine
getStateMachineAccessor
in interface StateMachine<S,E>
public void setRelay(StateMachine<S,E> stateMachine)
StateMachineAccess
setRelay
in interface StateMachineAccess<S,E>
stateMachine
- the state machinepublic void setParentMachine(StateMachine<S,E> parentMachine)
StateMachineAccess
setParentMachine
in interface StateMachineAccess<S,E>
parentMachine
- the state machinepublic void setForwardedInitialEvent(org.springframework.messaging.Message<E> message)
StateMachineAccess
setForwardedInitialEvent
in interface StateMachineAccess<S,E>
message
- the forwarded messagepublic void setTransitionConflightPolicy(TransitionConflictPolicy transitionConflictPolicy)
transitionConflictPolicy
- the new transition conflict policypublic java.lang.String toString()
toString
in class java.lang.Object
public void resetStateMachine(StateMachineContext<S,E> stateMachineContext)
StateMachineAccess
resetStateMachine
in interface StateMachineAccess<S,E>
stateMachineContext
- the state machine contextReactiveStateMachineAccess.resetStateMachineReactively(StateMachineContext)
public reactor.core.publisher.Mono<java.lang.Void> resetStateMachineReactively(StateMachineContext<S,E> stateMachineContext)
ReactiveStateMachineAccess
resetStateMachineReactively
in interface ReactiveStateMachineAccess<S,E>
stateMachineContext
- the state machine contextpublic void addStateMachineInterceptor(StateMachineInterceptor<S,E> interceptor)
StateMachineAccess
addStateMachineInterceptor
in interface StateMachineAccess<S,E>
interceptor
- the interceptorpublic void addStateMachineMonitor(StateMachineMonitor<S,E> monitor)
StateMachineAccess
addStateMachineMonitor
in interface StateMachineAccess<S,E>
monitor
- the monitorpublic java.util.UUID getUuid()
Region
public java.lang.String getId()
Region
public void setId(java.lang.String id)
id
- the new machine idprotected reactor.core.publisher.Mono<java.lang.Void> executeTriggerlessTransitions(StateMachine<S,E> stateMachine, StateContext<S,E> stateContext, State<S,E> state)
protected StateMachineExecutor<S,E> getStateMachineExecutor()