com.atomikos.finitestates
Class FSMImp<Status>

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

public class FSMImp<Status>
extends Object
implements FSM<Status>

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


Constructor Summary
FSMImp(Object eventsource, TransitionTable<Status> transitiontable, Status initialstate)
          Creates a new instance with a given event source.
FSMImp(TransitionTable<Status> transitiontable, Status initialstate)
          Constructor.
 
Method Summary
protected  void addEnterListener(Hashtable<Status,Hashtable<EventListener,Object>> listeners, EventListener lstnr, Status state)
          Help function for adding enter listeners.
 void addFSMEnterListener(FSMEnterListener<Status> lstnr, Status state)
          Add an enter event listener.
 void addFSMPreEnterListener(FSMPreEnterListener<Status> lstnr, Status state)
           
 void addFSMPreTransitionListener(FSMPreTransitionListener<Status> lstnr, Status from, Status to)
           
 void addFSMTransitionListener(FSMTransitionListener<Status> lstnr, Status from, Status to)
           
protected  void addTransitionListener(Hashtable listeners, Object lstnr, Status from, Status to)
          Help function for adding transition listeners.
 Status getState()
           
protected  void notifyListeners(Hashtable<Status,Hashtable<EventListener,Object>> listeners, Status state, boolean pre)
          Notify the enter listeners.
protected  void notifyListeners(Hashtable<Status,Hashtable<EventListener,Object>> listeners, Status from, Status to, boolean pre)
          Notify transition listeners.
 void setState(Status 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<Status> transitiontable,
              Status initialstate)
Constructor.

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

FSMImp

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

setState

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

Specified by:
setState in interface StateMutable<Status>
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<Status> lstnr,
                                Status state)
Description copied from interface: FSMEnterEventSource
Add an enter event listener.

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

addFSMPreEnterListener

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

addFSMTransitionListener

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

addFSMPreTransitionListener

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


Copyright © 2014. All Rights Reserved.