Package ptolemy.domains.tm.kernel
Class TMReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- 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 destination receiver is this receiver.
- The destination actor is the container's container of this receiver.
- The token is the received token.
- The priority is the value of the parameter with name priority of the container of this receiver. If the container does not has a parameter with that name, then look at the actor. If none of them has the parameter, then use the default priority value, which is java.Thread.NORMAL_PRIORITY.
- The flag hasStarted is false.
- The processing time is obtained from the container or the container's container of this receiver, similar to the way obtaining the priority value. If none of them has the parameter, then use the default value 0.
- Since:
- Ptolemy II 2.0
- Version:
- $Id$
- Author:
- Edward A. Lee, Jie Liu
- See Also:
TMDirector
- Pt.AcceptedRating:
- Yellow (janneck)
- Pt.ProposedRating:
- Yellow (liuj)
-
-
Constructor Summary
Constructors Constructor Description TMReceiver()
Construct an empty TMReceiver with no container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
Method Detail
-
clear
public void clear()
Clear this receiver of any contained tokens.- Specified by:
clear
in interfaceReceiver
- Overrides:
clear
in classAbstractReceiver
-
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 interfaceReceiver
- Overrides:
elementList
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
get
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
hasToken
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
hasToken
in classAbstractReceiver
- 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 interfaceReceiver
- Specified by:
put
in classAbstractReceiver
- 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().
-
-