ptolemy.domains.de.kernel
Class DEReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.domains.de.kernel.DEReceiver
All Implemented Interfaces:
Receiver
Direct Known Subclasses:
WirelessReceiver

public class DEReceiver
extends AbstractReceiver

An implementation of the ptolemy.actor.Receiver interface for the DE domain.

The put() method stores the given token in this receiver and posts a trigger event to the director. The director is responsible to dequeue that trigger event and invoke the actor that contains this receiver. The get() method returns the first available token from the receiver.

Before firing an actor, the director is expected to put at least one token into at least one of the receivers contained by the actor.

Since:
Ptolemy II 0.2
Version:
$Id: DEReceiver.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Lukito Muliadi, Edward A. Lee, Jie Liu, Haiyang Zheng
Accepted Rating:
Yellow (hyzheng)
Proposed Rating:
Green (hyzheng)

Field Summary
private  DEDirector _director
           
protected  long _directorVersion
          The version of the workspace of container, used for caching by _getDirector().
protected  java.util.LinkedList _tokens
          List for storing tokens.
 
Constructor Summary
DEReceiver()
          Construct an empty DEReceiver with no container.
DEReceiver(IOPort container)
          Construct an empty DEReceiver with the specified container.
 
Method Summary
private  DEDirector _getDirector()
          Return the director that created this receiver.
 void clear()
          Clear this receiver of any contained tokens.
 java.util.List<Token> elementList()
          Return a list with tokens that are currently in the receiver available for get() or getArray(), beginning with the oldest one.
 Token get()
          Get the first token from the receiver.
 boolean hasRoom()
          Return true, indicating that there is always room.
 boolean hasRoom(int tokens)
          Return true if the receiver has room for putting the given number of tokens into it (via the put() method).
 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 tokens available to the get() method.
 void put(Token token)
          Put a token into this receiver and post a trigger event to the director.
 
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

_directorVersion

protected long _directorVersion
The version of the workspace of container, used for caching by _getDirector(). Derived classes that modify the cache may need to update this variable.


_tokens

protected java.util.LinkedList _tokens
List for storing tokens. Access with clear(), add(), and take().


_director

private DEDirector _director
Constructor Detail

DEReceiver

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


DEReceiver

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

Parameters:
container - The container.
Throws:
IllegalActionException - If the container does not accept this receiver.
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 tokens that are currently in the receiver available for get() or getArray(), beginning with the oldest one.

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 the first token from the receiver. The token returned is one that was put in the receiver with a timestamp equal to or earlier than the current time. If there is no token, throw an exception. If this receiver contains more than one event, the oldest event is removed first. In other words, this receiver has a FIFO behavior.

Specified by:
get in interface Receiver
Specified by:
get in class AbstractReceiver
Returns:
A token.
Throws:
NoTokenException - If there are no more tokens. This is a runtime exception, so it need not to be declared explicitly.

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 boolean hasRoom(int tokens)
Return true if the receiver has room for putting the given number of tokens into it (via the put() method). Returning true in this method should also guarantee that calling the put() method will not result in an exception.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Parameters:
tokens - An int indicating the number of spaces available.
Returns:
True.

hasToken

public 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 boolean hasToken(int numberOfTokens)
Return true if there are numberOfTokens tokens tokens available to the get() method.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Parameters:
numberOfTokens - An int indicating how many tokens are needed.
Returns:
True if there are numberOfTokens tokens available.

put

public void put(Token token)
Put a token into this receiver and post a trigger event to the director. The director will be responsible to dequeue the trigger event at the correct timestamp and microstep and invoke the corresponding actor whose input port contains this receiver. This receiver may contain more than one events.

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.

_getDirector

private DEDirector _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 DEDirector.
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 DEDirector.