ptolemy.actor.gt
Class ModelExecutor.WrapperPort

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.Port
          extended by ptolemy.kernel.ComponentPort
              extended by ptolemy.actor.IOPort
                  extended by ptolemy.actor.TypedIOPort
                      extended by ptolemy.actor.gt.ModelExecutor.WrapperPort
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Enclosing class:
ModelExecutor

private class ModelExecutor.WrapperPort
extends TypedIOPort

The port of the wrapper. The get and send methods delegate to the port with the same name of the model executor.

Since:
Ptolemy II 8.0
Version:
$Id: ModelExecutor.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Thomas Huining Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 
Fields inherited from class ptolemy.actor.TypedIOPort
TYPE
 
Fields inherited from class ptolemy.actor.IOPort
_hasPortEventListeners, _portEventListeners, CONFIGURATION, RECEIVERS, REMOTERECEIVERS
 
Fields inherited from class ptolemy.kernel.Port
_insideLinks, _relationsList
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
ModelExecutor.WrapperPort(ModelExecutor.Wrapper container, java.lang.String name, boolean isInput, boolean isOutput)
          Construct a TypedIOPort with a container and a name that is either an input, an output, or both, depending on the third and fourth arguments.
 
Method Summary
 void broadcast(Token token)
          Send a token to all connected receivers.
 void broadcast(Token[] tokenArray, int vectorLength)
          Send the specified portion of a token array to all receivers connected to this port.
 Token get(int channelIndex)
          Get a token from the specified channel.
 Token[] get(int channelIndex, int vectorLength)
          Get an array of tokens from the specified channel.
 int getWidth()
          Return the width of the port.
 boolean hasToken(int channelIndex)
          Return true if the specified channel has a token to deliver via the get() method.
 boolean hasToken(int channelIndex, int tokens)
          Return true if the specified channel has the specified number of tokens to deliver via the get() method.
 void send(int channelIndex, Token token)
          Send a token to the specified channel, checking the type and converting the token if necessary.
 void send(int channelIndex, Token[] tokenArray, int vectorLength)
          Send the specified portion of a token array to all receivers connected to the specified channel, checking the type and converting the token if necessary.
 
Methods inherited from class ptolemy.actor.TypedIOPort
_checkContainer, _checkLiberalLink, _checkLink, _checkType, _description, addTypeListener, attributeChanged, clone, convert, getType, getTypeTerm, isTypeAcceptable, removeTypeListener, sendInside, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.IOPort
_checkLiberalLink, _exportMoMLContents, _getInsideWidth, _getOutsideWidth, _getReceiversLinkedToGroup, _newInsideReceiver, _newReceiver, _notifyPortEventListeners, _removeReceivers, addIOPortEventListener, broadcastClear, checkWidthConstraints, createReceivers, deepConnectedInPortList, deepConnectedInPorts, deepConnectedOutPortList, deepConnectedOutPorts, deepGetReceivers, getChannelForReceiver, getCurrentTime, getDefaultWidth, getInside, getInsideReceivers, getModelTime, getReceivers, getReceivers, getReceivers, getRelationIndex, getRemoteReceivers, getRemoteReceivers, getWidthFromConstraints, getWidthInside, hasRoom, hasRoomInside, hasTokenInside, hasWidthConstraints, insertLink, insideSinkPortList, insideSourcePortList, isInput, isInsideConnected, isKnown, isKnown, isKnownInside, isMultiport, isOutput, isOutsideConnected, liberalLink, link, numberOfSinks, numberOfSources, removeIOPortEventListener, sendClear, sendClearInside, setContainer, setDefaultWidth, setInput, setMultiport, setOutput, setWidthEquals, setWidthEquals, sinkPortList, sourcePortList, transferInputs, transferOutputs, unlink, unlink, unlinkAll, unlinkAllInside, unlinkInside, unlinkInside
 
Methods inherited from class ptolemy.kernel.ComponentPort
_deepConnectedPortList, _deepConnectedPorts, _deepInsidePortList, _deepInsidePorts, _isInsideLinkable, deepConnectedPortList, deepConnectedPorts, deepInsidePortList, deepInsidePorts, insertInsideLink, insidePortList, insidePorts, insideRelationList, insideRelations, isDeeplyConnected, isInsideGroupLinked, isInsideLinked, isOpaque, numInsideLinks
 
