Package ptolemy.domains.tdl.kernel
Class TDLReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- ptolemy.domains.tdl.kernel.TDLReceiver
-
- All Implemented Interfaces:
Receiver,StateReceiver
public class TDLReceiver extends AbstractReceiver implements StateReceiver
A TDL receiver stores a token until it gets a new token. A call to hasToken of a TDL receiver will always succeed. The TDL receiver is based on the Giotto receiver.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Patricia Derler
-
-
Constructor Summary
Constructors Constructor Description TDLReceiver()Construct an empty TDLReceiver with no container.TDLReceiver(IOPort container)Construct an empty TDLReceiver with the specified container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear this receiver of any contained tokens.voidcopyTokensTo(TDLReceiver newReceiver)Copy tokens to another receiver.java.util.List<Token>elementList()Return a list with the token currently in the receiver, or an empty list if there is no such token.Tokenget()Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update.TokengetTok()access method for the token, for testing purposes.booleanhasRoom()Return true, since writing to this receiver is always allowed.booleanhasRoom(int numberOfTokens)Return true, since writing to this receiver is always allowed.booleanhasToken()Return true if there is a token available.booleanhasToken(int numberOfTokens)Return true if the receiver has at least one token available.voidinit(Token token)Set the initial value of the receiver.voidput(Token token)Put a token into this receiver.Tokenremove()Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update and reset the _token only.voidreset()Reset the receiver by removing all tokens from the receiver.voidupdate()Update the receiver by making the last token that has been passed to put() available to get().-
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, setContainer, toString
-
-
-
-
Constructor Detail
-
TDLReceiver
public TDLReceiver()
Construct an empty TDLReceiver with no container.
-
TDLReceiver
public TDLReceiver(IOPort container) throws IllegalActionException
Construct an empty TDLReceiver 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. FIXME. Should rename and replace all the reset() with clear().- Specified by:
clearin interfaceReceiver- Overrides:
clearin classAbstractReceiver
-
elementList
public java.util.List<Token> elementList()
Return a list with the token currently in the receiver, or an empty list if there is no such token.- Specified by:
elementListin interfaceReceiver- Overrides:
elementListin classAbstractReceiver- Returns:
- A list of instances of Token.
-
get
public Token get() throws NoTokenException
Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update.- Specified by:
getin interfaceReceiver- Specified by:
getin classAbstractReceiver- Returns:
- A token.
- Throws:
NoTokenException- If no token is available.
-
hasRoom
public boolean hasRoom()
Return true, since writing to this receiver is always allowed.- Specified by:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- Returns:
- True.
-
hasRoom
public final boolean hasRoom(int numberOfTokens)
Return true, since writing to this receiver is always allowed.- Specified by:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- Parameters:
numberOfTokens- The size of tokens to be written to the receiver.- Returns:
- True.
-
hasToken
public boolean hasToken()
Return true if there is a token available. A token is available whenever put() has been called at least once followed by a call to the update() method.- Specified by:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- Returns:
- True if there is a token available.
-
hasToken
public final boolean hasToken(int numberOfTokens)
Return true if the receiver has at least one token available. Any number of calls to get() is allowed and will return the same available token.- Specified by:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- Parameters:
numberOfTokens- The number of tokens available in this receiver.- Returns:
- True if there is a token available.
-
put
public void put(Token token) throws NoRoomException
Put a token into this receiver. Any token which has been put into the receiver before without calling update will be lost. The token becomes available to the get() method only after update() is called.Note that putting a null into this receiver will leave the receiver empty after update. The receiver does not check against this but expects that IOPort will always put non-null tokens into receivers.
- Specified by:
putin interfaceReceiver- Specified by:
putin classAbstractReceiver- Parameters:
token- The token to be put into this receiver.- Throws:
NoRoomException- Not thrown in this base class.
-
remove
public Token remove() throws NoTokenException
Get the contained and available token, i.e., get the last token that has been put into the receiver before the last update and reset the _token only.- Returns:
- A token.
- Throws:
NoTokenException- If no token is available.
-
reset
public void reset()
Reset the receiver by removing all tokens from the receiver.- Specified by:
resetin interfaceReceiver- Overrides:
resetin classAbstractReceiver
-
update
public void update()
Update the receiver by making the last token that has been passed to put() available to get().
-
init
public void init(Token token)
Set the initial value of the receiver.- Parameters:
token- The initial token.
-
getTok
public Token getTok()
access method for the token, for testing purposes. TODO remove.- Returns:
- The token.
-
copyTokensTo
public void copyTokensTo(TDLReceiver newReceiver)
Copy tokens to another receiver. This is used in a mode switch if the same task exists in the target mode.- Parameters:
newReceiver- Receiver that gets the copied tokens.
-
-