ptolemy.domains.modal.kernel
Class FSMReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by 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: FSMReceiver.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Edward A. Lee
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

Field Summary
private  boolean _isKnown
          Flag indicating whether the state of the receiver is known.
private  Token _token
          The token held.
private  Token[] _tokenCache
          The cache used by the getArray() method to avoid reallocating.
 
Constructor Summary
FSMReceiver()
          Construct an empty receiver with no container.
FSMReceiver(IOPort container)
          Construct an empty receiver with the specified container.
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_isKnown

private boolean _isKnown
Flag indicating whether the state of the receiver is known.


_token

private Token _token
The token held.


_tokenCache

private Token[] _tokenCache
The cache used by the getArray() method to avoid reallocating.

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 interface Receiver
Overrides:
clear in class AbstractReceiver

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 interface Receiver
Overrides:
elementList in class AbstractReceiver
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 interface Receiver
Specified by:
get in class AbstractReceiver
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 interface Receiver
Overrides:
getArray in class AbstractReceiver
Parameters:
numberOfTokens - The number of tokens to get.
Returns:
The array of tokens.
Throws:
NoTokenException - If the status is unknow, if there is no token, or if the argument is not 1.

hasRoom

public boolean hasRoom()
Return true.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
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 interface Receiver
Specified by:
hasRoom in class AbstractReceiver
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 interface Receiver
Specified by:
hasToken in class AbstractReceiver
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 interface Receiver
Specified by:
hasToken in class AbstractReceiver
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 interface Receiver
Overrides:
isKnown in class AbstractReceiver
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 interface Receiver
Specified by:
put in class AbstractReceiver
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 interface Receiver
Overrides:
putArray in class AbstractReceiver
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 interface Receiver
Overrides:
reset in class AbstractReceiver
Throws:
IllegalActionException - If reset() is not supported by the domain.