public abstract class AbstractReceiver extends java.lang.Object implements Receiver
Receiver
Green (bart) |
Green (eal) |
Constructor and Description |
---|
AbstractReceiver()
Construct an empty receiver with no container.
|
AbstractReceiver(IOPort container)
Construct an empty receiver with the specified container.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Throw an exception.
|
java.util.List<Token> |
elementList()
Return a list with tokens that are currently in the receiver
available for get() or getArray().
|
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()
Deprecated.
As of Ptolemy II 4.1, replaced by
getModelTime() |
Time |
getModelTime()
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.
|
abstract 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 |
putArrayToAll(Token[] tokens,
int numberOfTokens,
Receiver[] receivers)
Put a sequence of tokens to all receivers in the specified array.
|
void |
putToAll(Token token,
Receiver[] receivers)
Put to all receivers in the specified array.
|
void |
reset()
Reset this receiver to its initial state, which in this base
class is the same as calling clear().
|
void |
setContainer(IOPort port)
Set the container.
|
java.lang.String |
toString()
Return the class name and the full name of the object,
with syntax "className {fullName}".
|
public AbstractReceiver()
public AbstractReceiver(IOPort container) throws IllegalActionException
container
- The container of the receiver.IllegalActionException
- If the container does
not accept this receiver.public void clear() throws IllegalActionException
clear
in interface Receiver
IllegalActionException
- Always thrown.public java.util.List<Token> elementList() throws IllegalActionException
elementList
in interface Receiver
IllegalActionException
- Always thrown in this base class.public abstract Token get() throws NoTokenException
get
in interface Receiver
NoTokenException
- 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 Receiver
numberOfTokens
- 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 Receiver
setContainer(IOPort)
@Deprecated public double getCurrentTime()
getModelTime()
public Time getModelTime()
public abstract boolean hasRoom()
public abstract boolean hasRoom(int numberOfTokens)
public abstract boolean hasToken()
public abstract boolean hasToken(int numberOfTokens)
public boolean isKnown()
public abstract void put(Token token) throws NoRoomException, IllegalActionException
put
in interface Receiver
token
- The token to put into the receiver, or null to
put no token.NoRoomException
- If there is no room in the receiver.IllegalActionException
- If the put fails
(e.g. because of incompatible types).public void putArray(Token[] tokenArray, int numberOfTokens) throws NoRoomException, IllegalActionException
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 Receiver
tokenArray
- 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.IllegalActionException
- If the token is not acceptable
to one of the ports (e.g., wrong type).public void putArrayToAll(Token[] tokens, int numberOfTokens, Receiver[] receivers) throws NoRoomException, IllegalActionException
putArray(Token[], int)
on each receiver in the specified array, after appropriate
type conversion. It also implements the functionality of
ConstantPublisherPort in that it will replace the specified
token with a constant value if the destination is marked to
receive a constant value, and it will drop the token
altogether if the destination has already received all the
constant tokens it expects to receive.
Note that subclasses that override this method will also
have to implement this if they wish to support
ConstantPublisherPort.putArrayToAll
in interface Receiver
tokens
- The sequence of token to put.numberOfTokens
- The number of tokens to put (the array might
be longer).receivers
- The receivers.NoRoomException
- If there is no room for the token.IllegalActionException
- If the token is not acceptable
to one of the ports (e.g., wrong type), or if the tokens array
does not have at least the specified number of tokens.public void putToAll(Token token, Receiver[] receivers) throws NoRoomException, IllegalActionException
put(Token)
on each receiver in the specified array, after appropriate
type conversion. It also implements the functionality of
ConstantPublisherPort in that it will replace the specified
token with a constant value if the destination is marked to
receive a constant value, and it will drop the token
altogether if the destination has already received all the
constant tokens it expects to receive.
Note that subclasses that override this method will also
have to implement this if they wish to support
ConstantPublisherPort.putToAll
in interface Receiver
token
- The token to put, or null to put no token.receivers
- The receivers.NoRoomException
- If there is no room for the token.IllegalActionException
- If the token is not acceptable
to one of the ports (e.g., wrong type).public void reset() throws IllegalActionException
reset
in interface Receiver
IllegalActionException
- If reset() is not supported by
the domain.public void setContainer(IOPort port) throws IllegalActionException
setContainer
in interface Receiver
port
- 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.getContainer()
public java.lang.String toString()
toString
in class java.lang.Object