Package ptolemy.domains.metroII.kernel
Class FireMachine
- java.lang.Object
-
- ptolemy.domains.metroII.kernel.FireMachine
-
- All Implemented Interfaces:
StartOrResumable
- Direct Known Subclasses:
BlockingFire
,NonBlockingFire
,ResumableFire
public abstract class FireMachine extends java.lang.Object implements StartOrResumable
FireMachine is an abstract wrapper for Ptolemy actors to adapt to MetroII semantics. FireMachine wraps an actor with a set of FSM interfaces so that the actor can be be seen as a FSM from outside. We pre-define the following states and each state represents a state of the wrapped actor:- START: the initial state;
- BEGIN: before getfire() is called;
- FIRING: getfire() 'yield returns' (@see net.jimblackler.Utils) some internal MetroII events;
- END: after getfire() completes;
- FINAL: the final state.
For any concrete subclass of ActMachine, the StartOrResumable() interface has to be implemented, in which how the FSM react to MetroII events (or in other words, the state transitions) should be implemented.
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Liangpeng Guo
- Pt.AcceptedRating:
- Red (glp)
- Pt.ProposedRating:
- Red (glp)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FireMachine.State
Predefined states for the wrapped actor.
-
Constructor Summary
Constructors Constructor Description FireMachine(Actor actor)
Constructs an FireMachine wrapper and initialize the MetroII events.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Actor
actor()
Returns the wrapped actor.FireMachine.State
getState()
Gets the state of the wrapped actor.metroIIcomm.Event.Builder
getStateEvent()
Returns the MetroII event associated with the current state.protected metroIIcomm.Event.Builder
proposeStateEvent()
Returns the MetroII event associated with the current state and set the state of the event to be PROPOSED.void
reset()
Resets the state to be PREFIRE_BEGIN.protected void
setState(FireMachine.State state)
Sets the state of the wrapped actor.void
wrapup()
Wraps up the firing by reseting.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ptolemy.domains.metroII.kernel.StartOrResumable
startOrResume
-
-
-
-
Constructor Detail
-
FireMachine
public FireMachine(Actor actor)
Constructs an FireMachine wrapper and initialize the MetroII events.- Parameters:
actor
- the actor whose getfire() is to be wrapped.
-
-
Method Detail
-
getStateEvent
public metroIIcomm.Event.Builder getStateEvent()
Returns the MetroII event associated with the current state.- Returns:
- the MetroII event associated with the current state.
-
getState
public FireMachine.State getState()
Gets the state of the wrapped actor.- Returns:
- the state.
- See Also:
setState(State)
-
reset
public void reset()
Resets the state to be PREFIRE_BEGIN.- Specified by:
reset
in interfaceStartOrResumable
-
wrapup
public void wrapup()
Wraps up the firing by reseting.
-
actor
protected Actor actor()
Returns the wrapped actor.- Returns:
- the wrapped actor.
-
proposeStateEvent
protected metroIIcomm.Event.Builder proposeStateEvent()
Returns the MetroII event associated with the current state and set the state of the event to be PROPOSED.- Returns:
- the MetroII event associated with the current state
-
setState
protected void setState(FireMachine.State state)
Sets the state of the wrapped actor.- Parameters:
state
- the state to be set.- See Also:
getState()
-
-