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 void
clear()
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.Token
get()
Get the contained Token.boolean
hasRoom()
Return true if this mailbox is empty.boolean
hasRoom(int numberOfTokens)
Return true if the argument is 1 and the mailbox is empty, and otherwise return false.boolean
hasToken()
Return true if this mailbox is not empty.boolean
hasToken(int numberOfTokens)
Return true if the argument is 1 and this mailbox is not empty, and otherwise return false.void
put(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 IllegalActionException
Clear this receiver of any contained token.- Specified by:
clear
in interfaceReceiver
- Overrides:
clear
in 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:
elementList
in interfaceReceiver
- Overrides:
elementList
in 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:
get
in interfaceReceiver
- Specified by:
get
in 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:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- Returns:
- True if this mailbox is empty.
-
hasRoom
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentException
Return true if the argument is 1 and the mailbox is empty, and otherwise return false.- Specified by:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in 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:
hasToken
in interfaceReceiver
- Specified by:
hasToken
in classAbstractReceiver
- Returns:
- True if this mailbox is not empty.
-
hasToken
public boolean hasToken(int numberOfTokens) throws java.lang.IllegalArgumentException
Return true if the argument is 1 and this mailbox is not empty, and otherwise return false.- Specified by:
hasToken
in interfaceReceiver
- Specified by:
hasToken
in 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:
put
in interfaceReceiver
- Specified by:
put
in classAbstractReceiver
- Parameters:
token
- The token to be put into the mailbox.- Throws:
NoRoomException
- If this mailbox is not empty.
-
-