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
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, size
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
clear, elementList, getArray, getContainer, isKnown, putArray, putArrayToAll, putToAll
protected 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 Receiver
setContainer
in class AbstractReceiver
port
- 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 Receiver
get
in class QueueReceiver
public PNDirector getDirector()
public boolean hasRoom()
hasRoom
in interface Receiver
hasRoom
in class QueueReceiver
public boolean hasRoom(int tokens)
hasRoom
in interface Receiver
hasRoom
in class QueueReceiver
tokens
- The number of tokens, which is ignored in this method.public boolean hasToken()
hasToken
in interface Receiver
hasToken
in class QueueReceiver
public boolean hasToken(int tokens)
hasToken
in interface Receiver
hasToken
in class QueueReceiver
tokens
- The number of tokens, which is ignored in this method.public boolean isConnectedToBoundary() throws IllegalActionException
isConnectedToBoundary
in interface ProcessReceiver
IllegalActionException
- If thrown by the boundary
detector.BoundaryDetector
public boolean isConnectedToBoundaryInside() throws InvalidStateException, IllegalActionException
isConnectedToBoundaryInside
in interface ProcessReceiver
IllegalActionException
- If thrown by the boundary
detector.InvalidStateException
- If thrown by the boundary
detector.BoundaryDetector
public boolean isConnectedToBoundaryOutside() throws IllegalActionException
isConnectedToBoundaryOutside
in interface ProcessReceiver
IllegalActionException
- If thrown by the boundary
detector.BoundaryDetector
public boolean isConsumerReceiver() throws IllegalActionException
isConsumerReceiver
in interface ProcessReceiver
IllegalActionException
- If thrown by the boundary
detector.isConnectedToBoundary()
public boolean isInsideBoundary()
isInsideBoundary
in interface ProcessReceiver
BoundaryDetector
public boolean isOutsideBoundary()
isOutsideBoundary
in interface ProcessReceiver
BoundaryDetector
public boolean isProducerReceiver()
isProducerReceiver
in interface ProcessReceiver
public boolean isReadBlocked()
isReadBlocked
in interface ProcessReceiver
public boolean isWriteBlocked()
isWriteBlocked
in interface ProcessReceiver
public void put(Token token) throws NoRoomException
put
in interface Receiver
put
in class QueueReceiver
token
- 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 ProcessReceiver
reset
in interface Receiver
reset
in class AbstractReceiver
public void requestFinish()
requestFinish
in interface ProcessReceiver