Package ptolemy.actor
Class Mailbox
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- ptolemy.actor.Mailbox
-
- All Implemented Interfaces:
Receiver
- Direct Known Subclasses:
GRReceiver,MailboxBoundaryReceiver,RegisterReceiver,SysMLADirector.SysMLAReceiver,SysMLConcurrentDirector.SysMLAReceiver,SysMLSequentialDirector.SysMLSequentialReceiver
public class Mailbox extends AbstractReceiver
A token holder with capacity one.- Since:
- Ptolemy II 0.2
- Version:
- $Id$
- Author:
- Jie Liu, Edward A. Lee, Lukito Muliadi
- Pt.AcceptedRating:
- Green (neuendor)
- Pt.ProposedRating:
- Green (eal)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear this receiver of any contained token.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 Token.booleanhasRoom()Return true if this mailbox is empty.booleanhasRoom(int numberOfTokens)Return true if the argument is 1 and the mailbox is empty, and otherwise return false.booleanhasToken()Return true if this mailbox is not empty.booleanhasToken(int numberOfTokens)Return true if the argument is 1 and this mailbox is not empty, and otherwise return false.voidput(Token token)Put a token into the mailbox.-
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, reset, setContainer, toString
-
-
-
-
Field Detail
-
_token
protected Token _token
The token held.
-
-
Constructor Detail
-
Mailbox
public Mailbox()
Construct an empty Mailbox with no container.
-
Mailbox
public Mailbox(IOPort container) throws IllegalActionException
Construct an empty Mailbox with the specified container.- Parameters:
container- The container.- Throws:
IllegalActionException- If the container does not accept this receiver.
-
-
Method Detail
-
clear
public void clear() throws IllegalActionExceptionClear this receiver of any contained token.- Specified by:
clearin interfaceReceiver- Overrides:
clearin classAbstractReceiver- Throws:
IllegalActionException- If a derived class throws it (not thrown in this base class).
-
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 Token. If there is none, throw an exception. The token is removed.- Specified by:
getin interfaceReceiver- Specified by:
getin classAbstractReceiver- Returns:
- The token contained by this mailbox.
- Throws:
NoTokenException- If this mailbox is empty.
-
hasRoom
public boolean hasRoom()
Return true if this mailbox is empty.- Specified by:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- Returns:
- True if this mailbox is empty.
-
hasRoom
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentExceptionReturn true if the argument is 1 and the mailbox is empty, and otherwise return false.- Specified by:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- Parameters:
numberOfTokens- The number of tokens to put into the mailbox.- Returns:
- True if the argument is 1 and the mailbox is empty, and otherwise return false.
- Throws:
java.lang.IllegalArgumentException- If the argument is not positive. This is a runtime exception, so it does not need to be declared explicitly.
-
hasToken
public boolean hasToken()
Return true if this mailbox is not empty.- Specified by:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- Returns:
- True if this mailbox is not empty.
-
hasToken
public boolean hasToken(int numberOfTokens) throws java.lang.IllegalArgumentExceptionReturn true if the argument is 1 and this mailbox is not empty, and otherwise return false.- Specified by:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- Parameters:
numberOfTokens- The number of tokens to get from the receiver.- Returns:
- True if the argument is 1 and this mailbox is not empty.
- Throws:
java.lang.IllegalArgumentException- If the argument is not positive. This is a runtime exception, so it does not need to be declared explicitly.
-
put
public void put(Token token) throws NoRoomException
Put a token into the mailbox. If the argument is null, then the mailbox will not contain a token after this returns.- Specified by:
putin interfaceReceiver- Specified by:
putin classAbstractReceiver- Parameters:
token- The token to be put into the mailbox.- Throws:
NoRoomException- If this mailbox is not empty.
-
-