public class TypedIOPort extends IOPort implements Typeable
This class keeps a list of TypeListeners. Whenever the type changes, this class will generate an instance of TypeEvent and pass it to the listeners by calling their typeChanged() method. A TypeListener register its interest in the type change event of this port by calling addTypeListener(), and can be removed from the listener list by calling the removeTypeListener().
A TypedIOPort can only link to instances of TypedIORelation. Derived classes may further constrain links to a subclass of TypedIORelation. To do this, they should override the protected methods _link() and _linkInside() to throw an exception if their arguments are not of the appropriate type. Similarly, an TypeIOPort can only be contained by a class derived from ComponentEntity and implementing the TypedActor interface. Subclasses may further constrain the containers by overriding _checkContainer().
Note that actors that call some of the setTypeXXX methods may also need to have a clone() method. Although the base classes neatly handle most aspects of the clone operation, there are subtleties involved with cloning type constraints. Absolute type constraints on ports and parameters are carried automatically into the clone, so clone() methods should never call setTypeEquals(). However, relative type constraints of the other setTypeXXX() methods are not cloned automatically because of the difficulty of ensuring that the other object being referred to in a relative constraint is the intended one.
For example the Ramp actor constructor calls:
output.setTypeAtLeast(init);so the clone() method of the Ramp actor calls:
newObject.output.setTypeAtLeast(newObject.init);
Yellow (neuendor) |
Green (yuhong) |
Modifier and Type | Class and Description |
---|---|
static class |
TypedIOPort.RunTimeTypeCheckException
Exception class for run-time type errors.
|
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected Type |
_resolvedType
The resolved type of the port.
|
static int |
TYPE
Indicate that the description(int) method should include
information about the type of this port.
|
_constantLimit, _constantToken, _constantTokensSent, _hasPortEventListeners, _portEventListeners, CONFIGURATION, defaultValue, RECEIVERS, REMOTERECEIVERS
_insideLinks, _relationsList
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
TypedIOPort()
Construct a TypedIOPort with no container and no name that is
neither an input nor an output.
|
TypedIOPort(ComponentEntity container,
java.lang.String name)
Construct a TypedIOPort with a containing actor and a name
that is neither an input nor an output.
|
TypedIOPort(ComponentEntity 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.
|
TypedIOPort(Workspace workspace)
Construct a port in the specified workspace with an empty
string as a name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_checkContainer(Entity container)
Override the base class to ensure that the proposed container
implements the TypedActor interface (the base class ensures that
the container implements the Actor interface), is null, or is
an EntityLibrary.
|
protected void |
_checkLiberalLink(ComponentRelation relation)
Override the method in the super class to ensure compatibility of
the relation.
|
protected void |
_checkLink(Relation relation)
Override the method in the super class to ensure compatibility of
the relation.
|
protected void |
_checkType(Token token)
Check that the specified token as well as the token in
the default value, if specified, is compatible with the
resolved type of this port.
|
protected void |
_checkTypedIOPortContainer(Entity container)
Override the base class to ensure that the proposed container
implements the TypedActor interface (the base class ensures that
the container implements the Actor interface), is null, or is
an EntityLibrary.
|
protected java.lang.String |
_description(int detail,
int indent,
int bracket)
Return a description of the object.
|
void |
addTypeListener(TypeListener listener)
Add a type listener to this port.
|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute.
|
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.
|
java.lang.Object |
clone(Workspace workspace)
Clone this port into the specified workspace.
|
Token |
convert(Token token)
Convert the specified token into a token with type equal
to the type returned by getType().
|
boolean |
getAutomaticTypeConversion()
Indicates whether conversion of received tokens is enabled or not.
|
Type |
getType()
Return the type of this port.
|
InequalityTerm |
getTypeTerm()
Return an InequalityTerm encapsulating the type of
this port.
|
boolean |
isTypeAcceptable()
Check whether the current type of this port is acceptable.
|
void |
removeTypeListener(TypeListener listener)
Remove a type listener from this port.
|
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.
|
void |
sendInside(int channelIndex,
Token token)
Send the specified token to all receivers connected to the
specified inside channel of this port, checking the type and
converting the token if necessary.
|
void |
setAutomaticTypeConversion(boolean automaticTypeConversion)
Allow actors to disable automatic type conversion on their input
ports in case they do not need it.
|
void |
setTypeAtLeast(InequalityTerm typeTerm)
Constrain the type of this port to be equal to or greater
than the type represented by the specified InequalityTerm.
|
void |
setTypeAtLeast(Typeable lesser)
Constrain the type of this port to be equal to or greater
than the type of the specified Typeable object.
|
void |
setTypeAtMost(Type type)
Constrain the type of this port to be equal to or less
than the argument.
|
void |
setTypeEquals(Type type)
Set the type of this port.
|
void |
setTypeSameAs(Typeable equal)
Constrain the type of this port to be the same as the type
of the specified Typeable object.
|
java.util.List |
typeConstraintList()
Deprecated.
Use typeConstraints().
|
java.util.Set<Inequality> |
typeConstraints()
Return the type constraints of this port in the form of a
set of inequalities.
|
_checkLiberalLink, _exportMoMLContents, _getInsideWidth, _getOutsideWidth, _getReceiversLinkedToGroup, _newInsideReceiver, _newInsideReceiver, _newReceiver, _newReceiver, _notifyPortEventListeners, _removeReceivers, _setConstant, _wrapReceiver, addIOPortEventListener, broadcastClear, checkWidthConstraints, createReceivers, deepConnectedInPortList, deepConnectedInPorts, deepConnectedOutPortList, deepConnectedOutPorts, deepGetReceivers, get, get, getChannelForReceiver, getCommunicationAspects, getCurrentTime, getDefaultWidth, getInside, getInsideReceivers, getModelTime, getReceivers, getReceivers, getReceivers, getRelationIndex, getRemoteReceivers, getRemoteReceivers, getWidth, getWidthFromConstraints, getWidthInside, hasNewToken, hasNewTokenInside, hasRoom, hasRoomInside, hasToken, hasToken, hasTokenInside, hasWidthConstraints, insertLink, insideSinkPortList, insideSourcePortList, invalidateCommunicationAspects, isInput, isInsideConnected, isKnown, isKnown, isKnownInside, isMultiport, isOutput, isOutsideConnected, liberalLink, link, numberOfSinks, numberOfSources, removeIOPortEventListener, reset, sendClear, sendClearInside, setContainer, setDefaultWidth, setInput, setMultiport, setOutput, setWidthEquals, setWidthEquals, sinkPortList, sourcePortList, transferInputs, transferOutputs, unlink, unlink, unlinkAll, unlinkAllInside, unlinkInside, unlinkInside
_deepConnectedPortList, _deepConnectedPorts, _deepInsidePortList, _deepInsidePorts, _isInsideLinkable, deepConnectedPortList, deepConnectedPorts, deepInsidePortList, deepInsidePorts, insertInsideLink, insidePortList, insidePorts, insideRelationList, insideRelations, isDeeplyConnected, isInsideGroupLinked, isInsideLinked, isOpaque, numInsideLinks
_getContainedObject, _propagateExistence, connectedPortList, connectedPorts, getContainer, isGroupLinked, isLinked, linkedRelationList, linkedRelations, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, numLinks, setName
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, 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, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
public static final int TYPE
protected Type _resolvedType
public TypedIOPort()
public TypedIOPort(Workspace workspace) throws IllegalActionException
workspace
- The workspace that will list the port.IllegalActionException
- If thrown by the superclass.public TypedIOPort(ComponentEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container actor.name
- The name of the port.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.public TypedIOPort(ComponentEntity container, java.lang.String name, boolean isInput, boolean isOutput) throws IllegalActionException, NameDuplicationException
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.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.public void addTypeListener(TypeListener listener)
listener
- The TypeListener to add.removeTypeListener(TypeListener)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class IOPort
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container.public void broadcast(Token token) throws IllegalActionException, NoRoomException
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.
broadcast
in class IOPort
token
- The token to sendIllegalActionException
- If the token to be sent cannot
be converted to the type of this portNoRoomException
- If a send to one of the channels throws
it.public void broadcast(Token[] tokenArray, int vectorLength) throws IllegalActionException, NoRoomException
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.
broadcast
in class IOPort
tokenArray
- The token array to sendvectorLength
- The number of elements of the token
array to send.NoRoomException
- If there is no room in the receiver.IllegalActionException
- If the tokens to be sent cannot
be converted to the type of this portpublic java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class IOPort
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- If one or more of the
attributes cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public Token convert(Token token) throws IllegalActionException
convert
in class IOPort
token
- The token to convert.IllegalActionException
- If the conversion is
invalid.public Type getType()
public InequalityTerm getTypeTerm()
getTypeTerm
in interface Typeable
public boolean isTypeAcceptable()
isTypeAcceptable
in interface Typeable
public boolean getAutomaticTypeConversion()
setAutomaticTypeConversion(boolean)
public void removeTypeListener(TypeListener listener)
listener
- The TypeListener to be removed.addTypeListener(TypeListener)
public void send(int channelIndex, Token token) throws IllegalActionException, NoRoomException
If the token argument is null, then no token is sent.
What this means exactly is domain dependent. In some domains
(SR, Continuous), it asserts that the output is "absent."
That is, IOPort.isKnown(int)
will return true
and IOPort.hasToken(int)
will return false.
In other domains (SDF, DE, PN), it simply does nothing.
Nothing is sent. Hence, IOPort.isKnown(int)
and IOPort.hasToken(int)
will return whatever they would
have returned before the call.
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.
send
in class IOPort
channelIndex
- The index of the channel, from 0 to width-1.token
- The token to send, or null to send no token.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.public void send(int channelIndex, Token[] tokenArray, int vectorLength) throws IllegalActionException, NoRoomException
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.
send
in class IOPort
channelIndex
- The index of the channel, from 0 to width-1tokenArray
- The token array to sendvectorLength
- The number of elements of the token
array to send.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.public void sendInside(int channelIndex, Token token) throws IllegalActionException, NoRoomException
If the token argument is null, then no token is sent.
What this means exactly is domain dependent. In some domains
(SR, Continuous), it asserts that the output is "absent."
That is, IOPort.isKnown(int)
will return true
and IOPort.hasToken(int)
will return false.
In other domains (SDF, DE, PN), it simply does nothing.
Nothing is sent. Hence, IOPort.isKnown(int)
and IOPort.hasToken(int)
will return whatever they would
have returned before the call.
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.
sendInside
in class IOPort
channelIndex
- The index of the channel, from 0 to width-1token
- The token to sendNoRoomException
- If there is no room in the receiver.IllegalActionException
- If conversion to the type of
the destination port cannot be done.public void setAutomaticTypeConversion(boolean automaticTypeConversion)
automaticTypeConversion
- False in order to disable
conversion of received tokens, true otherwise.getAutomaticTypeConversion()
public void setTypeAtLeast(Typeable lesser)
Actors that call this method should have a clone() method that repeats the relative type constraints that were specified in the constructor.
setTypeAtLeast
in interface Typeable
lesser
- A Typeable object.public void setTypeAtLeast(InequalityTerm typeTerm)
Actors that call this method should have a clone() method that repeats the relative type constraints that were specified in the constructor.
setTypeAtLeast
in interface Typeable
typeTerm
- An InequalityTerm.public void setTypeAtMost(Type type)
Actors that call this method should have a clone() method that repeats the relative type constraints that were specified in the constructor.
setTypeAtMost
in interface Typeable
type
- An instance of Type.public void setTypeEquals(Type type)
Actors that call setTypeEquals() are not required to have a clone() method. Absolute type constraints on ports and parameters are carried automatically into the clone, so clone() methods of actors should never call setTypeEquals(). Actors that call the other setTypeXXX() methods should have a clone() method.
This method is write-synchronized on the workspace.
setTypeEquals
in interface Typeable
type
- A Type.public void setTypeSameAs(Typeable equal)
Actors that call this method should have a clone() method that repeats the relative type constraints that were specified in the constructor.
setTypeSameAs
in interface Typeable
equal
- A Typeable object.public java.util.Set<Inequality> typeConstraints()
typeConstraints
in interface HasTypeConstraints
Inequality
@Deprecated public java.util.List typeConstraintList()
Inequality
protected void _checkContainer(Entity container) throws IllegalActionException
_checkContainer
in class IOPort
container
- The proposed container.IllegalActionException
- If the proposed container is not a
TypedActor, or if the base class throws it.protected final void _checkTypedIOPortContainer(Entity container) throws IllegalActionException
container
- The proposed container.IllegalActionException
- If the proposed container is not a
TypedActor, or if the base class throws it.protected void _checkLiberalLink(ComponentRelation relation) throws IllegalActionException
relation
- The relation to link to on the inside.IllegalActionException
- If this port has no container or
the relation is not an TypedIORelation, or the port already linked
to a relation and is not a multiport, or the relation has width
not exactly one and the port is not a multiport, or the
relation is incompatible with this port, or the port is not
in the same workspace as the relation.protected void _checkLink(Relation relation) throws IllegalActionException
_checkLink
in class IOPort
relation
- The relation to link to.IllegalActionException
- If this port has no container or
the relation is not an TypedIORelation, or the port already linked
to a relation and is not a multiport, or if the relation has width
not exactly one and the port is not a multiport, or the port is
not in the same workspace as the relation.protected void _checkType(Token token) throws IllegalActionException
token
- The token to check.IllegalActionException
- If the specified token is
either incomparable to the resolved type or higher in the
type lattice.protected java.lang.String _description(int detail, int indent, int bracket) throws IllegalActionException
If the detail argument sets the bit defined by the constant TYPE, then append to the description a field of the form "type {declared declaredType resolved resolvedType}". The declared type is the type set through setTypeEquals(). If this method is not called, the declared type is BaseType.UNKNOWN. The resolved type is the type of this port. Both types are represented by the names of the corresponding tokens.
This method is read-synchronized on the workspace.
_description
in class IOPort
detail
- The level of detail.indent
- The amount of indenting.bracket
- The number of surrounding brackets (0, 1, or 2).IllegalActionException
- If thrown while getting the
description of subcomponents.