ptolemy.domains.dt.kernel
Class DTReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.domains.sdf.kernel.SDFReceiver
          extended by ptolemy.domains.dt.kernel.DTReceiver
All Implemented Interfaces:
Receiver

public class DTReceiver
extends SDFReceiver

A first-in, first-out (FIFO) queue receiver with variable capacity. Tokens are put into the receiver with the put() method, and removed from the receiver with the get() method. The token removed is the oldest one in the receiver. Time is incremented by a fixed amount delta time every time the get() method is called. Each receiver has its own value of delta time. We calculate delta time as "period / (rate * repetitions)" where:

Since:
Ptolemy II 1.0
Version:
$Id: DTReceiver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
C. Fong
Accepted Rating:
Yellow (vogel)
Proposed Rating:
Yellow (chf)

Field Summary
private  double _deltaTime
           
private  Actor _from
           
private  IOPort _fromPort
           
private  int _inRate
           
private  Time _localTime
           
private  int _outrate
           
private  Actor _to
           
private  int _tokenFlowRate
           
private  IOPort _toPort
           
(package private)  boolean overrideHasToken
           
 
Fields inherited from class ptolemy.domains.sdf.kernel.SDFReceiver
_waitingTokens, INFINITE_CAPACITY
 
Constructor Summary
DTReceiver()
          Construct an empty receiver with no container.
DTReceiver(IOPort container)
          Construct an empty receiver with the specified container.
DTReceiver(IOPort container, int size)
          Construct an empty receiver with the specified container and size.
 
Method Summary
(package private)  void _debugViewReceiverInfo()
          For debugging purposes.
private  void _init()
          Initialize the DTReceiver.
 void calculateDeltaTime()
          Calculate the constant time increment for this receiver.
 void determineEnds()
          Determine the source and destination ports that use this receiver in their communications.
 Token get()
          Remove the first token (the oldest one) from the receiver and return it.
 double getCurrentTime()
          Deprecated. As of Ptolemy II 4.1, replaced by getModelTime()
 double getDeltaTime()
          Return the time interval between tokens for this receiver.
 Time getModelTime()
          Return the local time associated with this receiver.
 TypedIOPort getSourcePort()
          Return the port that feeds this Receiver The port returned by this method is precalculated during the determineEnds() method call.
 int getTokenFlowRate()
          Return the token flow rate for this receiver In DT, the token flow rate has the value "rate * repetitions"; where 'rate' is the port rate and 'repetitions' is the firing count of the actor that contains this receiver.
 boolean hasToken()
          Return true if get() will succeed in returning a token.
(package private)  void initializeLocalTime(Time time)
          Initialize the local time to the specified time.
 void put(Token token)
          Put a token to the receiver.
 void reset()
          Reset this receiver to its initial state, which includes calling clear() and resetting the current time to 0.0.
 
Methods inherited from class ptolemy.domains.sdf.kernel.SDFReceiver
clear, elementList, get, getArray, getCapacity, getHistoryCapacity, hasRoom, hasRoom, hasToken, historyElements, historySize, setCapacity, setHistoryCapacity, size
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getContainer, isKnown, putArray, putArrayToAll, putToAll, setContainer, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

overrideHasToken

boolean overrideHasToken

_deltaTime

private double _deltaTime

_from

private Actor _from

_fromPort

private IOPort _fromPort

_inRate

private int _inRate

_localTime

private Time _localTime

_outrate

private int _outrate

_tokenFlowRate

private int _tokenFlowRate

_to

private Actor _to

_toPort

private IOPort _toPort
Constructor Detail

DTReceiver

public DTReceiver()
Construct an empty receiver with no container.


DTReceiver

public DTReceiver(IOPort container)
           throws IllegalActionException
Construct an empty receiver with the specified container.

Parameters:
container - The container of the receiver.
Throws:
IllegalActionException - If the container does not accept this receiver.

DTReceiver

public DTReceiver(IOPort container,
                  int size)
           throws IllegalActionException
Construct an empty receiver with the specified container and size.

Parameters:
container - The container of the receiver.
size - The size of the buffer for the receiver.
Throws:
IllegalActionException - If the container does not accept this receiver.
Method Detail

calculateDeltaTime

public void calculateDeltaTime()
                        throws IllegalActionException
Calculate the constant time increment for this receiver. This method should only be invoked by the DT Director.

Throws:
IllegalActionException - If there is an error in getting attribute information from the ports.

determineEnds

public void determineEnds()
                   throws IllegalActionException
Determine the source and destination ports that use this receiver in their communications. In DT, the source and destination ports are distinct for each receiver because "non-deterministic merge" type relations are not allowed.

Throws:
IllegalActionException

get

public Token get()
Remove the first token (the oldest one) from the receiver and return it. If there is no token in the receiver, throw an exception. Increment the local time by deltaTime.

Specified by:
get in interface Receiver
Overrides:
get in class SDFReceiver
Returns:
The oldest token in the receiver.

getCurrentTime

public double getCurrentTime()
Deprecated. As of Ptolemy II 4.1, replaced by getModelTime()

Return the local time associated with this receiver.

Overrides:
getCurrentTime in class AbstractReceiver
Returns:
The local time associated with this receiver.

getDeltaTime

public double getDeltaTime()
Return the time interval between tokens for this receiver. Delta time is defined as "period / (token flow rate)"; where period is the director's period parameter and token flow rate is the number of tokens flowing through this receiver per iteration

Returns:
The time interval between tokens

getModelTime

public Time getModelTime()
Return the local time associated with this receiver.

Overrides:
getModelTime in class AbstractReceiver
Returns:
The local time associated with this receiver.

getSourcePort

public TypedIOPort getSourcePort()
Return the port that feeds this Receiver The port returned by this method is precalculated during the determineEnds() method call.

Returns:
The port that feeds this receiver.

getTokenFlowRate

public int getTokenFlowRate()
Return the token flow rate for this receiver In DT, the token flow rate has the value "rate * repetitions"; where 'rate' is the port rate and 'repetitions' is the firing count of the actor that contains this receiver.

Returns:
The token flow rate of this receiver

hasToken

public boolean hasToken()
Return true if get() will succeed in returning a token.

Specified by:
hasToken in interface Receiver
Overrides:
hasToken in class SDFReceiver
Returns:
A boolean indicating whether there is a token in this receiver.

put

public void put(Token token)
Put a token to the receiver. If the port feeding this receiver is null, report an internal error.

Specified by:
put in interface Receiver
Overrides:
put in class SDFReceiver
Parameters:
token - The token to be put to the receiver, or null to put no token.
Throws:
InternalErrorException - If the source port is null.

reset

public void reset()
           throws IllegalActionException
Reset this receiver to its initial state, which includes calling clear() and resetting the current time to 0.0.

Specified by:
reset in interface Receiver
Overrides:
reset in class AbstractReceiver
Throws:
IllegalActionException - If there is no director.

_debugViewReceiverInfo

void _debugViewReceiverInfo()
For debugging purposes. Display pertinent information about this receiver.


initializeLocalTime

void initializeLocalTime(Time time)
Initialize the local time to the specified time. FIXME: The specified time is assumed to have value 0.0. Instead, the director should have a startTime parameter. This method is designed for the newReceiver method of DTDirector only.

Parameters:
time - The desired local time.

_init

private void _init()
Initialize the DTReceiver. Set the cached information regarding source and destination actors to null. Set the local time to zero. Set deltaTime to zero.