|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--ptolemy.actor.AbstractReceiver
An abstract implementation of the Receiver interface. The container methods and some of the more esoteric methods are implemented, while the most domain-specific methods are left undefined. Note that the NoTokenException and NoRoomException exceptions that are thrown by several of the methods are runtime exceptions, so they need not be declared explicitly by the caller.
Receiver| Constructor Summary | |
AbstractReceiver()
Construct an empty receiver with no container. |
|
AbstractReceiver(IOPort container)
Construct an empty receiver with the specified container. |
|
| Method Summary | |
abstract Token |
get()
Get a token from this receiver. |
Token[] |
getArray(int numberOfTokens)
Get an array of tokens from this receiver. |
IOPort |
getContainer()
Return the container of this receiver, or null if there is none. |
double |
getCurrentTime()
Return the current time associated with this receiver. |
abstract boolean |
hasRoom()
Return true if the receiver has room to put a token into it (via the put() method). |
abstract boolean |
hasRoom(int numberOfTokens)
Return true if the receiver has room to put the specified number of tokens into it (via the put() method). |
abstract boolean |
hasToken()
Return true if the receiver contains a token that can be obtained by calling the get() method. |
abstract boolean |
hasToken(int numberOfTokens)
Return true if the receiver contains the specified number of tokens. |
boolean |
isKnown()
Return true if this receiver has known state, that is, the tokens in this receiver are known or if this receiver is known not to contain any tokens. |
void |
put(Token token)
Put the specified token into this receiver. |
void |
putArray(Token[] tokenArray,
int numberOfTokens)
Put a portion of the specified token array into this receiver. |
void |
setAbsent()
Set the receiver to contain no tokens. |
void |
setContainer(IOPort port)
Set the container. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public AbstractReceiver()
public AbstractReceiver(IOPort container)
throws IllegalActionException
container - The container of the receiver.IllegalActionException - If the container does
not accept this receiver.| Method Detail |
public abstract Token get()
throws NoTokenException
get in interface ReceiverNoTokenException - If there is no token.
public Token[] getArray(int numberOfTokens)
throws NoTokenException
This implementation works by calling get() repeatedly to populate an array. Derived classes may offer more efficient implementations. This implementation has two key limitations:
getArray in interface ReceivernumberOfTokens - The number of tokens to get.NoTokenException - If there are not numberOfTokens
tokens available. Note that if this exception is thrown, then
it is possible that some tokens will have been already extracted
from the receiver by the calls to get(). These tokens will be
lost. They will not be used on the next call to getArray().
Thus, it is highly advisable to call hasToken(int) before
calling this method.public IOPort getContainer()
getContainer in interface Receiverpublic double getCurrentTime()
public abstract boolean hasRoom()
hasRoom in interface Receiverpublic abstract boolean hasRoom(int numberOfTokens)
hasRoom in interface ReceivernumberOfTokens - The number of tokens to put into this receiver.public abstract boolean hasToken()
hasToken in interface Receiverpublic abstract boolean hasToken(int numberOfTokens)
hasToken in interface ReceivernumberOfTokens - The number of tokens desired.public boolean isKnown()
In this base class, assume that the receiver has known state, so return true. Receivers that may have unknown state must override this method.
isKnown in interface Receiver
public void put(Token token)
throws NoRoomException
put in interface Receivertoken - The token to put into the receiver.NoRoomException - If there is no room in the receiver.
public void putArray(Token[] tokenArray,
int numberOfTokens)
throws NoRoomException
This implementation works by calling put() repeatedly. The caller may feel free to reuse the array after this method returns. Derived classes may offer more efficient implementations. This implementation is not synchronized, so it is not suitable for multithreaded domains where there might be multiple threads writing to the same receiver. It is suitable, however, for multithreaded domains where only one thread is writing to the receiver. This is true even if a separate thread is reading from the receiver, as long as the put() and get() methods are properly synchronized.
putArray in interface ReceivertokenArray - The array containing tokens to put into this
receiver.numberOfTokens - The number of elements of the token
array to put into this receiver.NoRoomException - If the token array cannot be put.public void setAbsent()
In this base class, do nothing. Receivers that require some action to be performed must override this method.
setAbsent in interface ReceiverNoRoomException - If there is no room in the receiver.
public void setContainer(IOPort port)
throws IllegalActionException
setContainer in interface Receiverport - The container.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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||