|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ptolemy.kernel.util.NamedObj ptolemy.kernel.Port ptolemy.kernel.ComponentPort ptolemy.actor.IOPort ptolemy.actor.TypedIOPort
public class TypedIOPort
An IOPort with a type. This class implements the Typeable interface. The type is represented by an instance of Type in data.type package. It can be declared by calling setTypeEquals(). If this method is not called, or called with a BaseType.UNKNOWN argument, the type of this port will be set by type resolution using the type constraints. The type constraints on this port can be specified using the methods defined in the Typeable interface.
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) |
Nested Class Summary | |
---|---|
private class |
TypedIOPort.TypeTerm
|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.Set<Inequality> |
_constraints
|
private Type |
_declaredType
|
private Type |
_resolvedType
|
private java.util.List<TypeListener> |
_typeListeners
|
private TypedIOPort.TypeTerm |
_typeTerm
|
static int |
TYPE
Indicate that the description(int) method should include information about the type of this port. |
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 | |
---|---|
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. |
Method Summary | |
---|---|
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) or null. |
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 is compatible with the resolved type of this port. |
protected java.lang.String |
_description(int detail,
int indent,
int bracket)
Return a description of the object. |
private void |
_notifyTypeListener(Type oldType,
Type newType)
|
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(). |
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 |
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. |
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 java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int TYPE
private Type _declaredType
private Type _resolvedType
private TypedIOPort.TypeTerm _typeTerm
private java.util.List<TypeListener> _typeListeners
private java.util.Set<Inequality> _constraints
Constructor Detail |
---|
public TypedIOPort()
public TypedIOPort(Workspace workspace)
workspace
- The workspace that will list the port.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.Method Detail |
---|
public void addTypeListener(TypeListener listener)
listener
- The TypeListener to add.removeTypeListener(TypeListener)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
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 send
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.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()
getType
in interface Typeable
public InequalityTerm getTypeTerm()
getTypeTerm
in interface Typeable
public boolean isTypeAcceptable()
isTypeAcceptable
in interface Typeable
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 send
NoRoomException
- If there is no room in the receiver.
IllegalActionException
- If conversion to the type of
the destination port cannot be done.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
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 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
private void _notifyTypeListener(Type oldType, Type newType)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |