com.taserv.SMS
Class SimpleStateMachine

java.lang.Object
  extended by com.taserv.SMS.SimpleStateMachine
All Implemented Interfaces:
SimpleStateMachineIF

public class SimpleStateMachine
extends java.lang.Object
implements SimpleStateMachineIF

State machine implementation


Field Summary
static StateMachineObserverIF stateMachineObserver
          The mechanism for tracing state machines and thier behavior.
 
Constructor Summary
SimpleStateMachine()
           
SimpleStateMachine(java.lang.String stateMachineName)
           
 
Method Summary
 void addEntryTransition(java.lang.Object stateObj, EntryStateTransition trans)
          Adds entry transition to the state.
 void addExitTransition(java.lang.Object stateObj, ExitStateTransition trans)
          Adds exit transition to the state.
 void addState(java.lang.Enum stateID)
          Adds new state to SM or replaces existing state.
 void addState(SMStateIF state)
          Adds new state to SM or replaces existing state.
 void addTransition(java.lang.Enum origState, java.lang.Class triggerEventCls, StateTransition transition)
          Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class.
 void addTransition(java.lang.Enum origStateEnum, java.lang.Class triggerEventCls, StateTransition transition, java.lang.Enum newState)
          Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class.
 void addTransition(SMStateIF origState, java.lang.Class triggerEventCls, StateTransition transition)
          Adds new transition to the SM or replaces existing transition identified by the origState and the event class.
 void addTransition(SMStateIF origState, java.lang.Class triggerEventCls, StateTransition transition, java.lang.Enum newState)
          Adds new transition to the SM or replaces existing transition identified by the origState and the event class.
 SMStateIF getCurrentState()
          Returns current SM state
 SimpleStateMachineIF getSMMachineIF(java.lang.Enum state)
          Returns SimpleStateMachineIF interface for the state identified by state Enum
 java.lang.String getStateMachineName()
          Returns SM name
 java.util.HashMap<java.lang.Enum,SMStateIF> getStates()
          Returns states defined in the SM
 boolean handleEvent(SMEvent event)
          Entry point for SM event handling.
 void printDebugInfo()
           
 void removeEntryTransition(java.lang.Object stateObj, EntryStateTransition trans)
          Removes entry transition.
 void setCurrentState(java.lang.Enum stateID)
          Sets current SM state to the state identified by stateID
 void setCurrentState(SMStateIF state)
          Sets current SM state to the state
 void setSMMatrix(java.lang.Object[][] smMatrix)
          Adds states and transitions identified by smMatrix to the SM.
 void setSMMatrix(java.lang.Object stateObj, java.lang.Object[][] smMatrix)
          Adds states and transitions identified by smMatrix to the state identified by stateObj.
 void setSMName(java.lang.String name)
           
static void setStateMachineObserver(StateMachineObserverIF observer)
          Sets state machine observer for tracing purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stateMachineObserver

public static StateMachineObserverIF stateMachineObserver
The mechanism for tracing state machines and thier behavior. By default set to NULL so there is not tracing overhead.
It is possible to set observer with setStateMachineObserver method or by setting SMSDebuggerClass system property to the name of the class that should be set as the observer.
If SMSDebuggerClass system property is set to the observer class name, the observer will be created during SimpleStateMachine class loading and assigned as stateMachineObserver.

Constructor Detail

SimpleStateMachine

public SimpleStateMachine()

SimpleStateMachine

public SimpleStateMachine(java.lang.String stateMachineName)
Method Detail

setStateMachineObserver

public static void setStateMachineObserver(StateMachineObserverIF observer)
Sets state machine observer for tracing purposes.

Parameters:
observer - the observer to be used for all state machines

getStateMachineName

public java.lang.String getStateMachineName()
Description copied from interface: SimpleStateMachineIF
Returns SM name

Specified by:
getStateMachineName in interface SimpleStateMachineIF

setSMName

public void setSMName(java.lang.String name)

getStates

public java.util.HashMap<java.lang.Enum,SMStateIF> getStates()
Description copied from interface: SimpleStateMachineIF
Returns states defined in the SM

Specified by:
getStates in interface SimpleStateMachineIF
Returns:
copy of the defined states collection

getCurrentState

public SMStateIF getCurrentState()
Description copied from interface: SimpleStateMachineIF
Returns current SM state

Specified by:
getCurrentState in interface SimpleStateMachineIF

setSMMatrix

public void setSMMatrix(java.lang.Object[][] smMatrix)
                 throws SMBadMatrix,
                        SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds states and transitions identified by smMatrix to the SM.

Specified by:
setSMMatrix in interface SimpleStateMachineIF
Parameters:
smMatrix - transitions matrix identifying the behavior of the SM. The matrix should have the following format:
    
{
 { state <Enum or SMStateIF>, eventClass<Class>, transitionObject<StateTransition>, newState <Enum>},
 { state1 <Enum or SMStateIF>, eventClass1<Class>, transitionObject1<StateTransition>, newState1 <Enum>},
 …
}
Throws:
SMBadMatrix - if smMatrix format does not comform to the above format
SMStateCanNotCopy - if one of the states has to be replaced and the existing state data could not be copied to the new state

setSMMatrix

public void setSMMatrix(java.lang.Object stateObj,
                        java.lang.Object[][] smMatrix)
                 throws SMBadMatrix,
                        SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds states and transitions identified by smMatrix to the state identified by stateObj. The state identified by stateObj will be converted to SMCompositeState if needed.

Specified by:
setSMMatrix in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state that should have behavior identified by smMatrix
smMatrix - transitions matrix identifying the behavior of the state identified by stateObj The matrix should have the following format:
    