Methods inherited from class ptolemy.kernel.Port
_getContainedObject, _propagateExistence, connectedPortList, connectedPorts, getContainer, isGroupLinked, isLinked, linkedRelationList, linkedRelations, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, numLinks, setName
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelExecutor.WrapperPort

ModelExecutor.WrapperPort(ModelExecutor.Wrapper container,
                          java.lang.String name,
                          boolean isInput,
                          boolean isOutput)
                    throws IllegalActionException,
                           NameDuplicationException
Construct a TypedIOPort with a container and a name that is either an input, an output, or both, depending on the third and fourth arguments. The specified container must implement the TypedActor interface or an exception will be thrown.

Parameters:
container - The container actor.
name - The name of the port.
isInput - True if this is to be an input port.
isOutput - True if this is to be an output port.
Throws:
IllegalActionException - If the port is not of an acceptable class for the container, or if the container does not implement the TypedActor interface.
NameDuplicationException - If the name coincides with a port already in the container.
Method Detail

broadcast

public void broadcast(Token token)
               throws NoRoomException,
                      IllegalActionException
Send a token to all connected receivers. Tokens are in general immutable, so each receiver is given a reference to the same token and no clones are made. The transfer is accomplished by calling getRemoteReceivers() to determine the number of channels with valid receivers and then calling send() on the appropriate channels. It would probably be faster to call put() directly on the receivers. If there are no destination receivers, then nothing is sent. If the port is not connected to anything, or receivers have not been created in the remote port, then just return.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a put, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling put.

Overrides:
broadcast in class TypedIOPort
Parameters:
token - The token to send
Throws:
IllegalActionException - If the token to be sent cannot be converted to the type of this port
NoRoomException - If a send to one of the channels throws it.

broadcast

public void broadcast(Token[] tokenArray,
                      int vectorLength)
               throws NoRoomException,
                      IllegalActionException
Send the specified portion of a token array to all receivers connected to this port. The first vectorLength tokens of the token array are sent.

Tokens are in general immutable, so each receiver is given a reference to the same token and no clones are made. If the port is not connected to anything, or receivers have not been created in the remote port, or the channel index is out of range, or the port is not an output port, then just silently return. This behavior makes it easy to leave output ports unconnected when you are not interested in the output. The transfer is accomplished by calling the vectorized put() method of the remote receivers. If the port is not connected to anything, or receivers have not been created in the remote port, then just return.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a put, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling put.

Overrides:
broadcast in class TypedIOPort
Parameters:
tokenArray - The token array to send
vectorLength - The number of elements of the token array to send.
Throws:
NoRoomException - If there is no room in the receiver.
IllegalActionException - If the tokens to be sent cannot be converted to the type of this port

get

public Token get(int channelIndex)
          throws NoTokenException,
                 IllegalActionException
Get a token from the specified channel. If the channel has a group with more than one receiver (something that is possible if this is a transparent port), then this method calls get() on all receivers, but returns only the first non-null token returned by these calls. Normally this method is not used on transparent ports. If there is no token to return, then throw an exception.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a get, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling get().

Overrides:
get in class IOPort
Parameters:
channelIndex - The channel index.
Returns:
A token from the specified channel.
Throws:
NoTokenException - If there is no token.
IllegalActionException - If there is no director, and hence no receivers have been created, if the port is not an input port, or if the channel index is out of range.

get

public Token[] get(int channelIndex,
                   int vectorLength)
            throws NoTokenException,
                   IllegalActionException
Get an array of tokens from the specified channel. The parameter channelIndex specifies the channel and the parameter vectorLength specifies the number of valid tokens to get in the returned array. The length of the returned array will be equal to vectorLength.

If the channel has a group with more than one receiver (something that is possible if this is a transparent port), then this method calls get() on all receivers, but returns only the result from the first in the group. Normally this method is not used on transparent ports. If there are not enough tokens to fill the array, then throw an exception.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a get, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling get.

Overrides:
get in class IOPort
Parameters:
channelIndex - The channel index.
vectorLength - The number of valid tokens to get in the returned array.
Returns:
A token array from the specified channel containing vectorLength valid tokens.
Throws:
NoTokenException - If there is no array of tokens.
IllegalActionException - If there is no director, and hence no receivers have been created, if the port is not an input port, or if the channel index is out of range.

getWidth

public int getWidth()
             throws IllegalActionException
