org.progeeks.fsm
Class FiniteStateMachine

java.lang.Object
  extended by org.progeeks.fsm.FiniteStateMachine
All Implemented Interfaces:
StateHandler

public class FiniteStateMachine
extends java.lang.Object
implements StateHandler

Provides simple and fast state based processing of message events. FiniteStateMachine implements StateHandler because technically there's no reason that they can't be nested. I don't see a good use-case for it, but it's certainly possible.

Version:
$Revision: 1.1 $
Author:
Paul Speed

Constructor Summary
FiniteStateMachine(int stateCount, int messageTypeCount)
          Creates a new finite state machine that can process information using the specified number of states and message types.
 
Method Summary
 StateHandler getStateHandler(int state, int message)
          Returns the state handler for the specified state and message.
 int handleMessage(int state, int message, java.lang.Object stateInfo)
          Handles the specified message information by looking up the appropriate handler.
 void initializeMessageType(int messageType, StateHandler handler)
          Sets the specified handler to process all messages of the specified type no matter to which state they arrive.
 void initializeState(int state, StateHandler handler)
          Sets the specified handler to process all messages for the specified state.
 void initializeStateMachine(StateHandler handler)
          Initializes all states and message types to the specified handler.
 void setStateHandler(int state, int message, StateHandler handler)
          Sets the specified handler to process messages for the specified state and message type.
 void setStateHandlers(int[] states, int[] messages, StateHandler handler)
          Sets the specified handler to process messages for the specified states and message types.
 void setStateHandlers(int[] states, int message, StateHandler handler)
          Sets the specified handler to process messages for the specified states and message type.
 void setStateHandlers(int state, int[] messages, StateHandler handler)
          Sets the specified handler to process messages for the specified state and message types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FiniteStateMachine

public FiniteStateMachine(int stateCount,
                          int messageTypeCount)
Creates a new finite state machine that can process information using the specified number of states and message types.

Method Detail

handleMessage

public int handleMessage(int state,
                         int message,
                         java.lang.Object stateInfo)
Handles the specified message information by looking up the appropriate handler. The new state value is returned.

Specified by:
handleMessage in interface StateHandler
Parameters:
state - The current state the called this handler.
message - The numeric message to be handled.
stateInfo - The application specific data on which the handler can operate if necessary.

getStateHandler

public StateHandler getStateHandler(int state,
                                    int message)
Returns the state handler for the specified state and message.


setStateHandler

public void setStateHandler(int state,
                            int message,
                            StateHandler handler)
Sets the specified handler to process messages for the specified state and message type.


setStateHandlers

public void setStateHandlers(int[] states,
                             int message,
                             StateHandler handler)
Sets the specified handler to process messages for the specified states and message type.


setStateHandlers

public void setStateHandlers(int state,
                             int[] messages,
                             StateHandler handler)
Sets the specified handler to process messages for the specified state and message types.


setStateHandlers

public void setStateHandlers(int[] states,
                             int[] messages,
                             StateHandler handler)
Sets the specified handler to process messages for the specified states and message types.


initializeStateMachine

public void initializeStateMachine(StateHandler handler)
Initializes all states and message types to the specified handler.


initializeState

public void initializeState(int state,
                            StateHandler handler)
Sets the specified handler to process all messages for the specified state.


initializeMessageType

public void initializeMessageType(int messageType,
                                  StateHandler handler)
Sets the specified handler to process all messages of the specified type no matter to which state they arrive.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.