{
 { state <Enum or SMStateIF>, eventClass<Class>, transitionObject<StateTransition>, newState <Enum>},
 { state1 <Enum or SMStateIF>, eventClass1<Class>, transitionObject1<StateTransition>, newState1 <Enum>},
 …
}
Throws:
SMBadMatrix - if smMatrix format does not comform to the above format or stateObj is not Enum or SMStateIF
SMStateCanNotCopy - if one of the states has to be replaced and the existing state data could not be copied to the new state

addState

public void addState(java.lang.Enum stateID)
              throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new state to SM or replaces existing state. In case of replace existing state data such as events, transitions, etc. copied into new state.

Specified by:
addState in interface SimpleStateMachineIF
Parameters:
stateID - enum id of the state to be added
Throws:
SMStateCanNotCopy - Thrown if the new state can not copy existing state into itself

addState

public void addState(SMStateIF state)
              throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new state to SM or replaces existing state. In case of replace existing state data such as events, transitions, etc. copied into new state.

Specified by:
addState in interface SimpleStateMachineIF
Parameters:
state - state to be added
Throws:
SMStateCanNotCopy - Thrown if the new state can not copy existing state into itself

setCurrentState

public void setCurrentState(SMStateIF state)
                     throws SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Sets current SM state to the state

Specified by:
setCurrentState in interface SimpleStateMachineIF
Parameters:
state - the state to be set current
Throws:
SMStateNotFound - Thrown if the state does not exist in the SM

setCurrentState

public void setCurrentState(java.lang.Enum stateID)
                     throws SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Sets current SM state to the state identified by stateID

Specified by:
setCurrentState in interface SimpleStateMachineIF
Parameters:
stateID - enum id of the state to be set current
Throws:
SMStateNotFound - Thrown if the state does not exist in the SM

addTransition

public void addTransition(SMStateIF origState,
                          java.lang.Class triggerEventCls,
                          StateTransition transition)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origState and the event class. The new state after execution of the transition identified by the return value of transition.

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origState - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(SMStateIF origState,
                          java.lang.Class triggerEventCls,
                          StateTransition transition,
                          java.lang.Enum newState)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origState and the event class. The new state after execution of the transition identified by newState if the return value of transition is NULL, otherwise the new states set to the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origState - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
newState - enum id of the state to set current after execution of the transition if the return value of the transition is NULL
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(java.lang.Enum origState,
                          java.lang.Class triggerEventCls,
                          StateTransition transition)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class. The new state after execution of the transition identified by the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origState - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

addTransition

public void addTransition(java.lang.Enum origStateEnum,
                          java.lang.Class triggerEventCls,
                          StateTransition transition,
                          java.lang.Enum newState)
                   throws SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds new transition to the SM or replaces existing transition identified by the origStateEnum and the event class. The new state after execution of the transition identified by newState if the return value of transition is NULL, otherwise the new states set to the return value of the transition

Specified by:
addTransition in interface SimpleStateMachineIF
Parameters:
origStateEnum - the originating state of the transition
triggerEventCls - the class of the event that should trigger the transition
transition - the transition that will be preformed during handling of the triggerEvent assuming the current state is origState
newState - enum id of the state to set current after execution of the transition if the return value of the transition is NULL
Throws:
SMStateCanNotCopy - Thrown if the state identified by origState.stateID existed in the SM and was not equal to the origState and the existed state data can not be copied into the origState

handleEvent

public boolean handleEvent(SMEvent event)
Description copied from interface: SimpleStateMachineIF
Entry point for SM event handling. This method is used by SM scheduler to dispatch events to target SM. This method dispatches the event to the current SM state and if the state consumes the event, updates SM current state according to the state returned value. If the returned value is NULL, the current state does not change.

Specified by:
handleEvent in interface SimpleStateMachineIF
Parameters:
event - event to be handled by SM
Returns:
true if event was consumed by SM, false otherwise

addEntryTransition

public void addEntryTransition(java.lang.Object stateObj,
                               EntryStateTransition trans)
                        throws SMBadMatrix,
                               SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds entry transition to the state. The transition will be preformed every time the SM current state changes to the state

Specified by:
addEntryTransition in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state
trans - the entry transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF
SMStateCanNotCopy - if can not copy state data

removeEntryTransition

public void removeEntryTransition(java.lang.Object stateObj,
                                  EntryStateTransition trans)
                           throws SMBadMatrix
Description copied from interface: SimpleStateMachineIF
Removes entry transition.

Specified by:
removeEntryTransition in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state
trans - the entry transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF

addExitTransition

public void addExitTransition(java.lang.Object stateObj,
                              ExitStateTransition trans)
                       throws SMBadMatrix,
                              SMStateCanNotCopy
Description copied from interface: SimpleStateMachineIF
Adds exit transition to the state. The transition will be preformed every time the SM current state changes from the state to any other state

Specified by:
addExitTransition in interface SimpleStateMachineIF
Parameters:
stateObj - Enum or SMStateIF identifying the state
trans - the exit transition
Throws:
SMBadMatrix - if state is not Enum or SMStateIF
SMStateCanNotCopy - if can not copy state data

getSMMachineIF

public SimpleStateMachineIF getSMMachineIF(java.lang.Enum state)
                                    throws SMNotCompositeState,
                                           SMStateNotFound
Description copied from interface: SimpleStateMachineIF
Returns SimpleStateMachineIF interface for the state identified by state Enum

Specified by:
getSMMachineIF in interface SimpleStateMachineIF
Parameters:
state - Enum identifying the state
Returns:
SimpleStateMachineIF interface if the state is composite, otherwise throws SMNotCompositeState
Throws:
SMNotCompositeState - if the state is not composite
SMStateNotFound - if the state does not exist

printDebugInfo

public void printDebugInfo()


Copyright © 2004 TAServ. All Rights Reserved.