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
ConstructorDescriptionAbstractState
(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 TypeMethodDescriptionvoid
addActionListener
(ActionListener<S, E> listener) Adds the action listener.void
addStateListener
(StateListener<S, E> listener) Adds the state listener.protected void
Arm triggers.protected void
Disarm 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>>> GetsAction
s executed entering in this state.Collection<Function<StateContext<S,
E>, reactor.core.publisher.Mono<Void>>> GetsAction
s executed exiting from this state.getId()
Gets the state identifier.abstract Collection<S>
getIds()
Gets the state identifiers.Gets aPseudoState
attached to aState
.Collection<Region<S,
E>> Gets the regions.Collection<Function<StateContext<S,
E>, reactor.core.publisher.Mono<Void>>> GetsAction
s 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) boolean
Checks if state is a composite state.boolean
Checks if state is an orthogonal state.boolean
isSimple()
Checks if state is a simple state.boolean
Checks if state is a submachine state.protected void
notifyStateOnComplete
(StateContext<S, E> context) void
removeActionListener
(ActionListener<S, E> listener) Removes the action listener.void
removeStateListener
(StateListener<S, E> listener) Removes the state listener.reactor.core.publisher.Flux<StateMachineEventResult<S,
E>> Send an eventE
wrapped with aMessage
to the state and return aStateMachineEventResult
for results.void
setStateDoActionPolicy
(StateDoActionPolicy stateDoActionPolicy) void
setStateDoActionPolicyTimeout
(Long stateDoActionPolicyTimeout) void
setTriggers
(List<Trigger<S, E>> triggers) Sets the triggers.boolean
shouldDefer
(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, 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
-
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:State
Send an eventE
wrapped with aMessage
to the state and return aStateMachineEventResult
for results. -
shouldDefer
Description copied from interface:State
Checks if state wants to defer an event.- Specified by:
shouldDefer
in interfaceState<S,
E> - Parameters:
event
- the wrapped event- Returns:
- true if event should be deferred
-
exit
Description copied from interface:State
Initiate an exit sequence for the state. -
entry
Description copied from interface:State
Initiate an entry sequence for the state. -
getId
Description copied from interface:State
Gets the state identifier. -
getIds
Description copied from interface:State
Gets the state identifiers. Usually returned collection contains only one identifier except in a case where state is an orthogonal. -
getStates
Description copied from interface:State
Gets all possible states this state knows about including itself and substates. -
getPseudoState
Description copied from interface:State
Gets aPseudoState
attached to aState
.PseudoState
is not required and thus this method returnNULL
if it's not set.- Specified by:
getPseudoState
in interfaceState<S,
E> - Returns:
- pseudostate or null if state doesn't have one
-
getDeferredEvents
Description copied from interface:State
Gets the deferred events for this state.- Specified by:
getDeferredEvents
in interfaceState<S,
E> - Returns:
- the state deferred events
-
getEntryActions
Description copied from interface:State
GetsAction
s executed entering in this state.- Specified by:
getEntryActions
in interfaceState<S,
E> - Returns:
- the state entry actions
-
getStateActions
Description copied from interface:State
GetsAction
s executed once in this state.- Specified by:
getStateActions
in interfaceState<S,
E> - Returns:
- the state actions
-
getExitActions
Description copied from interface:State
GetsAction
s executed exiting from this state.- Specified by:
getExitActions
in interfaceState<S,
E> - Returns:
- the state exit actions
-
isComposite
public boolean isComposite()Description copied from interface:State
Checks if state is a composite state. A composite state is a state that contains at least one region.- Specified by:
isComposite
in interfaceState<S,
E> - Returns:
- true, if state is a composite state
-
isOrthogonal
public boolean isOrthogonal()Description copied from interface:State
Checks 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:
isOrthogonal
in interfaceState<S,
E> - Returns:
- true, if state is an orthogonal state
-
isSimple
public boolean isSimple()Description copied from interface:State
Checks 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:State
Checks if state is a submachine state. This kind of state refers to a state machine(submachine).- Specified by:
isSubmachineState
in interfaceState<S,
E> - Returns:
- true, if state is a submachine state
-
addStateListener
Description copied from interface:State
Adds the state listener.- Specified by:
addStateListener
in interfaceState<S,
E> - Parameters:
listener
- the listener
-
removeStateListener
Description copied from interface:State
Removes the state listener.- Specified by:
removeStateListener
in interfaceState<S,
E> - Parameters:
listener
- the listener
-
addActionListener
Description copied from interface:State
Adds the action listener.- Specified by:
addActionListener
in interfaceState<S,
E> - Parameters:
listener
- the listener
-
removeActionListener
Description copied from interface:State
Removes the action listener.- Specified by:
removeActionListener
in interfaceState<S,
E> - Parameters:
listener
- the listener
-
doPreStartReactively
Description copied from class:LifecycleObjectSupport
Subclasses may implement this for pre start logic.- Overrides:
doPreStartReactively
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
-
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
-