Class MailboxBoundaryReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- ptolemy.actor.Mailbox
-
- ptolemy.actor.process.MailboxBoundaryReceiver
-
- All Implemented Interfaces:
ProcessReceiver,Receiver
public class MailboxBoundaryReceiver extends Mailbox implements ProcessReceiver
A process receiver that stores tokens via a mailbox and can be used by composite actors. This receiver extends the functionality of the mailbox receiver found in the actor package in two key ways. First it facilitates blocking reads and writes. If a read (a call to get()) is attempted when this mailbox is empty then the call will block until a token is placed in the mailbox. Similarly if a write (a call to put()) is attempted when this mailbox is full (has a token) then the call will block until the token is removed from the mailbox.The second key feature of this mailbox receiver is that it can be used by opaque composite actors operating in process-oriented models of computation. Indeed the name "MailboxBoundaryReceiver" is used to indicate that this receiver can be contained on the boundary of an opaque composite actor. The get() and put() methods of mailbox boundary receiver can be invoked by a Branch object. In such cases any blocks that occur are registered with the calling branch. The branch will then serve as a proxy by communicating to the director through the branch controller.
Note that it is not necessary for a mailbox boundary receiver to be used in the ports of an opaque composite actor. It is perfectly fine for a mailbox boundary receiver to be used in the ports of an atomic actor. In such cases the get() and put() methods are called without the use of a branch object. If blocking reads or writes occur they are registered with the controlling director without the need for a branch or branch controller.
- Since:
- Ptolemy II 1.0
- Version:
- $Id$
- Author:
- John S. Davis II
- See Also:
Branch,BranchController- Pt.AcceptedRating:
- Yellow (davisj)
- Pt.ProposedRating:
- Green (mudit)
-
-
Constructor Summary
Constructors Constructor Description MailboxBoundaryReceiver()Construct an empty MailboxBoundaryReceiver with no container.MailboxBoundaryReceiver(IOPort container)Construct an empty MailboxBoundaryReceiver with the specified container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tokenget()Get a token from this receiver.ProcessDirectorgetDirector()Return the director in charge of this receiver, or null if there is none.booleanisConnectedToBoundary()Return true if this receiver is connected to a boundary port.booleanisConnectedToBoundaryInside()Return true if this receiver is connected to the inside of an input boundary port; return false otherwise.booleanisConnectedToBoundaryOutside()Return true if this receiver is connected to the outside of an output boundary port; return false otherwise.booleanisConsumerReceiver()Return true if this is a consumer receiver; return false otherwise.booleanisInsideBoundary()Return true if this receiver is contained on the inside of a boundary port.booleanisOutsideBoundary()Return true if this receiver is contained on the outside of a boundary port.booleanisProducerReceiver()Return true if this is a producer receiver; return false otherwise.booleanisReadBlocked()Return a true or false to indicate whether there is a read block on this receiver or not, respectively.booleanisWriteBlocked()Return a true or false to indicate whether there is a write block on this receiver or not.voidput(Token token)Put a token into this receiver.voidrequestFinish()Set a local flag requesting that execution of the actor containing this receiver discontinue.voidreset()Reset the local flags of this receiver.voidsetContainer(IOPort port)Set the container.-
Methods inherited from class ptolemy.actor.Mailbox
clear, elementList, hasRoom, hasRoom, hasToken, hasToken
-
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getContainer, getCurrentTime, getModelTime, isKnown, putArray, putArrayToAll, putToAll, 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
clear, elementList, getArray, getContainer, hasRoom, hasRoom, hasToken, hasToken, isKnown, putArray, putArrayToAll, putToAll
-
-
-
-
Constructor Detail
-
MailboxBoundaryReceiver
public MailboxBoundaryReceiver()
Construct an empty MailboxBoundaryReceiver with no container.
-
MailboxBoundaryReceiver
public MailboxBoundaryReceiver(IOPort container) throws IllegalActionException
Construct an empty MailboxBoundaryReceiver with the specified container.- Parameters:
container- The container.- Throws:
IllegalActionException- If the container cannot contain this receiver.
-
-
Method Detail
-
get
public Token get()
Get a token from this receiver. If the receiver is empty then block until a token becomes available. Use the local director to manage blocking reads that occur. If this receiver is terminated during the execution of this method, then throw a TerminateProcessException.
-
getDirector
public ProcessDirector getDirector()
Return the director in charge of this receiver, or null if there is none.- Returns:
- The director in charge of this receiver.
-
isConnectedToBoundary
public boolean isConnectedToBoundary() throws IllegalActionExceptionReturn true if this receiver is connected to a boundary port. A boundary port is an opaque port that is contained by a composite actor. If this receiver is connected to a boundary port, then return true; otherwise return false. This method is not synchronized so the caller should be.- Specified by:
isConnectedToBoundaryin interfaceProcessReceiver- Returns:
- True if this receiver is connected to boundary port; return false otherwise.
- Throws:
IllegalActionException- See Also:
BoundaryDetector
-
isConnectedToBoundaryInside
public boolean isConnectedToBoundaryInside() throws InvalidStateException, IllegalActionExceptionReturn true if this receiver is connected to the inside of an input boundary port; return false otherwise. A boundary port is an opaque port that is contained by a composite actor. This method is not synchronized so the caller should be.- Specified by:
isConnectedToBoundaryInsidein interfaceProcessReceiver- Returns:
- True if this receiver is connected to the inside of a boundary port; return false otherwise.
- Throws:
IllegalActionExceptionInvalidStateException- See Also:
BoundaryDetector
-
isConnectedToBoundaryOutside
public boolean isConnectedToBoundaryOutside() throws IllegalActionExceptionReturn true if this receiver is connected to the outside of an output boundary port; return false otherwise. A boundary port is an opaque port that is contained by a composite actor. If this receiver is contained on the inside of a boundary port, then return false. This method is not synchronized so the caller should be.- Specified by:
isConnectedToBoundaryOutsidein interfaceProcessReceiver- Returns:
- True if this receiver is connected to the outside of a boundary port; return false otherwise.
- Throws:
IllegalActionException- See Also:
BoundaryDetector
-
isConsumerReceiver
public boolean isConsumerReceiver() throws IllegalActionExceptionReturn true if this is a consumer receiver; return false otherwise. A consumer receiver is defined as a receiver that is connected to a boundary port.- Specified by:
isConsumerReceiverin interfaceProcessReceiver- Returns:
- True if this is a consumer receiver; return false otherwise.
- Throws:
IllegalActionException
-
isInsideBoundary
public boolean isInsideBoundary()
Return true if this receiver is contained on the inside of a boundary port. A boundary port is an opaque port that is contained by a composite actor. If this receiver is contained on the inside of a boundary port then return true; otherwise return false. This method is not synchronized so the caller should be.- Specified by:
isInsideBoundaryin interfaceProcessReceiver- Returns:
- True if this receiver is contained on the inside of a boundary port; return false otherwise.
- See Also:
BoundaryDetector
-
isOutsideBoundary
public boolean isOutsideBoundary()
Return true if this receiver is contained on the outside of a boundary port. A boundary port is an opaque port that is contained by a composite actor. If this receiver is contained on the outside of a boundary port then return true; otherwise return false. This method is not synchronized so the caller should be.- Specified by:
isOutsideBoundaryin interfaceProcessReceiver- Returns:
- True if this receiver is contained on the outside of a boundary port; return false otherwise.
- See Also:
BoundaryDetector
-
isProducerReceiver
public boolean isProducerReceiver()
Return true if this is a producer receiver; return false otherwise. A producer receiver is defined as a receiver that is connected to a boundary port.- Specified by:
isProducerReceiverin interfaceProcessReceiver- Returns:
- True if this is a producer receiver; return false otherwise.
-
isReadBlocked
public boolean isReadBlocked()
Return a true or false to indicate whether there is a read block on this receiver or not, respectively.- Specified by:
isReadBlockedin interfaceProcessReceiver- Returns:
- a boolean indicating whether a read is blocked on this receiver or not.
-
isWriteBlocked
public boolean isWriteBlocked()
Return a true or false to indicate whether there is a write block on this receiver or not.- Specified by:
isWriteBlockedin interfaceProcessReceiver- Returns:
- A boolean indicating whether a write is blocked on this receiver or not.
-
put
public void put(Token token)
Put a token into this receiver. If the receiver is full (contains a token) then block until room becomes available. Use the local director to manage blocking writes that occur. If this receiver is terminated during the execution of this method, then throw a TerminateProcessException. If the specified token is null, this method does nothing.
-
requestFinish
public void requestFinish()
Set a local flag requesting that execution of the actor containing this receiver discontinue.- Specified by:
requestFinishin interfaceProcessReceiver
-
reset
public void reset()
Reset the local flags of this receiver. Use this method when restarting execution.- Specified by:
resetin interfaceProcessReceiver- Specified by:
resetin interfaceReceiver- Overrides:
resetin classAbstractReceiver
-
setContainer
public void setContainer(IOPort port) throws IllegalActionException
Set the container. This overrides the base class to record the director.- Specified by:
setContainerin interfaceReceiver- Overrides:
setContainerin classAbstractReceiver- Parameters:
port- The container.- Throws:
IllegalActionException- If the container is not of an appropriate subclass of IOPort, or if the container's director is not an instance of ProcessDirector.- See Also:
AbstractReceiver.getContainer()
-
-