Package ptolemy.actor
Class IntermediateReceiver
- java.lang.Object
-
- ptolemy.actor.AbstractReceiver
-
- ptolemy.actor.IntermediateReceiver
-
- All Implemented Interfaces:
Receiver
public class IntermediateReceiver extends AbstractReceiver
A receiver that delegates to another receiver all method calls exceptput(Token)
(and its variants), for which it delegates to a communication aspect. The delegated receiver and the communication aspect are specified as constructor arguments.This can be used, for example, when multiple communication links share resources. The communication aspect can, for example, delay the delivery of tokens to the delegated receiver to take into account resource availability. It could also be used to make a centralized record of various communications.
Subclasses of this receiver may also intervene on method calls other than put().
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Patricia Derler, Edward A. Lee
- Pt.AcceptedRating:
- Red (derler)
- Pt.ProposedRating:
- Yellow (derler)
-
-
Field Summary
Fields Modifier and Type Field Description protected IOPort
_port
The port.Receiver
_receiver
Target receiver that is wrapped by this intermediate receiver.CommunicationAspect
communicationAspect
communication aspect that receives tokens from this receiver.Actor
source
The source actor that sent a token to this receiver.
-
Constructor Summary
Constructors Constructor Description IntermediateReceiver(CommunicationAspect aspect, Receiver receiver)
Construct an intermediate receiver with no container that wraps the specified receiver using the specified communication aspect.IntermediateReceiver(CommunicationAspect aspect, Receiver receiver, IOPort port)
Construct an intermediate receiver with no container that wraps the specified receiver using the specified communication aspect.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Reset the communication aspect and the receiver that we delegate to.java.util.List<Token>
elementList()
Delegate to the internal receiver and return whatever it returns.Token
get()
Delegate to the internal receiver and return whatever it returns.IOPort
getContainer()
Delegate to the internal receiver and return whatever it returns.boolean
hasRoom()
Delegate to the internal receiver and return whatever it returns.boolean
hasRoom(int numberOfTokens)
Delegate to the internal receiver and return whatever it returns.boolean
hasToken()
Delegate to the internal receiver and return whatever it returns.boolean
hasToken(int numberOfTokens)
Delegate to the internal receiver and return whatever it returns.boolean
isKnown()
Delegate to the internal receiver and return whatever it returns.void
put(Token token)
Forward the specified token to communication aspect specified in the constructor.void
reset()
Reset this receiver to its initial state, which in this base class is the same as calling clear().void
setContainer(IOPort port)
Set the container of the internal receiver.-
Methods inherited from class ptolemy.actor.AbstractReceiver
getArray, getCurrentTime, getModelTime, putArray, putArrayToAll, putToAll, toString
-
-
-
-
Field Detail
-
communicationAspect
public CommunicationAspect communicationAspect
communication aspect that receives tokens from this receiver.
-
source
public Actor source
The source actor that sent a token to this receiver.
-
_receiver
public Receiver _receiver
Target receiver that is wrapped by this intermediate receiver.
-
_port
protected IOPort _port
The port.
-
-
Constructor Detail
-
IntermediateReceiver
public IntermediateReceiver(CommunicationAspect aspect, Receiver receiver)
Construct an intermediate receiver with no container that wraps the specified receiver using the specified communication aspect.- Parameters:
aspect
- The communication aspect that receives tokens received by this receiver.receiver
- The receiver wrapped by this intermediate receiver.
-
IntermediateReceiver
public IntermediateReceiver(CommunicationAspect aspect, Receiver receiver, IOPort port)
Construct an intermediate receiver with no container that wraps the specified receiver using the specified communication aspect.- Parameters:
aspect
- The communication aspect that receives tokens received by this receiver.receiver
- The receiver wrapped by this intermediate receiver.port
- The port wrapped by this intermediate receiver
-
-
Method Detail
-
clear
public void clear() throws IllegalActionException
Reset the communication aspect and the receiver that we delegate to.- Specified by:
clear
in interfaceReceiver
- Overrides:
clear
in classAbstractReceiver
- Throws:
IllegalActionException
- Always thrown.
-
elementList
public java.util.List<Token> elementList() throws IllegalActionException
Delegate to the internal receiver and return whatever it returns.- Specified by:
elementList
in interfaceReceiver
- Overrides:
elementList
in classAbstractReceiver
- Returns:
- A list of instances of Token.
- Throws:
IllegalActionException
- Always thrown in this base class.
-
get
public Token get() throws NoTokenException
Delegate to the internal receiver and return whatever it returns.- Specified by:
get
in interfaceReceiver
- Specified by:
get
in classAbstractReceiver
- Returns:
- A token read from the receiver.
- Throws:
NoTokenException
- If the delegated receiver throws it.
-
getContainer
public IOPort getContainer()
Delegate to the internal receiver and return whatever it returns.- Specified by:
getContainer
in interfaceReceiver
- Overrides:
getContainer
in classAbstractReceiver
- Returns:
- The port containing the internal receiver.
- See Also:
setContainer(IOPort)
-
hasRoom
public boolean hasRoom()
Delegate to the internal receiver and return whatever it returns.- Specified by:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- Returns:
- True if the next call to put() will not result in a NoRoomException.
-
hasRoom
public boolean hasRoom(int numberOfTokens)
Delegate to the internal receiver and return whatever it returns.- Specified by:
hasRoom
in interfaceReceiver
- Specified by:
hasRoom
in classAbstractReceiver
- Parameters:
numberOfTokens
- The number of tokens to put into this receiver.- Returns:
- True if the next numberOfTokens calls to put() will not result in a NoRoomException.
-
hasToken
public boolean hasToken()
Delegate to the internal receiver and return whatever it returns.- Specified by:
hasToken
in interfaceReceiver
- Specified by:
hasToken
in classAbstractReceiver
- Returns:
- True if the next call to get() will not result in a NoTokenException.
-
hasToken
public boolean hasToken(int numberOfTokens)
Delegate to the internal receiver and return whatever it returns.- Specified by:
hasToken
in interfaceReceiver
- Specified by:
hasToken
in classAbstractReceiver
- Parameters:
numberOfTokens
- The number of tokens desired.- Returns:
- True if the next numberOfTokens calls to get() will not result in a NoTokenException.
-
isKnown
public boolean isKnown()
Delegate to the internal receiver and return whatever it returns.- Specified by:
isKnown
in interfaceReceiver
- Overrides:
isKnown
in classAbstractReceiver
- Returns:
- True.
-
put
public void put(Token token) throws NoRoomException, IllegalActionException
Forward the specified token to communication aspect specified in the constructor.- Specified by:
put
in interfaceReceiver
- Specified by:
put
in classAbstractReceiver
- Parameters:
token
- The token to put into the receiver, or null to put no token.- Throws:
NoRoomException
- If there is no room in the receiver.IllegalActionException
- If the put fails (e.g. because of incompatible types).
-
reset
public void reset() throws IllegalActionException
Reset this receiver to its initial state, which in this base class is the same as calling clear().- Specified by:
reset
in interfaceReceiver
- Overrides:
reset
in classAbstractReceiver
- Throws:
IllegalActionException
- If reset() is not supported by the domain.
-
setContainer
public void setContainer(IOPort port) throws IllegalActionException
Set the container of the internal receiver.- Specified by:
setContainer
in interfaceReceiver
- Overrides:
setContainer
in classAbstractReceiver
- Parameters:
port
- The container.- Throws:
IllegalActionException
- If the container is not of an appropriate subclass of IOPort. Not thrown in this base class, but may be thrown in derived classes.- See Also:
getContainer()
-
-