public class CSPReceiver extends AbstractReceiver implements ProcessReceiver
Green (kienhuis) |
Red (nsmyth) |
Constructor and Description |
---|
CSPReceiver()
Construct a CSPReceiver with no container.
|
CSPReceiver(IOPort container)
Construct a CSPReceiver with the specified container.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_checkFlagsAndWait()
This method wraps the wait() call between checks on the state
of the receiver.
|
protected CSPDirector |
_getDirector()
Return the director that is controlling the execution of this model.
|
protected AbstractBranchController |
_getOtherController()
Return the controller of the conditional branch to reach the
rendezvous point first.
|
protected int |
_getOtherID()
Return the branch ID of the branch that requested the
conditional receive.
|
protected boolean |
_isConditionalReceiveWaiting()
Return whether a ConditionalReceive is trying
to rendezvous with this receiver.
|
protected boolean |
_isConditionalSendWaiting()
Return whether a ConditionalSend is trying
to rendezvous with this receiver.
|
protected boolean |
_isGetWaiting()
Return whether a get() is waiting to rendezvous
at this receiver.
|
protected boolean |
_isPutWaiting()
Flag indicating whether or not a put() is waiting to rendezvous
at this receiver.
|
protected void |
_setConditionalReceive(boolean ready,
AbstractBranchController controller,
int otherID)
Set a flag so that a ConditionalSend branch knows whether or
not a ConditionalReceive is ready to rendezvous with it.
|
protected void |
_setConditionalSend(boolean ready,
AbstractBranchController controller,
int otherID)
Set a flag so that a ConditionalReceive branch knows whether or
not a ConditionalSend is ready to rendezvous with it.
|
void |
clear()
Reset local flags.
|
Token |
get()
Get a token from this receiver.
|
boolean |
hasRoom()
Return true.
|
boolean |
hasRoom(int tokens)
Return true.
|
boolean |
hasToken()
Return true.
|
boolean |
hasToken(int tokens)
Return true.
|
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()
This class serves as an example of a ConsumerReceiver and
hence this method returns true.
|
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 on an outside or
an inside boundary.
|
boolean |
isReadBlocked()
Return true if there is a get or a conditional receive
waiting on this receiver.
|
boolean |
isWriteBlocked()
Return true if there is either a put or a conditional send
waiting on this receiver.
|
void |
put(Token token)
Put a token into the mailbox 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 |
requestFinish()
The model has finished executing, so set a flag so that the
next time an actor tries to get or put it gets a
TerminateProcessException which will cause it to finish.
|
void |
reset()
Reset local flags.
|
elementList, getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, setContainer, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
elementList, getArray, getContainer, isKnown, putArray, setContainer
public CSPReceiver()
public CSPReceiver(IOPort container) throws IllegalActionException
container
- The port containing this receiver.IllegalActionException
- If this receiver cannot be
contained by the proposed container.public void clear()
clear
in interface Receiver
clear
in class AbstractReceiver
public Token get() throws TerminateProcessException
get
in interface Receiver
get
in class AbstractReceiver
TerminateProcessException
- If the actor to
which this receiver belongs has been terminated while still
running i.e it was not allowed to run to completion.public boolean hasRoom()
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
public boolean hasRoom(int tokens)
hasRoom
in interface Receiver
hasRoom
in class AbstractReceiver
tokens
- Ignored by this method.public boolean hasToken()
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
public boolean hasToken(int tokens)
hasToken
in interface Receiver
hasToken
in class AbstractReceiver
tokens
- Ignored by this method.public boolean isConnectedToBoundary() throws IllegalActionException
isConnectedToBoundary
in interface ProcessReceiver
IllegalActionException
BoundaryDetector
public boolean isConnectedToBoundaryInside() throws InvalidStateException, IllegalActionException
isConnectedToBoundaryInside
in interface ProcessReceiver
IllegalActionException
InvalidStateException
BoundaryDetector
public boolean isConnectedToBoundaryOutside() throws IllegalActionException
isConnectedToBoundaryOutside
in interface ProcessReceiver
IllegalActionException
BoundaryDetector
public boolean isConsumerReceiver() throws IllegalActionException
isConsumerReceiver
in interface ProcessReceiver
IllegalActionException
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 TerminateProcessException
put
in interface Receiver
put
in class AbstractReceiver
token
- The token, or null to do nothing.TerminateProcessException
- If the actor to
which this receiver belongs has been terminated while still
running i.e it was not allowed to run to completion.public void putArrayToAll(Token[] tokens, int numberOfTokens, Receiver[] receivers) throws NoRoomException, IllegalActionException, TerminateProcessException
putArrayToAll
in interface Receiver
putArrayToAll
in class AbstractReceiver
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.TerminateProcessException
- If the actor to
which this receiver belongs has been terminated while still
running i.e it was not allowed to run to completion.public void putToAll(Token token, Receiver[] receivers) throws NoRoomException, IllegalActionException, TerminateProcessException
putToAll
in interface Receiver
putToAll
in class AbstractReceiver
token
- The token to put, or null to put no token.receivers
- The receivers, which are assumed to
all be instances of CSPReceiver.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).TerminateProcessException
- If the actor to
which this receiver belongs has been terminated while still
running i.e it was not allowed to run to completion.public void requestFinish()
requestFinish
in interface ProcessReceiver
public void reset()
reset
in interface ProcessReceiver
reset
in interface Receiver
reset
in class AbstractReceiver
protected void _checkFlagsAndWait() throws TerminateProcessException, java.lang.InterruptedException
This method is internally synchronized on the director. To avoid missing events you should the callers also need to be synchronized on the director (this is currently the case).
TerminateProcessException
- If the actor to
which this receiver belongs has been terminated while still
running i.e it was not allowed to run to completion.java.lang.InterruptedException
- If the actor is
interrupted while waiting(for a rendezvous to complete).protected AbstractBranchController _getOtherController()
protected int _getOtherID()
protected CSPDirector _getDirector()
protected boolean _isConditionalReceiveWaiting()
protected boolean _isConditionalSendWaiting()
protected boolean _isGetWaiting()
protected boolean _isPutWaiting()
protected void _setConditionalSend(boolean ready, AbstractBranchController controller, int otherID)
ready
- Boolean indicating whether or not a conditional
send is waiting to rendezvous.controller
- The controller which contains the ConditionalSend
branch that is trying to rendezvous. It is stored in the
receiver so that if a ConditionalReceive arrives, it can easily
check whether the ConditionalSend branch was the first
branch of its conditional construct(CIF or CDO) to succeed.otherID
- The branch ID of the branch requesting the
conditional send.protected void _setConditionalReceive(boolean ready, AbstractBranchController controller, int otherID)
ready
- Boolean indicating whether or not a conditional
receive is waiting to rendezvous.controller
- The CSPActor which contains the ConditionalReceive
branch that is trying to rendezvous. It is stored in the
receiver so that if a ConditionalSend arrives, it can easily
check whether the ConditionalReceive branch was the first
branch of its conditional construct(CIF or CDO) to succeed.otherID
- The branch ID of the branch requesting the
conditional receive.