ptolemy.actor.util
Class PeriodicDirectorHelper

java.lang.Object
  extended by ptolemy.actor.util.PeriodicDirectorHelper

public class PeriodicDirectorHelper
extends java.lang.Object

This is a helper class for directors implementing PeriodicDirector. It collects common functionality to avoid code duplication.

Since:
Ptolemy II 8.0
Version:
$Id: PeriodicDirectorHelper.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Edward A. Lee
See Also:
PeriodicDirector
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (eal)

Field Summary
private  PeriodicDirector _director
          The associated director.
private  Time _nextFiringTime
          The expected next firing time.
 
Constructor Summary
PeriodicDirectorHelper(PeriodicDirector director)
          Construct a new helper.
 
Method Summary
private  Time _fireContainerAt(Time time)
          Request a firing of the container of the director at the specified time and throw an exception if the executive director does not agree to do it at the requested time.
 Time fireAt(Actor actor, Time time)
          Request a firing of the given actor at the given absolute time, and return the time at which the specified will be fired.
 void initialize()
          If the period parameter is greater than zero, then request a first firing of the executive director, if there is one.
 void postfire()
          If the period parameter is greater than 0.0, then if the associated director is at the top level, then increment its time by the specified period, and otherwise request a refiring at the current time plus the period.
 boolean prefire()
          If the period value is greater than zero, then return true if the current time is a multiple of the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_director

private PeriodicDirector _director
The associated director.


_nextFiringTime

private Time _nextFiringTime
The expected next firing time.

Constructor Detail

PeriodicDirectorHelper

public PeriodicDirectorHelper(PeriodicDirector director)
                       throws IllegalActionException
Construct a new helper.

Parameters:
director - The associated director.
Throws:
IllegalActionException - If the argument is not an instance of Director.
Method Detail

fireAt

public Time fireAt(Actor actor,
                   Time time)
            throws IllegalActionException
Request a firing of the given actor at the given absolute time, and return the time at which the specified will be fired. If the period is 0.0 and there is no enclosing director, then this method returns the current time. If the period is 0.0 and there is an enclosing director, then this method delegates to the enclosing director, returning whatever it returns. If the period is not 0.0, then this method checks to see whether the requested time is equal to the current time plus an integer multiple of the period. If so, it returns the requested time. If not, it returns the earliest future time that exceeds the requested time.

Parameters:
actor - The actor scheduled to be fired.
time - The requested time.
Returns:
Either the requested time or the current time plus the period or whatever the enclosing director returns.
Throws:
IllegalActionException - If the operation is not permissible (e.g. the given time is in the past).

initialize

public void initialize()
                throws IllegalActionException
If the period parameter is greater than zero, then request a first firing of the executive director, if there is one.

Throws:
IllegalActionException - If the superclass throws it.

postfire

public void postfire()
              throws IllegalActionException
If the period parameter is greater than 0.0, then if the associated director is at the top level, then increment its time by the specified period, and otherwise request a refiring at the current time plus the period.

Throws:
IllegalActionException - If the period parameter cannot be evaluated.

prefire

public boolean prefire()
                throws IllegalActionException
If the period value is greater than zero, then return true if the current time is a multiple of the value.

Returns:
true If either the period has value 0.0 or the current time is a multiple of the period.
Throws:
IllegalActionException - If the period parameter cannot be evaluated.

_fireContainerAt

private Time _fireContainerAt(Time time)
                       throws IllegalActionException
Request a firing of the container of the director at the specified time and throw an exception if the executive director does not agree to do it at the requested time. If there is no executive director (this director is at the top level), then ignore the request. This method is essentially a duplicate of the method in Director, which is not accessible.

Parameters:
time - The requested time.
Returns:
The time that the executive director indicates it will fire this director, or an instance of Time with value Double.NEGATIVE_INFINITY if there is no executive director.
Throws:
IllegalActionException - If the director does not agree to fire the actor at the specified time, or if there is no director.