Class STMImpl<StateEntityType extends StateEntity>

java.lang.Object
org.chenile.stm.impl.STMImpl<StateEntityType>
Type Parameters:
StateEntityType -
All Implemented Interfaces:
STM<StateEntityType>

public class STMImpl<StateEntityType extends StateEntity> extends Object implements STM<StateEntityType>
The main STM implementation. This requires the injection of a flow configurator to provide the STD information to the STM. The chief method is the proceed() method

Author:
Raja Shankar Kolluru
  • Field Details

  • Constructor Details

    • STMImpl

      public STMImpl()
  • Method Details

    • setStmFlowStore

      public void setStmFlowStore(STMFlowStore stmFlowStore)
      Description copied from interface: STM
      Initialization method. The flow needs to be read by a flow configurator which needs to be set into the STM.
      Specified by:
      setStmFlowStore in interface STM<StateEntityType extends StateEntity>
    • getStmFlowStore

      public STMFlowStore getStmFlowStore()
    • proceed

      public StateEntityType proceed(StateEntityType stateEntity) throws Exception
      Description copied from interface: STM
      This method allows the user to specify no starting state and feed it to the STM. This would start with the default flow and the initial state in it. It would then recursively process thru all "auto states" and finally returns the new state to which it transitioned.

      The new state is either an end state or a manual state (i.e. a state that requires a user triggered action to determine the transitioning event)

      This proceed() method supports the following kinds of behavior:

      If the state passed is null, then the initial state of the default flow is chosen.
      Specified by:
      proceed in interface STM<StateEntityType extends StateEntity>
      Parameters:
      stateEntity - - the parameter required by the transition action
      Returns:
      the transitioned state.
      Throws:
      Exception
    • proceed

      public StateEntityType proceed(StateEntityType stateEntity, Object transitionParam) throws Exception
      Description copied from interface: STM
      This method allows the user to specify a starting state and feed it to the STM. This would recursively process thru all "auto states" and finally returns the new state to which it transitioned.

      The new state is either an end state or a manual state (i.e. a state that requires a user triggered action to determine the transitioning event)

      This proceed() method supports the following kinds of behavior: If the state passed is null, then the initial state of the default flow is chosen.

      Specified by:
      proceed in interface STM<StateEntityType extends StateEntity>
      Parameters:
      stateEntity - - the entity with a state that needs to be processed by the STM
      transitionParam - - the parameter required by the transition action
      Returns:
      the transitioned state.
      Throws:
      Exception
    • proceed

      public StateEntityType proceed(StateEntityType stateEntity, String startingEventId, Object transitionParam) throws Exception
      This method recursively calls itself to transition as far down the flow of states as possible. It returns in either one of the following cases: The state reached is a final state. (i.e. a state with no transitions) in which case the exit action of the final state is called and the call chain ends. The state reached is a manual state (or a view state) in which case the entry action is called for that particular state and the state is returned. This method must be reinvoked with a starting event Id to make it proceed.

      All states in between would be traversed by the machine recursively. All the entry and exit actions would be called along with the action that actually computes the event.

      If the machine is called again after the final state is reached, it exits without doing anything.

      Specified by:
      proceed in interface STM<StateEntityType extends StateEntity>
      Parameters:
      stateEntity - - the entity with a state that needs to be processed by the STM
      startingEventId - - the event that needs to start the flow. This would have been most probably obtained by the user.
      transitionParam - - the parameter required by the transition action
      Returns:
      the transitioned state.
      Throws:
      Exception
    • internalProceed

      private StateEntityType internalProceed(StateEntityType stateEntity, String startingEventId, Object transitionParam, boolean doAuthChecks) throws Exception
      Throws:
      Exception
    • retrieveMergeFromPersistentStorage

      protected StateEntityType retrieveMergeFromPersistentStorage(StateEntityType originalStateEntity, String startEventId) throws Exception
      Throws:
      Exception
    • isBeginning

      private boolean isBeginning(State startState)
    • executeStartStateExitAction

      private void executeStartStateExitAction(State startState, StateEntityType stateEntity) throws Exception
      Throws:
      Exception
    • executeEndStateEntryAction

      private void executeEndStateEntryAction(State startState, State endState, StateEntityType stateEntity) throws Exception
      Throws:
      Exception
    • doEndStateChecks

      private StateEntityType doEndStateChecks(State endState, StateEntityType stateEntity, Object transitionParam) throws Exception
      Throws:
      Exception
    • obtainEndStateAndTransition

      private Object[] obtainEndStateAndTransition(StateEntityType stateEntity, State startState, String startingEventId, boolean doAuthChecks) throws Exception
      Obtains the end state and transition for the combination of start state and event Id. Since it returns a tuple, this is accomplished using an Object array. The object array is somewhat of a kludge.
      Parameters:
      stateEntity -
      startState -
      startingEventId -
      Returns:
      Throws:
      Exception
    • isTransitionAuthorized

      protected boolean isTransitionAuthorized(StateDescriptor startStateDescriptor, Transition transition) throws STMException
      Throws:
      STMException
    • obtainEvent

      protected String obtainEvent(StateEntityType stateEntity, StateDescriptor stateDescriptor) throws Exception
      Throws:
      Exception
    • obtainViewEvent

      protected String obtainViewEvent(StateEntity stateEntity, StateDescriptor manualStateDescriptor)
      A possible hook for a sub class to generate an event from a manual state.
      Parameters:
      stateEntity - - the current state
      manualStateDescriptor - - the state descriptor that maps with the current state.
      Returns:
      the event.
    • obtainActionEvent

      protected String obtainActionEvent(StateEntityType stateEntity, AutomaticStateDescriptor actionStateDescriptor) throws Exception
      Throws:
      Exception