public class PNQueueReceiver extends QueueReceiver implements ProcessReceiver
Tokens are appended to the queue with the put() method, which blocks on a write if the queue is full. Tokens are removed from the queue with the get() method, which blocks on a read if the queue is empty. In case a process blocks on a read or a write, the receiver informs the director about the same. The receiver also unblocks processes blocked on a read or a write. In case a process is blocked on a read (read-blocked), it is unblocked on availability of a token. If a process is blocked on a write (write-blocked), it is unblocked on the availability of room in the queue and informs the director of the same.
This class is also responsible for pausing or terminating a process that tries to read from or write to the receiver. In case of termination, the receiver throws a TerminateProcessException when a process tries to read from or write to the receiver. This terminates the process. In case of pausing, the receiver suspends the process when it tries to read from or write to the receiver and resumes it only after a request to resume the process has been received.g
QueueReceiver,
QueueReceiver| Red (hyzheng) |
| Yellow (eal) |
| Modifier and Type | Field and Description |
|---|---|
protected BoundaryDetector |
_boundaryDetector
A BoundaryDetector determines the topological relationship of
a Receiver with respect to boundary ports.
|
protected PNDirector |
_director
The director in charge of this receiver.
|
protected java.lang.Thread |
_readPending
Reference to a thread that is read blocked on this receiver.
|
protected boolean |
_terminate
Flag indicating whether finish has been requested.
|
protected java.lang.Thread |
_writePending
Reference to a thread that is write blocked on this receiver.
|
_queue, INFINITE_CAPACITY| Constructor and Description |
|---|
PNQueueReceiver()
Construct an empty receiver with no container.
|
PNQueueReceiver(IOPort container)
Construct an empty receiver with the specified container.
|
| Modifier and Type | Method and Description |
|---|---|
Token |
get()
Get a token from this receiver.
|
PNDirector |
getDirector()
Return the director in charge of this receiver, or null
if there is none.
|
boolean |
hasRoom()
Return true, since a channel in the Kahn process networks
model of computation is of infinite capacity and always has room.
|
boolean |
hasRoom(int tokens)
Return true, since a channel in the Kahn process networks
model of computation is of infinite capacity and always has room.
|
boolean |
hasToken()
Return true, since a call to the get() method of the receiver will
always return a token if the call to get() ever returns.
|
boolean |
hasToken(int tokens)
Return true, since a call to the get() method of the receiver will
always return a token if the call to get() ever returns.
|
boolean |
isConnectedToBoundary()
Return true if this receiver is connected to the inside of a
boundary port.
|
boolean |
isConnectedToBoundaryInside()
Return true if this receiver is connected to the inside of a
boundary port.
|
boolean |
isConnectedToBoundaryOutside()
Return true if this receiver is connected to the outside of a
boundary port.
|
boolean |
isConsumerReceiver()
Return true if this receiver is connected to the boundary.
|
boolean |
isInsideBoundary()
Return true if this receiver is contained on the inside of a
boundary port.
|
boolean |
isOutsideBoundary()
Return true if this receiver is contained on the outside of a
boundary port.
|
boolean |
isProducerReceiver()
Return true if this receiver is at a boundary.
|
boolean |
isReadBlocked()
Return a true or false to indicate whether there is a read block
on this receiver or not, respectively.
|
boolean |
isWriteBlocked()
Return a true or false to indicate whether there is a write block
on this receiver or not.
|
void |
put(Token token)
Put a token on the queue contained in this receiver.
|
void |
requestFinish()
Set a flag in the receiver to indicate the onset of termination.
|
void |
reset()
Reset the state variables in the receiver.
|
void |
setContainer(IOPort port)
Set the container.
|
clear, elementList, elements, get, getCapacity, getHistoryCapacity, historyElementList, historyElements, historySize, setCapacity, setHistoryCapacity, sizegetArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclear, elementList, getArray, getContainer, isKnown, putArray, putArrayToAll, putToAllprotected PNDirector _director
protected java.lang.Thread _readPending
protected java.lang.Thread _writePending
protected boolean _terminate
protected BoundaryDetector _boundaryDetector
public PNQueueReceiver()
public PNQueueReceiver(IOPort container) throws IllegalActionException
container - The container of this receiver.IllegalActionException - If the container does
not accept this receiver.public void setContainer(IOPort port) throws IllegalActionException
setContainer in interface ReceiversetContainer in class AbstractReceiverport - The container.IllegalActionException - If the container is not of
an appropriate subclass of IOPort, or if the container's director
is not an instance of PNDirector.AbstractReceiver.getContainer()public Token get()
get in interface Receiverget in class QueueReceiverpublic PNDirector getDirector()
public boolean hasRoom()
hasRoom in interface ReceiverhasRoom in class QueueReceiverpublic boolean hasRoom(int tokens)
hasRoom in interface ReceiverhasRoom in class QueueReceivertokens - The number of tokens, which is ignored in this method.public boolean hasToken()
hasToken in interface ReceiverhasToken in class QueueReceiverpublic boolean hasToken(int tokens)
hasToken in interface ReceiverhasToken in class QueueReceivertokens - The number of tokens, which is ignored in this method.public boolean isConnectedToBoundary()
throws IllegalActionException
isConnectedToBoundary in interface ProcessReceiverIllegalActionExceptionBoundaryDetectorpublic boolean isConnectedToBoundaryInside()
throws InvalidStateException,
IllegalActionException
isConnectedToBoundaryInside in interface ProcessReceiverIllegalActionExceptionInvalidStateExceptionBoundaryDetectorpublic boolean isConnectedToBoundaryOutside()
throws IllegalActionException
isConnectedToBoundaryOutside in interface ProcessReceiverIllegalActionExceptionBoundaryDetectorpublic boolean isConsumerReceiver()
throws IllegalActionException
isConsumerReceiver in interface ProcessReceiverIllegalActionExceptionisConnectedToBoundary()public boolean isInsideBoundary()
isInsideBoundary in interface ProcessReceiverBoundaryDetectorpublic boolean isOutsideBoundary()
isOutsideBoundary in interface ProcessReceiverBoundaryDetectorpublic boolean isProducerReceiver()
isProducerReceiver in interface ProcessReceiverpublic boolean isReadBlocked()
isReadBlocked in interface ProcessReceiverpublic boolean isWriteBlocked()
isWriteBlocked in interface ProcessReceiverpublic void put(Token token) throws NoRoomException
put in interface Receiverput in class QueueReceivertoken - The token to be put in the receiver, or null to not put anything.NoRoomException - If during initialization, capacity cannot be increased
enough to accommodate initial tokens.public void reset()
reset in interface ProcessReceiverreset in interface Receiverreset in class AbstractReceiverpublic void requestFinish()
requestFinish in interface ProcessReceiver