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 state
E - 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

public abstract class AbstractState<S,E> extends LifecycleObjectSupport implements State<S,E>
Base implementation of a State.
Author:
Janne Valkealahti
  • Constructor Details

  • 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 event E wrapped with a Message to the state and return a StateMachineEventResult for results.
      Specified by:
      sendEvent in interface State<S,E>
      Parameters:
      event - the wrapped event to send
      Returns:
      the state machine event results
    • shouldDefer

      public boolean shouldDefer(org.springframework.messaging.Message<E> event)
      Description copied from interface: State
      Checks if state wants to defer an event.
      Specified by:
      shouldDefer in interface State<S,E>
      Parameters:
      event - the wrapped event
      Returns:
      true if event should be deferred
    • exit

      public reactor.core.publisher.Mono<Void> exit(StateContext<S,E> context)
      Description copied from interface: State
      Initiate an exit sequence for the state.
      Specified by:
      exit in interface State<S,E>
      Parameters:
      context - the state context
      Returns:
      Mono for completion
    • entry

      public reactor.core.publisher.Mono<Void> entry(StateContext<S,E> context)
      Description copied from interface: State
      Initiate an entry sequence for the state.
      Specified by:
      entry in interface State<S,E>
      Parameters:
      context - the state context
      Returns:
      Mono for completion
    • getId

      public S getId()
      Description copied from interface: State
      Gets the state identifier.
      Specified by:
      getId in interface State<S,E>
      Returns:
      the state identifiers
    • getIds

      public abstract Collection<S> 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.
      Specified by:
      getIds in interface State<S,E>
      Returns:
      the state identifiers
    • getStates

      public abstract Collection<State<S,E>> getStates()
      Description copied from interface: State
      Gets all possible states this state knows about including itself and substates.
      Specified by:
      getStates in interface State<S,E>
      Returns:
      all state including itself and nested states
    • getPseudoState

      public PseudoState<S,E> getPseudoState()
      Description copied from interface: State
      Gets a PseudoState attached to a State. PseudoState is not required and thus this method return NULL if it's not set.
      Specified by:
      getPseudoState in interface State<S,E>
      Returns:
      pseudostate or null if state doesn't have one
    • getDeferredEvents

      public Collection<E> getDeferredEvents()
      Description copied from interface: State
      Gets the deferred events for this state.
      Specified by:
      getDeferredEvents in interface State<S,E>
      Returns:
      the state deferred events
    • getEntryActions

      public Collection<Function<StateContext<S,E>,reactor.core.publisher.Mono<Void>>> getEntryActions()
      Description copied from interface: State
      Gets Actions executed entering in this state.
      Specified by:
      getEntryActions in interface State<S,E>
      Returns:
      the state entry actions
    • getStateActions

      public Collection<Function<StateContext<S,E>,reactor.core.publisher.Mono<Void>>> getStateActions()
      Description copied from interface: State
      Gets Actions executed once in this state.
      Specified by:
      getStateActions in interface State<S,E>
      Returns:
      the state actions
    • getExitActions

      public Collection<Function<StateContext<S,E>,reactor.core.publisher.Mono<Void>>> getExitActions()
      Description copied from interface: State
      Gets Actions executed exiting from this state.
      Specified by:
      getExitActions in interface State<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 interface State<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 returns TRUE, State.isComposite() will also always return TRUE.
      Specified by:
      isOrthogonal in interface State<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.
      Specified by:
      isSimple in interface State<S,E>
      Returns:
      true, if state is a simple state
    • 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 interface State<S,E>
      Returns:
      true, if state is a submachine state
    • addStateListener

      public void addStateListener(StateListener<S,E> listener)
      Description copied from interface: State
      Adds the state listener.
      Specified by:
      addStateListener in interface State<S,E>
      Parameters:
      listener - the listener
    • removeStateListener

      public void removeStateListener(StateListener<S,E> listener)
      Description copied from interface: State
      Removes the state listener.
      Specified by:
      removeStateListener in interface State<S,E>
      Parameters:
      listener - the listener
    • addActionListener

      public void addActionListener(ActionListener<S,E> listener)
      Description copied from interface: State
      Adds the action listener.
      Specified by:
      addActionListener in interface State<S,E>
      Parameters:
      listener - the listener
    • removeActionListener

      public void removeActionListener(ActionListener<S,E> listener)
      Description copied from interface: State
      Removes the action listener.
      Specified by:
      removeActionListener in interface State<S,E>
      Parameters:
      listener - the listener
    • doPreStartReactively

      protected reactor.core.publisher.Mono<Void> doPreStartReactively()
      Description copied from class: LifecycleObjectSupport
      Subclasses may implement this for pre start logic.
      Overrides:
      doPreStartReactively in class LifecycleObjectSupport
      Returns:
      the mono for completion
    • doPreStopReactively

      protected reactor.core.publisher.Mono<Void> doPreStopReactively()
      Description copied from class: LifecycleObjectSupport
      Subclasses may implement this for pre stop logic.
      Overrides:
      doPreStopReactively in class LifecycleObjectSupport
      Returns:
      the mono for completion
    • getSubmachine

      public StateMachine<S,E> getSubmachine()
      Gets the submachine.
      Returns:
      the submachine or null if not set
    • getRegions

      public Collection<Region<S,E>> getRegions()
      Gets the regions.
      Returns:
      the regions or empty collection if no regions
    • setTriggers

      public void setTriggers(List<Trigger<S,E>> triggers)
      Sets the triggers.
      Parameters:
      triggers - the triggers
    • getTriggers

      public List<Trigger<S,E>> getTriggers()
      Gets the triggers.
      Returns:
      the triggers
    • setStateDoActionPolicy

      public void setStateDoActionPolicy(StateDoActionPolicy stateDoActionPolicy)
    • setStateDoActionPolicyTimeout

      public void setStateDoActionPolicyTimeout(Long stateDoActionPolicyTimeout)
    • 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 action
      context - the context
      Returns:
      mono for completion
    • handleStateDoOnComplete

      protected reactor.core.publisher.Mono<Void> handleStateDoOnComplete(StateContext<S,E> context)
    • notifyStateOnComplete

      protected void notifyStateOnComplete(StateContext<S,E> context)
    • toString

      public String toString()
      Overrides:
      toString in class Object