Class DistributedStateMachine<S,E>

java.lang.Object
org.springframework.statemachine.support.LifecycleObjectSupport
org.springframework.statemachine.ensemble.DistributedStateMachine<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, Region<S,E>, StateMachine<S,E>, StateMachineReactiveLifecycle

public class DistributedStateMachine<S,E> extends LifecycleObjectSupport implements StateMachine<S,E>
DistributedStateMachine is wrapping a real StateMachine and works together with a StateMachineEnsemble order to provide a distributed state machine. Every distributed state machine will enter its initial state regardless of a distributed state status.
Author:
Janne Valkealahti
  • Constructor Details

    • DistributedStateMachine

      public DistributedStateMachine(StateMachineEnsemble<S,E> ensemble, StateMachine<S,E> delegate)
      Instantiates a new distributed state machine.
      Parameters:
      ensemble - the state machine ensemble
      delegate - the delegating state machine
  • Method Details

    • onInit

      protected void onInit() throws Exception
      Description copied from class: LifecycleObjectSupport
      Subclasses may implement this for initialization logic. Called during the InitializingBean phase.
      Overrides:
      onInit in class LifecycleObjectSupport
      Throws:
      Exception - exception
    • 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
    • sendEvent

      public boolean sendEvent(org.springframework.messaging.Message<E> event)
      Description copied from interface: Region
      Send an event E wrapped with a Message to the region.

      NOTE: this method is now deprecated in favour of a reactive methods.

      Specified by:
      sendEvent in interface Region<S,E>
      Parameters:
      event - the wrapped event to send
      Returns:
      true if event was accepted
    • sendEvent

      public boolean sendEvent(E event)
      Description copied from interface: Region
      Send an event E to the region.

      NOTE: this method is now deprecated in favour of a reactive methods.

      Specified by:
      sendEvent in interface Region<S,E>
      Parameters:
      event - the event to send
      Returns:
      true if event was accepted
    • sendEvent

      public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvent(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
      Description copied from interface: Region
      Send a Mono of event and return a Flux of StateMachineEventResults. Events are consumed after returned results are consumed.
      Specified by:
      sendEvent in interface Region<S,E>
      Parameters:
      event - the event
      Returns:
      the event results
    • sendEventCollect

      public reactor.core.publisher.Mono<List<StateMachineEventResult<S,E>>> sendEventCollect(reactor.core.publisher.Mono<org.springframework.messaging.Message<E>> event)
      Description copied from interface: Region
      Send a Mono of event and return a Mono of collected StateMachineEventResults as a list. Events are consumed after returned results are consumed.
      Specified by:
      sendEventCollect in interface Region<S,E>
      Parameters:
      event - the event
      Returns:
      the event results
    • sendEvents

      public reactor.core.publisher.Flux<StateMachineEventResult<S,E>> sendEvents(reactor.core.publisher.Flux<org.springframework.messaging.Message<E>> events)
      Description copied from interface: Region
      Send a Flux of events and return a Flux of StateMachineEventResults. Events are consumed after returned results are consumed.
      Specified by:
      sendEvents in interface Region<S,E>
      Parameters:
      events - the events
      Returns:
      the event results
    • getState

      public State<S,E> getState()
      Description copied from interface: Region
      Gets the current State.
      Specified by:
      getState in interface Region<S,E>
      Returns:
      current state
    • getStates

      public Collection<State<S,E>> getStates()
      Description copied from interface: Region
      Gets the States defined in this region. Returned collection is an unmodifiable copy because states in a state machine are immutable.
      Specified by:
      getStates in interface Region<S,E>
      Returns:
      immutable copy of states
    • getTransitions

      public Collection<Transition<S,E>> getTransitions()
      Description copied from interface: Region
      Gets a Transitions for this region.
      Specified by:
      getTransitions in interface Region<S,E>
      Returns:
      immutable copy of transitions
    • isComplete

      public boolean isComplete()
      Description copied from interface: Region
      Checks if region complete. Region is considered to be completed if it has reached its end state and no further event processing is happening.
      Specified by:
      isComplete in interface Region<S,E>
      Returns:
      true, if complete
    • setStateMachineError

      public void setStateMachineError(Exception exception)
      Description copied from interface: StateMachine
      Sets the state machine error.
      Specified by:
      setStateMachineError in interface StateMachine<S,E>
      Parameters:
      exception - the new state machine error
    • hasStateMachineError

      public boolean hasStateMachineError()
      Description copied from interface: StateMachine
      Checks for state machine error.
      Specified by:
      hasStateMachineError in interface StateMachine<S,E>
      Returns:
      true, if error has been set
    • addStateListener

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

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

      public State<S,E> getInitialState()
      Description copied from interface: StateMachine
      Gets the initial state S.
      Specified by:
      getInitialState in interface StateMachine<S,E>
      Returns:
      initial state
    • getExtendedState

      public ExtendedState getExtendedState()
      Description copied from interface: StateMachine
      Gets the state machine extended state.
      Specified by:
      getExtendedState in interface StateMachine<S,E>
      Returns:
      extended state
    • getStateMachineAccessor

      public StateMachineAccessor<S,E> getStateMachineAccessor()
      Description copied from interface: StateMachine
      Gets the state machine accessor.
      Specified by:
      getStateMachineAccessor in interface StateMachine<S,E>
      Returns:
      the state machine accessor
    • getUuid

      public UUID getUuid()
      Description copied from interface: Region
      Gets the region and state machine unique id.
      Specified by:
      getUuid in interface Region<S,E>
      Returns:
      the region and state machine unique id
    • getId

      public String getId()
      Description copied from interface: Region
      Gets the region and state machine id. This identifier is provided for users disposal and can be set from a various ways to build a machines.
      Specified by:
      getId in interface Region<S,E>
      Returns:
      the region and state machine id
    • toString

      public String toString()
      Overrides:
      toString in class Object