Return the width of the port. The width is the sum of the widths of the relations that the port is linked to (on the outside). Note that this method cannot be used to determine whether a port is connected (deeply) to another port that can either supply it with data or consume data it produces. The correct methods to use to determine that are numberOfSinks() and numberOfSources(). This method is read-synchronized on the workspace. This method will trigger the width inference algorithm if necessary.

Overrides:
getWidth in class IOPort
Returns:
The width of the port.
Throws:
IllegalActionException - If the width cannot be determined.
See Also:
IOPort.numberOfSinks(), IOPort.numberOfSources()

hasToken

public boolean hasToken(int channelIndex)
                 throws IllegalActionException
Return true if the specified channel has a token to deliver via the get() method. If this port is not an input, or if the channel index is out of range, then throw an exception. Note that this does not report any tokens in inside receivers of an output port. Those are accessible only through getInsideReceivers().

Overrides:
hasToken in class IOPort
Parameters:
channelIndex - The channel index.
Returns:
True if there is a token in the channel.
Throws:
IllegalActionException - If the receivers do not support this query, if there is no director, and hence no receivers, if the port is not an input port, or if the channel index is out of range.

hasToken

public boolean hasToken(int channelIndex,
                        int tokens)
                 throws IllegalActionException
Return true if the specified channel has the specified number of tokens to deliver via the get() method. If this port is not an input, or if the channel index is out of range, then throw an exception. Note that this does not report any tokens in inside receivers of an output port. Those are accessible only through getInsideReceivers().

Overrides:
hasToken in class IOPort
Parameters:
channelIndex - The channel index.
tokens - The number of tokens to query the channel for.
Returns:
True if there is a token in the channel.
Throws:
IllegalActionException - If the receivers do not support this query, if there is no director, and hence no receivers, if the port is not an input port, or if the channel index is out of range.

send

public void send(int channelIndex,
                 Token token)
          throws NoRoomException,
                 IllegalActionException
Send a token to the specified channel, checking the type and converting the token if necessary. If the port is not connected to anything, or receivers have not been created in the remote port, or the channel index is out of range, or the port is not an output port, then just silently return. This behavior makes it easy to leave output ports unconnected when you are not interested in the output. If the type of the specified token is the type of this port, or the token can be converted to that type losslessly, the token is sent to all receivers connected to the specified channel. Otherwise, IllegalActionException is thrown. Before putting the token into the destination receivers, this method also checks the type of the remote input port, and converts the token if necessary. The conversion is done by calling the convert() method of the type of the remote input port.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a put, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling put.

Overrides:
send in class TypedIOPort
Parameters:
channelIndex - The index of the channel, from 0 to width-1.
token - The token to send.
Throws:
IllegalActionException - If the token to be sent cannot be converted to the type of this port, or if the token is null.
NoRoomException - If there is no room in the receiver.

send

public void send(int channelIndex,
                 Token[] tokenArray,
                 int vectorLength)
          throws NoRoomException,
                 IllegalActionException
Send the specified portion of a token array to all receivers connected to the specified channel, checking the type and converting the token if necessary. The first vectorLength tokens of the token array are sent. If the port is not connected to anything, or receivers have not been created in the remote port, or the channel index is out of range, or the port is not an output port, then just silently return. This behavior makes it easy to leave output ports unconnected when you are not interested in the output.

If the type of the tokens in the specified portion of the token array is the type of this port, or the tokens in the specified portion of the token array can be converted to that type losslessly, the tokens in the specified portion of the token array are sent to all receivers connected to the specified channel. Otherwise, IllegalActionException is thrown. Before putting the tokens in the specified portion of the token array into the destination receivers, this method also checks the type of the remote input port, and converts the tokens if necessary. The conversion is done by calling the convert() method of the type of the remote input port.

Some of this method is read-synchronized on the workspace. Since it is possible for a thread to block while executing a put, it is important that the thread does not hold read access on the workspace when it is blocked. Thus this method releases read access on the workspace before calling put.

Overrides:
send in class TypedIOPort
Parameters:
channelIndex - The index of the channel, from 0 to width-1
tokenArray - The token array to send
vectorLength - The number of elements of the token array to send.
Throws:
NoRoomException - If there is no room in the receiver.
IllegalActionException - If the tokens to be sent cannot be converted to the type of this port, or if the vectorLength argument is greater than the length of the tokenArray argument.