ptolemy.actor.sched
Class FixedPointReceiver

java.lang.Object
  extended by ptolemy.actor.AbstractReceiver
      extended by ptolemy.actor.sched.FixedPointReceiver
All Implemented Interfaces:
Receiver

public class FixedPointReceiver
extends AbstractReceiver

The receiver for use with FixedPointDirector or any of its subclasses. This receiver has capacity 1. The status of this receiver can be either known or unknown. If it is known, then it can be either present or absent. If it is present, then it has a token, which provides a value.

At first, an instance of this class has status unknown. The clear() method makes the status known and absent. The put() method makes the status known and present, and provides a value. The reset() method reverts the status to unknown. Once the status of a receiver becomes known, the value cannot be changed, nor can the status be changed from present to absent or vice versa. To change the value or the status, call reset() first. Normally, the reset() method is called only by the director and constructors.

The isKnown() method returns true if the receiver has status known. The hasRoom() method returns true if the receiver has status unknown. If the receiver has a known status, the hasToken() method returns true if the receiver contains a token. If the receiver has an unknown status, the hasToken() method will throw an InvalidStateException.

This class is based on the original SRReceiver, written by Paul Whitaker.

Since:
Ptolemy II 5.2
Version:
$Id: FixedPointReceiver.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Haiyang Zheng and Edward A. Lee
Accepted Rating:
Yellow (eal)
Proposed Rating:
Green (hyzheng)

Field Summary
private  FixedPointDirector _director
          The director of this receiver.
private  boolean _known
          A flag indicating whether this receiver has status known.
private  Token _token
          The token held.
 
Constructor Summary
FixedPointReceiver()
          Construct an FixedPointReceiver with unknown status.
FixedPointReceiver(FixedPointDirector director)
          Construct an FixedPointReceiver with unknown status.
 
Method Summary
 void clear()
          Set the status of this receiver to be known and absent.
 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()
          Return the contained token.
 boolean hasRoom()
          Return true if the status of the receiver is unknown.
 boolean hasRoom(int numberOfTokens)
          If the argument is 1, return true if the status of the receiver is unknown.
 boolean hasToken()
          Return true if the receiver contains a token, and false otherwise.
 boolean hasToken(int numberOfTokens)
          If the argument is 1, return true if the receiver contains a token, and false otherwise.
 boolean isKnown()
          Return true if this receiver has status known, that is, this receiver either is either known to have a token or known to not to have a token.
 void put(Token token)
          If the specified token is non-null, then set the status of this receiver to known and present, and to contain the specified token.
 void reset()
          Reset the receiver by deleting any contained tokens and setting the status of this receiver to unknown.
 void setContainer(IOPort port)
          Set the container.
 
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, putArray, putArrayToAll, putToAll, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_director

private FixedPointDirector _director
The director of this receiver.


_known

private boolean _known
A flag indicating whether this receiver has status known.


_token

private Token _token
The token held.

Constructor Detail

FixedPointReceiver

public FixedPointReceiver()
Construct an FixedPointReceiver with unknown status. This constructor does not need a director.


FixedPointReceiver

public FixedPointReceiver(FixedPointDirector director)
Construct an FixedPointReceiver with unknown status.

Parameters:
director - The director of this receiver.
Method Detail

clear

public void clear()
           throws IllegalActionException
Set the status of this receiver to be known and absent.

Specified by:
clear in interface Receiver
Overrides:
clear in class AbstractReceiver
Throws:
IllegalActionException - If this receiver is known and present.

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 interface Receiver
Overrides:
elementList in class AbstractReceiver
Returns:
A list of instances of Token.

get

public Token get()
          throws NoTokenException
Return the contained token. If there is no token or the status of this receiver is unknown, throw an exception.

Specified by:
get in interface Receiver
Specified by:
get in class AbstractReceiver
Returns:
The token contained in the receiver.
Throws:
NoTokenException - If there is no token.
InvalidStateException - If the status is unknown.

hasRoom

public boolean hasRoom()
Return true if the status of the receiver is unknown.

Specified by:
hasRoom in interface Receiver
Specified by:
hasRoom in class AbstractReceiver
Returns:
True if the status of the receiver is unknown.
See Also:
isKnown()

hasRoom

public boolean hasRoom(int numberOfTokens)
                throws java.lang.IllegalArgumentException
If the argument is 1, return true if the status of the receiver is unknown. Otherwise, throw an exception. This receiver has capacity one.

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 receiver can accept a token.
Throws:
java.lang.IllegalArgumentException - If the argument is not positive.
See Also:
isKnown(), hasRoom()

hasToken

public boolean hasToken()
Return true if the receiver contains a token, and false otherwise. If the receiver has status unknown, this method will throw an exception.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Returns:
True if this receiver contains a token.
Throws:
InvalidStateException - If the status is unknown.

hasToken

public boolean hasToken(int numberOfTokens)
If the argument is 1, return true if the receiver contains a token, and false otherwise. If the argument is larger than 1, return false (this receiver has capacity one). If the receiver has status unknown, throw an exception.

Specified by:
hasToken in interface Receiver
Specified by:
hasToken in class AbstractReceiver
Parameters:
numberOfTokens - The number of tokens.
Returns:
True if the argument is 1 and the receiver has a token.
Throws:
java.lang.IllegalArgumentException - If the argument is not positive.
InvalidStateException - If the status is unknown.
See Also:
hasToken()

isKnown

public boolean isKnown()
Return true if this receiver has status known, that is, this receiver either is either known to have a token or known to not to have a token.

Specified by:
isKnown in interface Receiver
Overrides:
isKnown in class AbstractReceiver
Returns:
True if this receiver has status known.

put

public void put(Token token)
         throws IllegalActionException
If the specified token is non-null, then set the status of this receiver to known and present, and to contain the specified token. If the receiver is already known and the value of the contained token is different from that of the new token, throw an exception. If the specified token is null, then set the status to be known and absent (by calling clear()).

Specified by:
put in interface Receiver
Specified by:
put in class AbstractReceiver
Parameters:
token - The token to be put into this receiver.
Throws:
java.lang.IllegalArgumentException - If the argument is null.
IllegalActionException - If the status is known and absent, or a token is present but not have the same value, or a token is present and cannot be compared to the specified token.

reset

public void reset()
Reset the receiver by deleting any contained tokens and setting the status of this receiver to unknown. This is called by the , normally in its initialize() and postfire() methods.

Specified by:
reset in interface Receiver
Overrides:
reset in class AbstractReceiver

setContainer

public void setContainer(IOPort port)
                  throws IllegalActionException
Set the container. This overrides the base class so that if the container is being set to null, and if the director of this receiver is not null, this method removes the receiver from the list in that director.

Specified by:
setContainer in interface Receiver
Overrides:
setContainer in class AbstractReceiver
Parameters:
port - The container.
Throws:
IllegalActionException - If the container is not of an appropriate subclass of IOPort. Not thrown in this base class, but may be thrown in derived classes.
See Also:
AbstractReceiver.getContainer()