Package ptolemy.domains.modal.kernel
Class FSMReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- ptolemy.domains.modal.kernel.FSMReceiver
-
- All Implemented Interfaces:
Receiver
public class FSMReceiver extends AbstractReceiver
A receiver with capacity one for which one can explicitly set the status.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Constructor Summary
Constructors Constructor Description FSMReceiver()
Construct an empty receiver with no container.FSMReceiver(IOPort container)
Construct an empty receiver with the specified container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear this receiver of any contained token and set the known status to true.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.Token[]
getArray(int numberOfTokens)
If the argument is 1, there is a token, and the status is known, then return an array containing the one token.boolean
hasRoom()
Return true.boolean
hasRoom(int numberOfTokens)
Return true if the argument is 1, 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 receiver is not empty, and otherwise return false.boolean
isKnown()
Return whether the state of the receiver is known.void
put(Token token)
Put a token into this receiver.void
putArray(Token[] tokenArray, int numberOfTokens)
If the argument has one token, then put that token in the receiver.void
reset()
Set the receiver to unknown.-
Methods inherited from class ptolemy.actor.AbstractReceiver
getContainer, getCurrentTime, getModelTime, putArrayToAll, putToAll, setContainer, toString
-
-
-
-
Constructor Detail
-
FSMReceiver
public FSMReceiver()
Construct an empty receiver with no container. The initial status is unknown.
-
FSMReceiver
public FSMReceiver(IOPort container) throws IllegalActionException
Construct an empty receiver with the specified container. The initial status is unknown.- 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 token and set the known status to true.- Specified by:
clear
in interfaceReceiver
- Overrides:
clear
in classAbstractReceiver
-
elementList
public java.util.List<Token> elementList() throws IllegalActionException
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.
- Throws:
IllegalActionException
- If the status is unknown.
-
get
public Token get() throws NoTokenException
Get the contained Token. If there is none, throw an exception. The token is not removed. It can be repeatedly read.- Specified by:
get
in interfaceReceiver
- Specified by:
get
in classAbstractReceiver
- Returns:
- The token contained by this receiver.
- Throws:
NoTokenException
- If this receiver is empty or unknown
-
getArray
public Token[] getArray(int numberOfTokens) throws NoTokenException
If the argument is 1, there is a token, and the status is known, then return an array containing the one token. Otherwise, throw an exception.- Specified by:
getArray
in interfaceReceiver
- Overrides:
getArray
in classAbstractReceiver
- Parameters:
numberOfTokens
- The number of tokens to get.- Returns:
- The array of tokens.
- Throws:
NoTokenException
- If the status is unknown, if there is no token, or if the argument is not 1.
-
hasRoom
public boolean hasRoom()
Return true.- Specified by:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- Returns:
- True.
-
hasRoom
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentException
Return true if the argument is 1, and otherwise return false.- Specified by:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- Parameters:
numberOfTokens
- The number of tokens to put into the receiver.- Returns:
- True if the argument is 1, 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.
- Throws:
InternalErrorException
- If the status is not known.
-
hasToken
public boolean hasToken(int numberOfTokens) throws java.lang.IllegalArgumentException
Return true if the argument is 1 and this receiver 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 receiver is not empty.
- Throws:
InternalErrorException
- If the status is not known.java.lang.IllegalArgumentException
- If the argument is not positive. This is a runtime exception, so it does not need to be declared explicitly.
-
isKnown
public boolean isKnown()
Return whether the state of the receiver is known.- Specified by:
isKnown
in interfaceReceiver
- Overrides:
isKnown
in classAbstractReceiver
- Returns:
- True if the state of the receiver is known.
- See Also:
clear()
,put(Token)
-
put
public void put(Token token) throws NoRoomException
Put a token into this receiver. If the argument is null, then the receiver will not contain a token after this returns, getting the same effect as calling clear(). If there was previously a token in the receiver, this overwrites that token. Set the known status of the receiver to true.- 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.
-
putArray
public void putArray(Token[] tokenArray, int numberOfTokens) throws NoRoomException, IllegalActionException
If the argument has one token, then put that token in the receiver. Otherwise, throw an exception.- Specified by:
putArray
in interfaceReceiver
- Overrides:
putArray
in classAbstractReceiver
- Parameters:
tokenArray
- The array containing tokens to put into this receiver.numberOfTokens
- The number of elements of the token array to put into this receiver.- Throws:
NoRoomException
- If the token array cannot be put.IllegalActionException
- If the token is not acceptable to one of the ports (e.g., wrong type).
-
reset
public void reset() throws IllegalActionException
Set the receiver to unknown.- Specified by:
reset
in interfaceReceiver
- Overrides:
reset
in classAbstractReceiver
- Throws:
IllegalActionException
- If reset() is not supported by the domain.
-
-