com.atomikos.finitestates
Class FSMImp

java.lang.Object
  extended by com.atomikos.finitestates.FSMImp
All Implemented Interfaces:
FSM, FSMEnterEventSource, FSMPreEnterEventSource, FSMPreTransitionEventSource, FSMTransitionEventSource, Stateful, StateMutable

public class FSMImp
extends Object
implements FSM

Implementation of a finite state machine. The following consistency is provided:


Constructor Summary
FSMImp(Object eventsource, TransitionTable transitiontable, Object initialstate)
          Creates a new instance with a given event source.
FSMImp(TransitionTable transitiontable, Object initialstate)
          Constructor.
 
Method Summary
protected  void addEnterListener(Hashtable listeners, Object lstnr, Object state)
          Help function for adding enter listeners.
 void addFSMEnterListener(FSMEnterListener lstnr, Object state)
          Add an enter event listener.
 void addFSMPreEnterListener(FSMPreEnterListener lstnr, Object state)
           
 void addFSMPreTransitionListener(FSMPreTransitionListener lstnr, Object from, Object to)
           
 void addFSMTransitionListener(FSMTransitionListener lstnr, Object from, Object to)
           
protected  void addTransitionListener(Hashtable listeners, Object lstnr, Object from, Object to)
          Help function for adding transition listeners.
 Object getState()
           
protected  void notifyListeners(Hashtable listeners, Object state, boolean pre)
          Notify the enter listeners.
protected  void notifyListeners(Hashtable listeners, Object from, Object to, boolean pre)
          Notify transition listeners.
 void setState(Object state)
          To set a new state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSMImp

public FSMImp(TransitionTable transitiontable,
              Object initialstate)
Constructor.

Parameters:
transitiontable - The transitiontable with valid transitions.
initialstate - The initial state of the FSM.

FSMImp

public FSMImp(Object eventsource,
              TransitionTable transitiontable,
              Object initialstate)
Creates a new instance with a given event source. Useful for cases where finite state machine behaviour is modelled by delegation to an instance of this class.

Parameters:
eventsource - The object to be used as source of events.
transitiontable - The transitiontable for state changes.
initialstate - The initial state of the FSM.
Method Detail

addEnterListener

protected void addEnterListener(Hashtable listeners,
                                Object lstnr,
                                Object state)
Help function for adding enter listeners.

Parameters:
listeners - One of the listener tables.
lstnr - The listener to add.
state - The state for which the listener wants to be notified.

addTransitionListener

protected void addTransitionListener(Hashtable listeners,
                                     Object lstnr,
                                     Object from,
                                     Object to)
Help function for adding transition listeners.

Parameters:
listeners - One of the transition listener tables.
lstnr - The listener to add.
from - The start state of the transition.
to - The end state of the transition.

notifyListeners

protected void notifyListeners(Hashtable listeners,
                               Object state,
                               boolean pre)
Notify the enter listeners.

Parameters:
listeners - One of the enter listener tables.
state - The state about to enter (or entered).
pre - True iff before entering.

notifyListeners

protected void notifyListeners(Hashtable listeners,
                               Object from,
                               Object to,
                               boolean pre)
Notify transition listeners.

Parameters:
listeners - One of the transition listener tables.
from - The initial state.
to - The end state.
pre - True iff before transition.

getState

public Object getState()
Specified by:
getState in interface Stateful
Returns:
The object representing the state.
See Also:
FSM

setState

public void setState(Object state)
              throws IllegalStateException
Description copied from interface: StateMutable
To set a new state.

Specified by:
setState in interface StateMutable
Parameters:
state - The new state.
Throws:
IllegalStateException - if the new state transition to the new state is not allowed.
See Also:
StateMutable

addFSMEnterListener

public void addFSMEnterListener(FSMEnterListener lstnr,
                                Object state)
Description copied from interface: FSMEnterEventSource
Add an enter event listener.

Specified by:
addFSMEnterListener in interface FSMEnterEventSource
Parameters:
lstnr - The listener.
state - The state to listen on.
See Also:
FSMEnterEventSource

addFSMPreEnterListener

public void addFSMPreEnterListener(FSMPreEnterListener lstnr,
                                   Object state)
Specified by:
addFSMPreEnterListener in interface FSMPreEnterEventSource
See Also:
FSMPreEnterEventSource

addFSMTransitionListener

public void addFSMTransitionListener(FSMTransitionListener lstnr,
                                     Object from,
                                     Object to)
Specified by:
addFSMTransitionListener in interface FSMTransitionEventSource
See Also:
FSMTransitionEventSource

addFSMPreTransitionListener

public void addFSMPreTransitionListener(FSMPreTransitionListener lstnr,
                                        Object from,
                                        Object to)
Specified by:
addFSMPreTransitionListener in interface FSMPreTransitionEventSource
See Also:
FSMPreTransitionEventSource


Copyright © 2011. All Rights Reserved.