|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.actor.AbstractReceiver
ptolemy.domains.rendezvous.kernel.RendezvousReceiver
public class RendezvousReceiver
Receiver for rendezvous style communication. In the rendezvous domain, all communication is via synchronous message passing, so both the the sending and receiving processes need to rendezvous at the receiver. For rendezvous, the receiver is the key synchronization point. It is assumed each receiver has at most one thread trying to send to it and at most one thread trying to receive from it at any one time. The receiver performs the synchronization necessary for simple rendezvous (get() and put() operations). This receiver is based on the CSPReceiver class by John S. Davis II, Thomas Feng, Edward A. Lee, Neil Smyth, and Yang Zhao.
Green (tfeng) |
Green (tfeng) |
Nested Class Summary | |
---|---|
private static class |
RendezvousReceiver.TopologicalSort
Topological sort for the set of receivers to be committed. |
Field Summary | |
---|---|
private BoundaryDetector |
_boundaryDetector
The boundary detector. |
private int |
_channelIndex
The index of the channel that this receiver is in. |
private boolean |
_getConditional
Flag indicating that the _getWaiting thread is a conditional rendezvous. |
private Receiver[][] |
_getReceivers
The receivers currently being gotten data from. |
private java.lang.Thread |
_getWaiting
Indicator that a get() is waiting on this receiver. |
private boolean |
_putConditional
Flag indicating that the _putWaiting thread is a conditional rendezvous. |
private Receiver[][] |
_putReceivers
The receivers currently being put data to. |
private java.lang.Thread |
_putWaiting
Indicator that a put() is waiting on this receiver. |
private Receiver[][] |
_symmetricGetReceivers
The receivers for a get operation on the other side, or null. |
private Receiver[][] |
_symmetricPutReceivers
The receivers for a put operation on the other side, or null. |
private Receiver[][] |
_thisReceiver
Array with just one receiver, this one, for convenience. |
private Token |
_token
The token being transferred during the rendezvous. |
private static int |
GET
Flag to test whether an operation does a get. |
private static int |
GET_CONDITIONAL
Flag to test whether an operation does a conditional get. |
private static int |
GET_FROM_ALL
Flag for the "get from all" operation. |
private static int |
GET_FROM_ANY
Flag for the "get from any" operation. |
private static int |
GET_FROM_ANY_PUT_TO_ALL
Flag for the "get from any and put to all" operation. |
private static int |
PUT
Flag to test whether an operation does a put. |
private static int |
PUT_CONDITIONAL
Flag to test whether an operation does a conditional put. |
private static int |
PUT_TO_ALL
Flag for the "put to all" operation. |
private static int |
PUT_TO_ANY
Flag for the "put to any" operation. |
Constructor Summary | |
---|---|
RendezvousReceiver()
Construct a RendezvousReceiver with no container. |
|
RendezvousReceiver(IOPort container)
Construct a RendezvousReceiver with the specified container. |
Method Summary | |
---|---|
private static boolean |
_checkRendezvous(Receiver[][] receivers,
boolean isPut,
java.util.Set beingChecked,
java.util.Set ready,
java.util.Set notReady,
java.util.Set symmetricReceivers,
boolean isSymmetricGet,
boolean isSymmetricPut,
Receiver farSideReceiver)
Check whether a rendezvous can be formed starting from the given two-dimensional array of receivers. |
protected static void |
_commitRendezvous(java.util.Set receivers,
RendezvousDirector director)
Commit the rendezvous formed by the set of receivers that agree to send and receive at the same time. |
protected RendezvousDirector |
_getDirector()
Return the director that is controlling the execution of this model. |
private static java.util.Map |
_getOrPutTokens(Receiver[][] getReceivers,
Receiver[][] putReceivers,
RendezvousDirector director,
Token token,
Token[][] tokenArray,
int flag)
Get or put token(s) to the array of receivers, or both put and get at the same time. |
private static int |
_getSelectedBranch(Receiver[][] receivers,
java.util.Set beingChecked,
java.util.Set ready)
Get the branch of the two-dimensional array of receivers that has been selected by previous recursive calls of _checkRendezvous(Receiver[][], boolean, Set, Set, Set,
Set, boolean, boolean, Receiver) . |
private static boolean |
_isConditional(Receiver[][] receivers,
boolean isPut)
Test whether a two-dimensional array of receivers are conditional. |
protected static java.util.Set |
_receiversReadyToCommit(Receiver[][] receivers,
boolean isPut)
Get the receivers that are ready to form a rendezvous according to the rendezvous semantics. |
private void |
_resetFlags(boolean clearGet,
boolean clearPut)
Reset the flags of this receiver. |
private static void |
_resetReceiversFlags(Receiver[][] receivers,
boolean clearGet,
boolean clearPut)
Reset the flags of the receivers in the given array. |
void |
clear()
Reset local flags. |
Token |
get()
Get a token from this receiver. |
static Token[][] |
getFromAll(Receiver[][] receivers,
RendezvousDirector director)
Get from all receivers in the specified array. |
static Token |
getFromAny(Receiver[][] receivers,
RendezvousDirector director)
Get from any receiver in the specified array. |
static void |
getFromAnyPutToAll(Receiver[][] getReceivers,
Receiver[][] putReceivers,
RendezvousDirector director)
Get from any receiver in the getReceivers array, and put the token received to all receivers in putReceivers array. |
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 if this port is connected to a 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 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. |
static void |
putToAll(Token[][] tokens,
Receiver[][] receivers,
RendezvousDirector director)
Put to all receivers in the specified array. |
void |
putToAll(Token token,
Receiver[] receivers)
Put to all receivers in the specified array. |
void |
putToAll(Token token,
Receiver[] receivers,
RendezvousDirector director)
Put to all receivers in the specified array. |
static void |
putToAny(Token token,
Receiver[][] receivers,
RendezvousDirector director)
Put the specified token to any receiver 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. |
static void |
waitForChange(RendezvousDirector director)
Wait on the specified director. |
Methods inherited from class ptolemy.actor.AbstractReceiver |
---|
elementList, getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, setContainer, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ptolemy.actor.Receiver |
---|
elementList, getArray, getContainer, isKnown, putArray, setContainer |
Field Detail |
---|
private static final int GET
private static final int PUT
private static final int GET_CONDITIONAL
private static final int PUT_CONDITIONAL
private static final int GET_FROM_ALL
private static final int GET_FROM_ANY
private static final int PUT_TO_ALL
private static final int PUT_TO_ANY
private static final int GET_FROM_ANY_PUT_TO_ALL
private BoundaryDetector _boundaryDetector
private int _channelIndex
private boolean _getConditional
private Receiver[][] _getReceivers
private java.lang.Thread _getWaiting
private boolean _putConditional
private Receiver[][] _putReceivers
private java.lang.Thread _putWaiting
private Receiver[][] _symmetricGetReceivers
private Receiver[][] _symmetricPutReceivers
private Receiver[][] _thisReceiver
private Token _token
Constructor Detail |
---|
public RendezvousReceiver()
public RendezvousReceiver(IOPort container) throws IllegalActionException
container
- The port containing this receiver.
IllegalActionException
- If this receiver cannot be
contained by the proposed container.Method Detail |
---|
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 static Token[][] getFromAll(Receiver[][] receivers, RendezvousDirector director) throws TerminateProcessException
receivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver.director
- The director, on which this method
synchronizes.
TerminateProcessException
- If the actor to which this
receiver belongs is to be terminated.public static Token getFromAny(Receiver[][] receivers, RendezvousDirector director) throws TerminateProcessException
receivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver.director
- The director, on which this method
synchronizes.
TerminateProcessException
- If the actor to which this
receiver belongs is to be terminated.public static void getFromAnyPutToAll(Receiver[][] getReceivers, Receiver[][] putReceivers, RendezvousDirector director) throws IllegalActionException, TerminateProcessException
getReceivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver, to get tokens from.putReceivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver, to put tokens to.director
- The director, on which this method
synchronizes.
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 is to be terminated.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
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 IllegalActionException, TerminateProcessException
put
in interface Receiver
put
in class AbstractReceiver
token
- The token, or null to not put any token.
IllegalActionException
- If the token is not
acceptable to the port (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 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
putToAll
in interface Receiver
putToAll
in class AbstractReceiver
token
- The token to put, or null to not put any 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 putToAll(Token token, Receiver[] receivers, RendezvousDirector director) throws IllegalActionException, TerminateProcessException
token
- The token to put, or null to not put any token.receivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver.director
- The director, on which this method
synchronizes.
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 is to be terminated.public static void putToAll(Token[][] tokens, Receiver[][] receivers, RendezvousDirector director) throws IllegalActionException, TerminateProcessException
tokens
- The tokens to put.receivers
- * The receivers, which are assumed to all be
instances of RendezvousReceiver.director
- The director, on which this method
synchronizes.
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 is to be terminated.public static void putToAny(Token token, Receiver[][] receivers, RendezvousDirector director) throws IllegalActionException, TerminateProcessException
token
- The token to put.receivers
- The receivers, which are assumed to all be
instances of RendezvousReceiver.director
- The director, on which this method
synchronizes.
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 is to be terminated.public void requestFinish()
requestFinish
in interface ProcessReceiver
public void reset()
reset
in interface ProcessReceiver
reset
in interface Receiver
reset
in class AbstractReceiver
public static void waitForChange(RendezvousDirector director) throws TerminateProcessException
director
- The director on which to wait.
TerminateProcessException
- If a finish has been
requested of the specified director, or if the calling thread
is interrupted while waiting.protected static void _commitRendezvous(java.util.Set receivers, RendezvousDirector director)
receivers
- The receivers that participate in the rendezvous.director
- The director._receiversReadyToCommit(Receiver[][], boolean)
protected RendezvousDirector _getDirector()
protected static java.util.Set _receiversReadyToCommit(Receiver[][] receivers, boolean isPut)
receivers
- The array of receivers to be put to or get
from.isPut
- If true, the rendezvous is to put tokens to the
receivers; if false, the rendezvous is to get tokens from the
receivers.
_commitRendezvous(Set, RendezvousDirector)
private static boolean _checkRendezvous(Receiver[][] receivers, boolean isPut, java.util.Set beingChecked, java.util.Set ready, java.util.Set notReady, java.util.Set symmetricReceivers, boolean isSymmetricGet, boolean isSymmetricPut, Receiver farSideReceiver)
receivers
- The initial two-dimensional array of receivers
on an actor.isPut
- Whether the request is put.beingChecked
- The set of receivers that are being checked
by previous recursive calls.ready
- The set of receivers that are ready for a
rendezvous.notReady
- The set of receivers that are not ready for a
rendezvous.symmetricReceivers
- The set of symmetric receivers that
have been visited during the traversal.isSymmetricGet
- Whether the previous recursive call is
from the other side (the get side) of a Merge or Barrier.isSymmetricPut
- Whether the previous recursive call is
from the other side (the put side) of a Merge or Barrier.farSideReceiver
- The receiver that is being checked on
the far side, or null if this method is not called from the far
side.
private static java.util.Map _getOrPutTokens(Receiver[][] getReceivers, Receiver[][] putReceivers, RendezvousDirector director, Token token, Token[][] tokenArray, int flag) throws IllegalActionException, TerminateProcessException
getReceivers
- The receivers from with tokens are
received.putReceivers
- The receivers to which tokens are put.director
- The director.token
- The token of the put to any operation, or null.tokenArray
- The token array of the put to all operation, or
null.flag
- The flag representing the operation to be
performed.
IllegalActionException
- If the token is not
acceptable to one of the ports (e.g., wrong type). This can
happen only if the operation is put to all or put to any.
TerminateProcessException
- If the actor to which this
receiver belongs is to be terminated.private static int _getSelectedBranch(Receiver[][] receivers, java.util.Set beingChecked, java.util.Set ready)
_checkRendezvous(Receiver[][], boolean, Set, Set, Set,
Set, boolean, boolean, Receiver)
.
receivers
- The two-dimensional array of receivers.beingChecked
- The set of receivers that are being checked
by previous recursive calls.ready
- The set of receivers that are ready for a
rendezvous.
private static boolean _isConditional(Receiver[][] receivers, boolean isPut)
receivers
- The two-dimensional array of receivers.isPut
- Whether to test put conditional (true) or to test
get conditional (false).
private void _resetFlags(boolean clearGet, boolean clearPut)
clearGet
- Whether to reset the flags related to the get methods.clearPut
- Whether to reset the flags related to the put methods.private static void _resetReceiversFlags(Receiver[][] receivers, boolean clearGet, boolean clearPut)
receivers
- An array of receivers to be reset.clearGet
- Whether to reset the flags related to the get methods.clearPut
- Whether to reset the flags related to the put methods.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |