ptolemy.domains.tm.kernel
Class TMReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.domains.tm.kernel.TMReceiver
All Implemented Interfaces:
Receiver

public class TMReceiver
extends AbstractReceiver

The receiver for the TM domain. This receiver contains a FIFO queue. Upon receiving a token, it creates a TMEvent. The properties of the TM events are:

The event is then queued with the director, so it is not immediately available by the get() method. Later, the director may make the token available again by calling the _triggerEvent() method. See the TMDirector class for the event dispatching mechanism.

Since:
Ptolemy II 2.0
Version:
$Id: TMReceiver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee, Jie Liu
See Also:
TMDirector
Accepted Rating:
Yellow (janneck)
Proposed Rating:
Yellow (liuj)

Field Summary
private  TMDirector _director
           
private  long _directorVersion
           
private  java.util.LinkedList _tokens
           
 
Constructor Summary
TMReceiver()
          Construct an empty TMReceiver with no container.
 
Method Summary
protected  void _triggerEvent(Token token)
          Make a token available to the get() method.
 void clear()
          Clear this receiver of any contained tokens.
 java.util.List<Token> elementList()
          Return a list with the tokens currently in the receiver, or an empty list if there are no such tokens.
 Token get()
          Get a token from the receiver.
 TMDirector getDirector()
          Return the director that created this receiver.
 boolean hasRoom()
          Return true, indicating that there is always room.
 boolean hasRoom(int tokens)
          Return true, indicating that there is always room for any number of tokens.
 boolean hasToken()
          Return true if there is at least one token available to the get() method.
 boolean hasToken(int numberOfTokens)
          Return true if there are numberOfTokens tokens available to the get() method.
 void put(Token token)
          Put a token into this receiver.
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, reset, setContainer, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_director

private TMDirector _director

_directorVersion

private long _directorVersion

_tokens

private java.util.LinkedList _tokens
Constructor Detail

TMReceiver

public TMReceiver()
Construct an empty TMReceiver with no container.

Method Detail

clear

public void clear()
Clear this receiver of any contained tokens.

Specified by:
clear in interface Receiver
Overrides:
clear in class AbstractReceiver

elementList

public java.util.List<Token> elementList()
Return a list with the tokens currently in the receiver, or an empty list if there are no such tokens.

Specified by:
elementList in interface Receiver
Overrides:
elementList in class AbstractReceiver
Returns:
A list of instances of Token.

get

public Token get()
          throws NoTokenException
Get a token from the receiver. The token returned is one that was put in the receiver that is ready for process. A token is ready to be processed if it has the highest priority among all the appending events (system wide), and the resource is ready to be allocated to its destination actor. Whether the resource is ready depends on whether there is any active tasks, and whether the execution is preemptive. Note that there might be multiple such tokens in the receiver. In that case, FIFO behaviour is used with respect to the put() method. If there is no such token, throw an exception. This method is synchronized since the actor may not execute in the same thread as the director.

Specified by:
get in interface Receiver
Specified by:
get in class AbstractReceiver
Returns:
A token.
Throws:
NoTokenException - Not thrown in this base class.

getDirector

public TMDirector getDirector()
                       throws IllegalActionException
Return the director that created this receiver. If this receiver is an inside receiver of an output port of an opaque composite actor, then the director will be the local director of the container of its port. Otherwise, it's the executive director of the container of its port. Note that the director returned is guaranteed to be non-null. This method is read synchronized on the workspace.

Returns:
An instance of TMDirector that creates this receiver.
Throws:
IllegalActionException - If there is no container port, or if the port has no container actor, or if the actor has no director, or if the director is not an instance of TMDirector.

hasRoom

public final boolean hasRoom()
Return true, indicating that there is always room.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Returns:
True.

hasRoom

public final boolean hasRoom(int tokens)
Return true, indicating that there is always room for any number of tokens.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Parameters:
tokens - The number of tokens, currently ignored.
Returns:
True.

hasToken

public final boolean hasToken()
Return true if there is at least one token available to the get() method.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Returns:
True if there are more tokens.

hasToken

public final boolean hasToken(int numberOfTokens)
Return true if there are numberOfTokens tokens available to the get() method.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Parameters:
numberOfTokens - The number of tokens, currently ignored.
Returns:
True if there are numberOfTokens tokens available.

put

public void put(Token token)
Put a token into this receiver. Note that this token does not become immediately available to the get() method. Instead, the token is queued with the director, and the director must put the token back into this receiver using the _triggerEvent() protected method in order for the token to become available to the get() method. By default, this token will be enqueued by the director with the default priority -- 5. However, by setting a priority parameter to the container of this receiver, or the container's container, you can enqueue the event with any priority. This method is synchronized since the actor may not execute in the same thread as the director.

Specified by:
put in interface Receiver
Specified by:
put in class AbstractReceiver
Parameters:
token - The token to be put, or null to put no token.

_triggerEvent

protected void _triggerEvent(Token token)
Make a token available to the get() method. Normally, only a director will call this method.

Parameters:
token - The token to make available to get().