Class FixedPointReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- 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$
- Author:
- Haiyang Zheng and Edward A. Lee
- Pt.AcceptedRating:
- Yellow (eal)
- Pt.ProposedRating:
- Green (hyzheng)
-
-
Field Summary
Fields Modifier and Type Field Description protected FixedPointDirector_directorThe director of this receiver.protected boolean_knownA flag indicating whether this receiver has status known.protected Token_tokenThe token held.
-
Constructor Summary
Constructors Constructor Description FixedPointReceiver()Construct an FixedPointReceiver with unknown status.FixedPointReceiver(FixedPointDirector director)Construct an FixedPointReceiver with unknown status.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()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.Tokenget()Return the contained token.booleanhasRoom()Return true if the status of the receiver is unknown.booleanhasRoom(int numberOfTokens)If the argument is 1, return true if the status of the receiver is unknown.booleanhasToken()Return true if the receiver contains a token, and false otherwise.booleanhasToken(int numberOfTokens)If the argument is 1, return true if the receiver contains a token, and false otherwise.booleanisKnown()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.voidput(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.voidreset()Reset the receiver by deleting any contained tokens and setting the status of this receiver to unknown, unless the containing port has no sources, in which case set to known and absent.voidsetContainer(IOPort port)Set the container.-
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, putArray, putArrayToAll, putToAll, toString
-
-
-
-
Field Detail
-
_director
protected FixedPointDirector _director
The director of this receiver.
-
_known
protected boolean _known
A flag indicating whether this receiver has status known.
-
_token
protected 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 IllegalActionExceptionSet the status of this receiver to be known and absent.- Specified by:
clearin interfaceReceiver- Overrides:
clearin classAbstractReceiver- 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:
elementListin interfaceReceiver- Overrides:
elementListin classAbstractReceiver- 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:
getin interfaceReceiver- Specified by:
getin classAbstractReceiver- 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:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- Returns:
- True if the status of the receiver is unknown.
- See Also:
isKnown()
-
hasRoom
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentExceptionIf 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:
hasRoomin interfaceReceiver- Specified by:
hasRoomin classAbstractReceiver- 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:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- 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:
hasTokenin interfaceReceiver- Specified by:
hasTokenin classAbstractReceiver- 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:
isKnownin interfaceReceiver- Overrides:
isKnownin classAbstractReceiver- 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 callingclear()).- Specified by:
putin interfaceReceiver- Specified by:
putin classAbstractReceiver- 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, unless the containing port has no sources, in which case set to known and absent. This is called by the , normally in its initialize() and postfire() methods.- Specified by:
resetin interfaceReceiver- Overrides:
resetin classAbstractReceiver
-
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:
setContainerin interfaceReceiver- Overrides:
setContainerin classAbstractReceiver- 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()
-
-