Class AbstractState<S,E>
java.lang.Object
org.springframework.statemachine.support.LifecycleObjectSupport
org.springframework.statemachine.state.AbstractState<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,State<S,,E> StateMachineReactiveLifecycle
- Direct Known Subclasses:
AbstractSimpleState,RegionState,StateMachineState
Base implementation of a
State.-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionAbstractState(S id, Collection<E> deferred) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> stateActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions, StateMachine<S, E> submachine) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions, StateMachine<S, E> submachine) Instantiates a new abstract state.AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, StateMachine<S, E> submachine) Instantiates a new abstract state.AbstractState(S id, PseudoState<S, E> pseudoState) Instantiates a new abstract state. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionListener(ActionListener<S, E> listener) Adds the action listener.voidaddStateListener(StateListener<S, E> listener) Adds the state listener.protected voidArm triggers.protected voidDisarm triggers.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.reactor.core.publisher.Mono<Void>entry(StateContext<S, E> context) Initiate an entry sequence for the state.protected reactor.core.publisher.Mono<Void>executeAction(Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>> action, StateContext<S, E> context) Execute action and notify action listener if set.reactor.core.publisher.Mono<Void>exit(StateContext<S, E> context) Initiate an exit sequence for the state.Gets the deferred events for this state.Collection<Function<StateContext<S,E>, reactor.core.publisher.Mono<Void>>> GetsActions executed entering in this state.Collection<Function<StateContext<S,E>, reactor.core.publisher.Mono<Void>>> GetsActions executed exiting from this state.getId()Gets the state identifier.abstract Collection<S>getIds()Gets the state identifiers.Gets aPseudoStateattached to aState.Collection<Region<S,E>> Gets the regions.Collection<Function<StateContext<S,E>, reactor.core.publisher.Mono<Void>>> GetsActions executed once in this state.abstract Collection<State<S,E>> Gets all possible states this state knows about including itself and substates.Gets the submachine.Gets the triggers.protected reactor.core.publisher.Mono<Void>handleStateDoOnComplete(StateContext<S, E> context) booleanChecks if state is a composite state.booleanChecks if state is an orthogonal state.booleanisSimple()Checks if state is a simple state.booleanChecks if state is a submachine state.protected voidnotifyStateOnComplete(StateContext<S, E> context) voidremoveActionListener(ActionListener<S, E> listener) Removes the action listener.voidremoveStateListener(StateListener<S, E> listener) Removes the state listener.reactor.core.publisher.Flux<StateMachineEventResult<S,E>> Send an eventEwrapped with aMessageto the state and return aStateMachineEventResultfor results.voidsetStateDoActionPolicy(StateDoActionPolicy stateDoActionPolicy) voidsetStateDoActionPolicyTimeout(Long stateDoActionPolicyTimeout) voidsetTriggers(List<Trigger<S, E>> triggers) Sets the triggers.booleanshouldDefer(org.springframework.messaging.Message<E> event) Checks if state wants to defer an event.toString()Methods inherited from class org.springframework.statemachine.support.LifecycleObjectSupport
afterPropertiesSet, destroy, doDestroy, doPostStartReactively, doPostStopReactively, getBeanFactory, getPhase, isAutoStartup, isRunning, onInit, 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
stop
-
Constructor Details
-
AbstractState
Instantiates a new abstract state.- Parameters:
id- the state identifierpseudoState- the pseudo state
-
AbstractState
Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferred
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actions
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actionspseudoState- the pseudo state
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, StateMachine<S, E> submachine) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actionspseudoState- the pseudo statesubmachine- the submachine
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actionspseudoState- the pseudo stateregions- the regions
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions, StateMachine<S, E> submachine) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actionspseudoState- the pseudo stateregions- the regionssubmachine- the submachine
-
AbstractState
public AbstractState(S id, Collection<E> deferred, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> entryActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> exitActions, Collection<Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>>> stateActions, PseudoState<S, E> pseudoState, Collection<Region<S, E>> regions, StateMachine<S, E> submachine) Instantiates a new abstract state.- Parameters:
id- the state identifierdeferred- the deferredentryActions- the entry actionsexitActions- the exit actionsstateActions- the state actionspseudoState- the pseudo stateregions- the regionssubmachine- the submachine
-
-
Method Details
-
sendEvent
public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvent(org.springframework.messaging.Message<E> event) Description copied from interface:StateSend an eventEwrapped with aMessageto the state and return aStateMachineEventResultfor results. -
shouldDefer
Description copied from interface:StateChecks if state wants to defer an event.- Specified by:
shouldDeferin interfaceState<S,E> - Parameters:
event- the wrapped event- Returns:
- true if event should be deferred
-
exit
Description copied from interface:StateInitiate an exit sequence for the state. -
entry
Description copied from interface:StateInitiate an entry sequence for the state. -
getId
Description copied from interface:StateGets the state identifier. -
getIds
Description copied from interface:StateGets the state identifiers. Usually returned collection contains only one identifier except in a case where state is an orthogonal. -
getStates
Description copied from interface:StateGets all possible states this state knows about including itself and substates. -
getPseudoState
Description copied from interface:StateGets aPseudoStateattached to aState.PseudoStateis not required and thus this method returnNULLif it's not set.- Specified by:
getPseudoStatein interfaceState<S,E> - Returns:
- pseudostate or null if state doesn't have one
-
getDeferredEvents
Description copied from interface:StateGets the deferred events for this state.- Specified by:
getDeferredEventsin interfaceState<S,E> - Returns:
- the state deferred events
-
getEntryActions
Description copied from interface:StateGetsActions executed entering in this state.- Specified by:
getEntryActionsin interfaceState<S,E> - Returns:
- the state entry actions
-
getStateActions
Description copied from interface:StateGetsActions executed once in this state.- Specified by:
getStateActionsin interfaceState<S,E> - Returns:
- the state actions
-
getExitActions
Description copied from interface:StateGetsActions executed exiting from this state.- Specified by:
getExitActionsin interfaceState<S,E> - Returns:
- the state exit actions
-
isComposite
public boolean isComposite()Description copied from interface:StateChecks if state is a composite state. A composite state is a state that contains at least one region.- Specified by:
isCompositein interfaceState<S,E> - Returns:
- true, if state is a composite state
-
isOrthogonal
public boolean isOrthogonal()Description copied from interface:StateChecks if state is an orthogonal state. An orthogonal composite state contains two or more regions. If this method returnsTRUE,State.isComposite()will also always returnTRUE.- Specified by:
isOrthogonalin interfaceState<S,E> - Returns:
- true, if state is an orthogonal state
-
isSimple
public boolean isSimple()Description copied from interface:StateChecks if state is a simple state. A simple state does not have any regions and it does not refer to any submachine state machine. -
isSubmachineState
public boolean isSubmachineState()Description copied from interface:StateChecks if state is a submachine state. This kind of state refers to a state machine(submachine).- Specified by:
isSubmachineStatein interfaceState<S,E> - Returns:
- true, if state is a submachine state
-
addStateListener
Description copied from interface:StateAdds the state listener.- Specified by:
addStateListenerin interfaceState<S,E> - Parameters:
listener- the listener
-
removeStateListener
Description copied from interface:StateRemoves the state listener.- Specified by:
removeStateListenerin interfaceState<S,E> - Parameters:
listener- the listener
-
addActionListener
Description copied from interface:StateAdds the action listener.- Specified by:
addActionListenerin interfaceState<S,E> - Parameters:
listener- the listener
-
removeActionListener
Description copied from interface:StateRemoves the action listener.- Specified by:
removeActionListenerin interfaceState<S,E> - Parameters:
listener- the listener
-
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
-
getSubmachine
Gets the submachine.- Returns:
- the submachine or null if not set
-
getRegions
Gets the regions.- Returns:
- the regions or empty collection if no regions
-
setTriggers
Sets the triggers.- Parameters:
triggers- the triggers
-
getTriggers
Gets the triggers.- Returns:
- the triggers
-
setStateDoActionPolicy
-
setStateDoActionPolicyTimeout
-
armTriggers
protected void armTriggers()Arm triggers. -
disarmTriggers
protected void disarmTriggers()Disarm triggers. -
executeAction
protected reactor.core.publisher.Mono<Void> executeAction(Function<StateContext<S, E>, reactor.core.publisher.Mono<Void>> action, StateContext<S, E> context) Execute action and notify action listener if set.- Parameters:
action- the actioncontext- the context- Returns:
- mono for completion
-
handleStateDoOnComplete
-
notifyStateOnComplete
-
toString
-