public class PrioritizedTimedQueue extends AbstractReceiver
A PrioritizedTimedQueue is subclassed by DDEReceiver. Hence, PrioritizedTimedQueues serve as the foundation for receivers contained in the IO ports of actors operating within DDE models. A TimeKeeper object is assigned to each actor that operates according to the DDE model of computation. The TimeKeeper manages each of the receivers that are contained by an actor by keeping track of the receiver times of each receiver. As information flows through a PrioritizedTimedQueue, the TimeKeeper must be kept up to date with respect to the receiver times. The TimeKeeper orders the PrioritizedTimedQueues according to their receiver times and priorities. PrioritizedTimedQueues with smaller receiver times are ordered first.
PrioritizedTimedQueues with identical receiver times are sorted according to their respective priorities. PrioritizedTimedQueues are assigned priorities (a nonnegative integer) by a TimeKeeper when the TimeKeeper is instantiated. Receivers with higher receiver priorities are ordered before receivers with lower priorities. The priority of a receiver can be explicitly specified or it can be implicitly determined based on the topology. In the latter case, the priority of a receiver is set according to the inverse order in which it was connected to the model topology. I.e., if two input receivers (receiver A and receiver B) are added to an actor such that receiver A is connected in the model topology before receiver B, then receiver B will have a higher priority than receiver A.
If the oldest token in the queue has a time stamp of IGNORE, then the next oldest token from the other receivers contained by the actor in question will be consumed and the token time stamped IGNORE will be dropped. The IGNORE time stamp is useful in feedback topologies in which an actor should ignore inputs from a feedback cycle when the execution of the model is just beginning. FeedBackDelay actors output a single IGNORE token during their initialize() methods for just this reason. In general, IGNORE tokens should not be handled unless fundamental changes to the DDE kernel are intended.
The values of the package friendly variables IGNORE, INACTIVE and ETERNITY are arbitrary as long as they have unique, negative values. ETERNITY is used in conjunction with the completionTime to indicate that an actor should continue executing indefinitely.
Note that a PrioritizedTimedQueue is intended for use within a multi-threaded environment. PrioritizedTimedQueue does not require the synchronization facilities provided by ptolemy.kernel.util.Workspace. PrioritizedTimedQueue is subclassed by DDEReceiver which adds significant synchronization facilities and where appropriate employs workspace.
DDEReceiver
,
TimeKeeper
Green (kienhuis) |
Green (davisj) |
Modifier and Type | Field and Description |
---|---|
(package private) Time |
_lastTime |
(package private) int |
_priority |
(package private) static double |
ETERNITY |
(package private) static double |
IGNORE |
(package private) static double |
INACTIVE |
Constructor and Description |
---|
PrioritizedTimedQueue()
Construct an empty queue with no container.
|
PrioritizedTimedQueue(IOPort container)
Construct an empty queue with the specified IOPort container.
|
PrioritizedTimedQueue(IOPort container,
int priority)
Construct an empty queue with the specified IOPort container
and priority.
|
Modifier and Type | Method and Description |
---|---|
(package private) Time |
_getCompletionTime()
Return the completion time of this receiver.
|
(package private) boolean |
_hasNullToken()
Return true if this receiver has a NullToken at the front
of the queue; return false otherwise.
|
(package private) void |
_setCompletionTime(Time time)
Set the completion time of this receiver.
|
(package private) void |
_setReceiverTime(Time time)
Set the receiver time of this receiver to the specified
value.
|
java.util.List<Token> |
elementList()
Return a list with the tokens currently in the receiver, or
an empty list if there is no such token.
|
Token |
get()
Take the the oldest token off of the queue and return it.
|
int |
getCapacity()
Get the queue capacity of this receiver.
|
Time |
getLastTime()
Deprecated.
Only used for testing purposes
|
Time |
getReceiverTime()
Return the receiver time of this receiver.
|
boolean |
hasRoom()
Return true if the number of tokens stored in the queue is
less than the capacity of the queue.
|
boolean |
hasRoom(int numberOfTokens)
Return true if the queue capacity minus the queue size is
greater than the argument.
|
boolean |
hasToken()
Return true if there are tokens stored on the queue.
|
boolean |
hasToken(int numberOfTokens)
Return true if queue size is at least the argument.
|
void |
put(Token token)
Throw an exception, since this method is not used in
DDE.
|
void |
put(Token token,
Time time)
Put a token on the queue with the specified time stamp and set
the last time value to be equal to this time stamp.
|
void |
removeIgnoredToken()
Remove the oldest token off of this queue if it has a
time stamp with a value of IGNORE.
|
void |
reset()
Reset local flags.
|
void |
setCapacity(int capacity)
Set the queue capacity of this receiver.
|
clear, getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, setContainer, toString
static final double ETERNITY
static final double IGNORE
static final double INACTIVE
Time _lastTime
int _priority
public PrioritizedTimedQueue()
public PrioritizedTimedQueue(IOPort container) throws IllegalActionException
container
- The IOPort that contains this receiver.IllegalActionException
- If this receiver cannot be
contained by the proposed container.public PrioritizedTimedQueue(IOPort container, int priority) throws IllegalActionException
container
- The IOPort that contains this receiver.priority
- The priority of this receiver.IllegalActionException
- If this receiver cannot be
contained by the proposed container.public java.util.List<Token> elementList()
elementList
in interface Receiver
elementList
in class AbstractReceiver
public Token get()
get
in interface Receiver
get
in class AbstractReceiver
NoTokenException
- If the queue is empty.public int getCapacity()
setCapacity(int)
@Deprecated public Time getLastTime()
public Time getReceiverTime()
public boolean hasRoom()
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
public boolean hasRoom(int numberOfTokens) throws java.lang.IllegalArgumentException
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
numberOfTokens
- The number of tokens to put into the queue.java.lang.IllegalArgumentException
- If the argument is not positive.
This is a runtime exception, so it does not need to be declared
explicitly.public boolean hasToken()
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
public boolean hasToken(int numberOfTokens) throws java.lang.IllegalArgumentException
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
numberOfTokens
- The number of tokens to get from the queue.java.lang.IllegalArgumentException
- If the argument is not positive.
This is a runtime exception, so it does not need to be declared
explicitly.public void put(Token token)
put
in interface Receiver
put
in class AbstractReceiver
token
- The token to be put to the receiver.NoRoomException
- If the receiver is full.public void put(Token token, Time time) throws NoRoomException
token
- The token to put on the queue.time
- The time stamp of the token.NoRoomException
- If the queue is full.public void removeIgnoredToken()
NoTokenException
- If the queue is empty.public void reset()
reset
in interface Receiver
reset
in class AbstractReceiver
public void setCapacity(int capacity) throws IllegalActionException
capacity
- The capacity of this receiver's queue.IllegalActionException
- If the superclass throws it.getCapacity()
Time _getCompletionTime()
boolean _hasNullToken()
void _setCompletionTime(Time time)
time
- The completion time of this receiver.void _setReceiverTime(Time time)
time
- The new receiver time.