Class STMImpl<StateEntityType extends StateEntity>
- Type Parameters:
StateEntityType
-
- All Implemented Interfaces:
STM<StateEntityType>
- Author:
- Raja Shankar Kolluru
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate StateEntityType
doEndStateChecks
(State endState, StateEntityType stateEntity, Object transitionParam) private void
executeEndStateEntryAction
(State startState, State endState, StateEntityType stateEntity) private void
executeStartStateExitAction
(State startState, StateEntityType stateEntity) private StateEntityType
internalProceed
(StateEntityType stateEntity, String startingEventId, Object transitionParam, boolean doAuthChecks) private boolean
isBeginning
(State startState) protected boolean
isTransitionAuthorized
(StateDescriptor startStateDescriptor, Transition transition) protected String
obtainActionEvent
(StateEntityType stateEntity, AutomaticStateDescriptor actionStateDescriptor) private Object[]
obtainEndStateAndTransition
(StateEntityType stateEntity, State startState, String startingEventId, boolean doAuthChecks) Obtains the end state and transition for the combination of start state and event Id.protected String
obtainEvent
(StateEntityType stateEntity, StateDescriptor stateDescriptor) protected String
obtainViewEvent
(StateEntity stateEntity, StateDescriptor manualStateDescriptor) A possible hook for a sub class to generate an event from a manual state.proceed
(StateEntityType stateEntity) This method allows the user to specify no starting state and feed it to the STM.proceed
(StateEntityType stateEntity, Object transitionParam) This method allows the user to specify a starting state and feed it to the STM.proceed
(StateEntityType stateEntity, String startingEventId, Object transitionParam) This method recursively calls itself to transition as far down the flow of states as possible.protected StateEntityType
retrieveMergeFromPersistentStorage
(StateEntityType originalStateEntity, String startEventId) void
setStmFlowStore
(STMFlowStore stmFlowStore) Initialization method.
-
Field Details
-
stmFlowStore
-
stmInternalTransitionInvoker
-
-
Constructor Details
-
STMImpl
public STMImpl()
-
-
Method Details
-
setStmFlowStore
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 interfaceSTM<StateEntityType extends StateEntity>
-
getStmFlowStore
-
proceed
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 interfaceSTM<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 interfaceSTM<StateEntityType extends StateEntity>
- Parameters:
stateEntity
- - the entity with a state that needs to be processed by the STMtransitionParam
- - 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 interfaceSTM<StateEntityType extends StateEntity>
- Parameters:
stateEntity
- - the entity with a state that needs to be processed by the STMstartingEventId
- - 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
-
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
A possible hook for a sub class to generate an event from a manual state.- Parameters:
stateEntity
- - the current statemanualStateDescriptor
- - the state descriptor that maps with the current state.- Returns:
- the event.
-
obtainActionEvent
protected String obtainActionEvent(StateEntityType stateEntity, AutomaticStateDescriptor actionStateDescriptor) throws Exception - Throws:
Exception
-