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)
Instantiates a new abstract state machine.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
acceptEvent(org.springframework.messaging.Message<E> message) |
void |
addStateListener(StateMachineListener<S,E> listener)
Adds the state listener.
|
void |
addStateMachineInterceptor(StateMachineInterceptor<S,E> interceptor)
Adds the state machine interceptor.
|
protected void |
doDestroy() |
protected void |
doStart()
Subclasses may implement this method with the start behavior.
|
protected void |
doStop()
Subclasses may implement this method with the stop behavior.
|
ExtendedState |
getExtendedState()
Gets the state machine extended state.
|
java.lang.String |
getId()
Gets the region and state machine unique 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.
|
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. |
boolean |
hasStateMachineError()
Checks for state machine error.
|
boolean |
isComplete()
Checks if region complete.
|
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.
|
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. |
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 |
setInitialEnabled(boolean enabled)
Sets if initial state is enabled when a state machine is
using sub states.
|
void |
setRelay(StateMachine<S,E> stateMachine)
Sets the relay state machine.
|
void |
setStateMachineError(java.lang.Exception exception)
Sets the state machine error.
|
protected void |
stateChangedInRelay() |
java.lang.String |
toString() |
getBeanName, getStateListener, getStateMachineEventPublisher, getStateMachineInterceptors, notifyEventNotAccepted, notifyExtendedStateChanged, notifyStateChanged, notifyStateEntered, notifyStateExited, notifyStateMachineError, notifyStateMachineStarted, notifyStateMachineStopped, notifyTransition, notifyTransitionEnd, notifyTransitionStart, setBeanName, setContextEventsEnabled, setStateMachineEventPublisher, setStateMachineInterceptors
afterPropertiesSet, destroy, getBeanFactory, getPhase, getTaskExecutor, getTaskScheduler, isAutoStartup, isRunning, setAutoStartup, setPhase, setTaskExecutor, setTaskScheduler, start, stop, stop
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)
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 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)
public boolean sendEvent(org.springframework.messaging.Message<E> event)
Region
E
wrapped with a Message
to the region.public boolean sendEvent(E event)
Region
E
to the region.protected void onInit() throws java.lang.Exception
LifecycleObjectSupport
InitializingBean
phase. Implementor should
always call super method not to break initialization chain.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 void doStart()
LifecycleObjectSupport
LifecycleObjectSupport.lifecycleLock
.doStart
in class LifecycleObjectSupport
protected void doStop()
LifecycleObjectSupport
LifecycleObjectSupport.lifecycleLock
.doStop
in class LifecycleObjectSupport
protected void doDestroy()
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 machineprotected void stateChangedInRelay()
stateChangedInRelay
in class StateMachineObjectSupport<S,E>
public void setForwardedInitialEvent(org.springframework.messaging.Message<E> message)
StateMachineAccess
setForwardedInitialEvent
in interface StateMachineAccess<S,E>
message
- the forwarded messagepublic 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 contextpublic void addStateMachineInterceptor(StateMachineInterceptor<S,E> interceptor)
StateMachineAccess
addStateMachineInterceptor
in interface StateMachineAccess<S,E>
interceptor
- the interceptorpublic java.lang.String getId()
Region
protected boolean acceptEvent(org.springframework.messaging.Message<E> message)