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

Constructor Detail

FSMImp

public FSMImp(TxState initialstate)
Constructor.

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

FSMImp

public FSMImp(Object eventsource,
              TxState 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<TxState,Set<EventListener>> listeners,
                                EventListener lstnr,
                                TxState 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<TxState,Hashtable<TxState,Set<EventListener>>> listeners,
                                     EventListener lstnr,
                                     TxState from,
                                     TxState 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<TxState,Set<EventListener>> listeners,
                               TxState 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<TxState,Hashtable<TxState,Set<EventListener>>> listeners,
                               TxState from,
                               TxState 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 TxState getState()
Specified by:
getState in interface Stateful
Returns:
The object representing the state.
See Also:
FSM

setState

public void setState(TxState state)
              throws IllegalStateException
Specified by:
setState in interface StateMutable
Throws:
IllegalStateException - if the new state transition to the new state is not allowed.
See Also:
StateMutable

addFSMEnterListener

public void addFSMEnterListener(FSMEnterListener lstnr,
                                TxState 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,
                                   TxState state)
Specified by:
addFSMPreEnterListener in interface FSMPreEnterEventSource
See Also:
FSMPreEnterEventSource

addFSMTransitionListener

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

addFSMPreTransitionListener

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


Copyright © 2016. All Rights Reserved.