Package ptolemy.actor

Class IOPort

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    TypedIOPort

    public class IOPort
    extends ComponentPort
    This class supports exchanging data between entities via message passing. It can serve as an input port, an output port, or both. If it is an input port, then it contains some number of receivers, which are responsible for receiving data from remote entities. If it is an output port, then it can send data to remote receivers.

    Its receivers are created by a director. It must therefore be contained by an actor that has a director. If it is not, then any attempt to read data or list the receivers will trigger an exception.

    If this port is at the boundary of an composite actor, then it can have both inside and outside links, with corresponding inside and outside receivers if it opaque. The inside links are to relations inside the opaque composite actor, whereas the outside links are to relations outside. If it is not specified, then a link is an outside link.

    The port has a defaultValue parameter that, by default, is empty. If this parameter is not empty, the port always has a token. The value of the port is initially specified by the defaultValue. Afterwards, the previous token of the port is remembered. The defaultValue may optionally be an array, in which case a different default value can be different for each channel. If the port is wider than the array, then only the first n channels will have default values, where n is the length of the array.

    The port has a width, which by default is constrained to be either zero or one. The width is the sum of the widths of the linked relations. A port with a width greater than one behaves as a bus interface, so if the width is w, then the port can simultaneously handle w distinct input or output channels of data.

    In general, an input port might have more than one receiver for each channel. This occurs particularly for transparent input ports, which treat the receivers of the ports linked on the inside as its own. This might also occur for opaque ports in some derived classes. Each receiver in the group is sent the same data. Thus, an input port in general will have w distinct groups of receivers, and can receive w distinct channels.

    By default, the maximum width of the port is one, so only one channel is handled. A port that allows a width greater than one is called a multiport. Calling setMultiport() with a true argument converts the port to a multiport.

    The width of the port is not set directly. It is the sum of the widths of the relations that the port is linked to on the outside. The sum of the widths of the relations linked on the inside can be more or less than the width. If it is more, then the excess inside relations will be treated as if they are unconnected. If it is less, then the excess outside relations will be treated as if they are unconnected.

    An IOPort can only link to instances of IORelation. Derived classes may further constrain links to a subclass of IORelation. To do this, they should override the protected methods _checkLink() and _checkLiberalLink() to throw an exception if their arguments are not of the appropriate type. Similarly, an IOPort can only be contained by a class derived from ComponentEntity and implementing the Actor interface. Subclasses may further constrain the containers by overriding the protected method _checkContainer().

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Edward A. Lee, Jie Liu, Neil Smyth, Lukito Muliadi, Contributor: Bert Rodiers
    Pt.AcceptedRating:
    Red (neuendor)
    Pt.ProposedRating:
    Green (eal)
    • Field Detail

      • defaultValue

        public Parameter defaultValue
        The default value of the port. By default, this parameter is empty. If this value is not empty, then the port is persistent, which means that the get methods always return a token (they never throw NoTokenException), and that hasToken(int), hasToken(int, int), and hasTokenInside(int) always return true, indicating that a token is available. To determine whether there is a new token, use hasNewToken(int) or hasNewTokenInside(int).

        The defaultValue may optionally be an array, in which case a different default value can be different for each channel. If the port is wider than the array, then only the first n channels will have default values, where n is the length of the array.

        If this port is an output port, then the persistent value is used only when retrieving a token from the inside. I.e., it will be used only if the output port belongs to an opaque composite actor.

      • CONFIGURATION

        public static final int CONFIGURATION
        Indicate that the description(int) method should include information about whether the port is an input, output, or multiport, whether it is opaque, and what is its width.
        See Also:
        Constant Field Values
      • RECEIVERS

        public static final int RECEIVERS
        Indicate that the description(int) method should include receivers contained by this port (if any).
        See Also:
        Constant Field Values
      • REMOTERECEIVERS

        public static final int REMOTERECEIVERS
        Indicate that the description(int) method should include receivers remotely connected to this port (if any).
        See Also:
        Constant Field Values
      • _constantLimit

        protected int _constantLimit
        The limit of the number of constant values to return instead of the received tokens. This is protected so that AbstractReceiver can access it.
      • _constantToken

        protected Token _constantToken
        The constant value to return instead of the received tokens. This is protected so that AbstractReceiver can access it.
      • _constantTokensSent

        protected int _constantTokensSent
        The number of constant tokens that have been sent since the last call to _setConstant(). This is protected so that AbstractReceiver can access it.
      • _hasPortEventListeners

        protected boolean _hasPortEventListeners
        Flag that is true if there are port event listeners.
      • _portEventListeners

        protected java.util.List<IOPortEventListener> _portEventListeners
        The list of IOPortEventListeners registered with this object. NOTE: Because of the way we synchronize on this object, it should never be reset to null after the first list is created.
    • Constructor Detail

      • IOPort

        public IOPort()
        Construct an IOPort with no container and no name that is neither an input nor an output.
      • IOPort

        public IOPort​(Workspace workspace)
               throws IllegalActionException
        Construct a port in the specified workspace with an empty string as a name. You can then change the name with setName(). If the workspace argument is null, then use the default workspace. The object is added to the workspace directory. Increment the version number of the workspace.
        Parameters:
        workspace - The workspace that will list the port.
        Throws:
        IllegalActionException - If thrown by the superclass or while initializing
      • IOPort

        public IOPort​(ComponentEntity container,
                      java.lang.String name)
               throws IllegalActionException,
                      NameDuplicationException
        Construct an IOPort with a containing actor and a name that is neither an input nor an output. The specified container must implement the Actor interface, or an exception will be thrown.
        Parameters:
        container - The container actor.
        name - The name of the port.
        Throws:
        IllegalActionException - If the port is not of an acceptable class for the container, or if the container does not implement the Actor interface.
        NameDuplicationException - If the name coincides with a port already in the container.
      • IOPort

        public IOPort​(ComponentEntity container,
                      java.lang.String name,
                      boolean isInput,
                      boolean isOutput)
               throws IllegalActionException,
                      NameDuplicationException
        Construct an IOPort 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 Actor 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 Actor interface.
        NameDuplicationException - If the name coincides with a port already in the container.
    • Method Detail

      • addIOPortEventListener

        public void addIOPortEventListener​(IOPortEventListener listener)
        Append a listener to the current set of port event listeners. If the listener is already in the set, it will not be added again. Note that this method is basically the same as addDebugListener in the class NamedObj.
        Parameters:
        listener - The listener to which to send token sent messages.
        See Also:
        removeIOPortEventListener(IOPortEventListener)
      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        If a communication aspect is added, removed or modified, invalidate the list of communication aspects which is read again in the preinitialize phase.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the new color attribute cannot be created.
      • broadcast

        public void broadcast​(Token token)
                       throws IllegalActionException,
                              NoRoomException
        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 putting the token into 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().

        Parameters:
        token - The token to send
        Throws:
        IllegalActionException - Not thrown in this base class.
        NoRoomException - If a send to one of the channels throws it.
      • broadcast

        public void broadcast​(Token[] tokenArray,
                              int vectorLength)
                       throws IllegalActionException,
                              NoRoomException
        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().

        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 - Not thrown in this base class.
      • broadcastClear

        public void broadcastClear()
                            throws IllegalActionException
        Set all receivers connected on the outside to have no tokens. The transfer is accomplished by calling clear() on the appropriate receivers. If there are no destination receivers, or if this is not an output port, then do nothing. Some of this method is read-synchronized on the workspace.
        Throws:
        IllegalActionException - If a receiver does not support clear().
        See Also:
        sendClear(int )
      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone this port into the specified workspace. The new port is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new port with no connections and no container.
        Overrides:
        clone in class ComponentPort
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        A new IOPort.
        Throws:
        java.lang.CloneNotSupportedException - If one or more of the attributes cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • convert

        public Token convert​(Token token)
                      throws IllegalActionException
        Convert the specified token into a token acceptable to this port. In this base class, this method simply returns the same token passed to it, performing no conversion.
        Parameters:
        token - The token to convert.
        Returns:
        The converted token.
        Throws:
        IllegalActionException - If the conversion is invalid (not thrown in this base class).
      • createReceivers

        public void createReceivers()
                             throws IllegalActionException
        Create new receivers for this port, replacing any that may previously exist, and validate any instances of Settable that this port may contain. This method should only be called on opaque ports.

        If the port is an input port, receivers are created as necessary for each relation connecting to the port from the outside. If the port is an output port, receivers are created as necessary for each relation connected to the port from the inside. Note that only composite entities will have relations connecting to ports from the inside.

        Note that it is perfectly allowable for a zero width output port to have insideReceivers. This can be used to allow a model to be embedded in a container that does not connect the port to anything.

        This method is not write-synchronized on the workspace, so the caller should be.

        Throws:
        IllegalActionException - If this port is not an opaque input port or if there is no director.
      • deepConnectedInPortList

        public java.util.List<IOPort> deepConnectedInPortList()
        Return a list of input ports connected to this port on the outside. NOTE: This method is not as useful as it might seem. In particular, it includes in the returned list input ports that are higher in the hierarchy to which this port is connected on the inside. This can be confusing because such ports cannot receive data produced by this port. To get a list of the ports that can receive data from this port, use the sinkPortList() method.
        Returns:
        A list of IOPort objects.
        See Also:
        ComponentPort.deepConnectedPortList()
      • deepConnectedInPorts

        @Deprecated
        public java.util.Enumeration deepConnectedInPorts()
        Deprecated.
        Use deepConnectedInPortList() instead.
        Deeply enumerate the ports connected to this port on the outside that are input ports. This method is deprecated and calls deepConnectedInPortList(). It is read-synchronized on the workspace.
        Returns:
        An enumeration of input IOPort objects.
        See Also:
        ComponentPort.deepConnectedPorts()
      • deepConnectedOutPortList

        public java.util.List<IOPort> deepConnectedOutPortList()
        Return a list of output ports connected to this port on the outside. NOTE: This method is not as useful as it might seem. In particular, it includes in the returned list output ports that are higher in the hierarchy to which this port is connected on the inside. This can be confusing because such ports cannot send data to this port. To get a list of the ports that can send data to this port, use the sourcePortList() method.
        Returns:
        An enumeration of IOPort objects.
        See Also:
        ComponentPort.deepConnectedPorts()
      • deepConnectedOutPorts

        @Deprecated
        public java.util.Enumeration deepConnectedOutPorts()
        Deprecated.
        Use deepConnectedInPortList() instead.
        Deeply enumerate the ports connected to this port on the outside that are output ports. This method is deprecated and calls deepConnectedInPortList(). It is read-synchronized on the workspace.
        Returns:
        An enumeration of output IOPort objects.
        See Also:
        ComponentPort.deepConnectedPorts()
      • deepGetReceivers

        public Receiver[][] deepGetReceivers()
                                      throws InvalidStateException,
                                             IllegalActionException
        If the port is an input, return the receivers deeply linked on the inside. This method is used to obtain the receivers that are to receive data at this input port. The returned value is an array of arrays in the same format as that returned by getReceivers(). The difference between this method and getReceivers() is that this method treats the port as a transparent port regardless of whether it is one. That is, the returned receivers are contained by ports connected on the inside to this port. The number of channels is the inside width of this port. If there are no relations linked on the inside, it returns an empty array. This method is used for opaque, non-atomic entities. It "sees through" the boundary of opaque ports and actors. This method is not read-synchronized on the workspace, so the caller should be.
        Returns:
        The inside receivers, or an empty receiver array if there are none.
        Throws:
        IllegalActionException - If thrown while getting the deep receivers of the relation or while getting the inside width.
        InvalidStateException - Not thrown in this base class
      • 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().

        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.

        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.
      • getChannelForReceiver

        public int getChannelForReceiver​(Receiver receiver)
                                  throws IllegalActionException
        Return the corresponding channel in this port for the given receiver. The given receiver may be contained by this port or a port that is connected to this port.
        Parameters:
        receiver - A receiver that is contained in this port or connected to another receiver contained in this port.
        Returns:
        The corresponding channel for the receiver.
        Throws:
        IllegalActionException - If the given receiver does not take part in any connections pertaining to this port.
      • getCurrentTime

        @Deprecated
        public double getCurrentTime​(int channelIndex)
                              throws IllegalActionException
        Deprecated.
        As Ptolemy II 4.1, replaced by getModelTime(int).
        Call the getModelTime(int) method and return a double representation of the model time.
        Parameters:
        channelIndex - The channel index.
        Returns:
        The current time associated with a certain channel.
        Throws:
        IllegalActionException - If the channel index is out of range or if the port is not an input port.
      • getDefaultWidth

        public int getDefaultWidth()
        Get the default width. In case there is no unique solution for a relation connected to this port the default width will be used.
        Returns:
        The default width.
        See Also:
        setDefaultWidth(int)
      • getInside

        public Token getInside​(int channelIndex)
                        throws NoTokenException,
                               IllegalActionException
        Get a token from the specified inside channel of this port. This method is usually called on the output port of a composite actor.

        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. This method is usually called only by the director of a composite actor during transferOutputs(), as atomic actors do not normally have relations connected on the inside of their ports.

        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().

        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 output port, or if the channel index is out of range.
      • getInsideReceivers

        public Receiver[][] getInsideReceivers()
        If the port is an opaque output port, return the receivers that receive data from all inside linked relations. This method is used for opaque, non-atomic entities, which have opaque ports with inside links. Normally, those inside links are not visible. This method permits a director to transfer data across an opaque boundary by transferring it from the inside receivers to whatever receivers this might be connected to on the outside. The returned value is an an array of arrays in the same format as that returned by getReceivers(). This method is read-synchronized on the workspace.
        Returns:
        The local inside receivers, or an empty array if there are none.
        See Also:
        getInside(int)
      • getIOPortEventListeners

        public java.util.List<IOPortEventListener> getIOPortEventListeners()
        Get the listeners for IOPortEvents.
        Returns:
        The a copy of the list of listeners for IOPortEvents, if any. Otherwise an empty list.
      • getRelationIndex

        public static int getRelationIndex​(IOPort port,
                                           Relation relation,
                                           boolean isOutsideRelation)
        Retrieve the index of the relation at the port. In case the relation is not connected with this port -1 will be returned.
        Parameters:
        port - The port.
        relation - The relation.
        isOutsideRelation - A flag that specifies that the relation is an outside relation of the port.
        Returns:
        The index of the relation at the port.
      • getModelTime

        public Time getModelTime​(int channelIndex)
                          throws IllegalActionException
        Return the current time associated with a certain channel. In most domains, this is just the current time of the director. However, in some domains, the current time is a per-channel concept. If the channel has a token to be read (i.e. hasToken() returns true), then the current time is the time associated with that token. If there is no token to be read, then the current time is the time of most recently read token. If no token has been previously read, then the current time is 0.0. Notice that this means that an actor accessing time should do things in the following order:
             if (hasToken(n)) {
                double time = port.getCurrentTime(n);
                Token token = port.get(n);
             }
          
        I.e., getCurrentTime() is called before get(). Currently, only the DT domain uses this per-channel time feature.
        Parameters:
        channelIndex - The channel index.
        Returns:
        The current time associated with a certain channel.
        Throws:
        IllegalActionException - If the channel index is out of range or if the port is not an input port.
      • getModelTime

        public Time getModelTime​(int channelIndex,
                                 boolean inside)
                          throws IllegalActionException
        Return the current time associated with a certain channel. In most domains, this is just the current time of the director. However, in some domains, the current time is a per-channel concept. If the channel has a token to be read (i.e. hasToken() returns true), then the current time is the time associated with that token. If there is no token to be read, then the current time is the time of most recently read token. If no token has been previously read, then the current time is 0.0. Notice that this means that an actor accessing time should do things in the following order:
             if (hasToken(n)) {
                double time = port.getCurrentTime(n);
                Token token = port.get(n);
             }
          
        I.e., getCurrentTime() is called before get(). Currently, only the DT domain uses this per-channel time feature.
        Parameters:
        channelIndex - The channel index.
        inside - True for an inside channel.
        Returns:
        The current time associated with a certain channel.
        Throws:
        IllegalActionException - If the channel index is out of range or if the port is not an input port.
      • getCommunicationAspects

        public java.util.List<CommunicationAspect> getCommunicationAspects()
                                                                    throws IllegalActionException
        Return the list of communication aspects in this port. A communication aspect is a Parameter whose value is an ObjectToken that references an object that implements the CommunicationAspect interface. Update the sequence number of communication aspects.
        Returns:
        The list of communication aspects.
        Throws:
        IllegalActionException - Thrown if the token of the parameter containing the communication aspect object cannot be retrieved.
      • getReceivers

        public Receiver[][] getReceivers()
        If the port is an input, return the receivers that receive data from all linked relations. For an input port, the returned value is an array of arrays. The first index specifies the channel number. The second index specifies the receiver number within the group of receivers that get copies from the same channel.

        For a transparent port (a port of a non-opaque entity), this method returns receivers in ports connected to this port on the inside. For an opaque port, the receivers returned are contained directly by this port.

        The number of channels (number of groups) is the width of the port.

        For each channel, there may be any number of receivers in the group. The individual receivers are selected using the second index of the returned array of arrays. If there are no receivers in the group, then the channel is represented by null. I.e., if the returned array of arrays is x and the channel number is c, then x[c] is null. Otherwise, it is an array, where the size of the array is the number of receivers in the group. If the port is opaque, then the group size is one, so only x[c][0] is defined. If the port is transparent, the group size is arbitrary.

        For an opaque port, this method creates receivers by calling _newReceiver() if there are no receivers or the number of receivers does not match the width of the port. In the latter case, previous receivers are lost, together with any data they may contain.

        This method is read-synchronized on the workspace. If its cached list of local receivers is not valid, however, then it acquires write synchronization on the workspace to reconstruct it.

        Returns:
        The local receivers, or an empty array if there are none.
      • getReceivers

        public Receiver[][] getReceivers​(IORelation relation)
                                  throws IllegalActionException
        If the port is an input, return receivers that handle incoming channels from the specified relation. If the port is an opaque output and the relation is inside linked, return the receivers that handle incoming channels from the inside. Since the port may be linked multiple times to the specified relation, this method only returns the relations correspond to the first occurrence. The returned value is an array of arrays of the same form as that returned by getReceivers() with no arguments. Note that a single occurrence of a relation may represent multiple channels because it may be a bus. If there are no matching receivers, then return an empty array.

        This method is read-synchronized on the workspace.

        Parameters:
        relation - Relations that are linked on the outside or inside.
        Returns:
        The local receivers.
        Throws:
        IllegalActionException - If the relation is not linked from the outside, or if there is no director.
      • getReceivers

        public Receiver[][] getReceivers​(IORelation relation,
                                         int occurrence)
                                  throws IllegalActionException
        If the port is an input, return receivers that handle incoming channels from the specified relation. If the port is an opaque output and the relation is inside linked, return the receivers that handle incoming channels from the inside. Since the port may be linked multiple times to the specified relation, the occurrences argument specifies which of the links we wish to examine. The returned value is an array of arrays of the same form as that returned by getReceivers() with no arguments. Note that a single occurrence of a relation may represent multiple channels because it may be a bus. If there are no matching receivers, then return an empty array.

        This method is read-synchronized on the workspace.

        Parameters:
        relation - Relations that are linked on the outside or inside.
        occurrence - The occurrence number that we are interested in, starting at 0.
        Returns:
        The local receivers, or an empty array if there are none.
        Throws:
        IllegalActionException - If the relation is not linked from the outside.
      • getRemoteReceivers

        public Receiver[][] getRemoteReceivers()
                                        throws IllegalActionException
        If the port is an output, return the remote receivers that can receive from the port. For an output port, the returned value is an array of arrays of the same form as that returned by getReceivers() with no arguments. The length of the array is the width of the port (the number of channels). It is an array of arrays, each of which represents a group of receivers that receive data from the same channel.

        This method may have the effect of creating new receivers in the remote input ports, if they do not already have the right number of receivers. In this case, previous receivers are lost, together with any data they may contain.

        This method is read-synchronized on the workspace.

        Returns:
        The receivers for output data, or an empty array if there are none.
        Throws:
        IllegalActionException - If thrown while getting the width of this port, getting the deep receives of a relation or getting the width of a relation.
      • getRemoteReceivers

        public Receiver[][] getRemoteReceivers​(IORelation relation)
                                        throws IllegalActionException
        If this port is an output, return the remote receivers that can receive data from this port through the specified relation or any relation in its relation group. The relation or one in its relation group should be linked to the port from the inside, otherwise an exception is thrown. For an output port, the returned value is an array of arrays of the same form as that returned by getReceivers() with no arguments.

        This method may have the effect of creating new receivers in the remote input ports, if they do not already have the right number of receivers. In this case, previous receivers are lost, together with any data they may contain.

        This method is read-synchronized on the workspace.

        Parameters:
        relation - The specified relation from which the remote receivers can receive data.
        Returns:
        The receivers for output data, or an empty array if there are none.
        Throws:
        IllegalActionException - If the IORelation is not linked to the port from the inside.
      • 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.
        Returns:
        The width of the port.
        Throws:
        IllegalActionException - If thrown while calling _getWidth()
        See Also:
        numberOfSinks(), numberOfSources()
      • getWidthFromConstraints

        public int getWidthFromConstraints()
        Get the width from the constraints put on the width of this port if the width is fully determined. If it is not possible to determine the width yet (for example because dependent relations also don't have their width inferred), -1 is returned
        Returns:
        The width.
      • getWidthInside

        public int getWidthInside()
                           throws IllegalActionException
        Return the inside width of this port. The inside width is the sum of the widths of the relations that the port is linked to on the inside. This method is read-synchronized on the workspace. This method will trigger the width inference algorithm if necessary.
        Returns:
        The width of the inside of the port.
        Throws:
        IllegalActionException - If thrown while getting the width of the relations or while creating receivers.
      • hasNewToken

        public boolean hasNewToken​(int channelIndex)
                            throws IllegalActionException
        Return true if the specified channel has a new token to deliver via the get() method. This differs from hasToken(int) in that it does not return true just because the port is persistent or the most recently received input was a SmoothToken. 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().
        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.
      • hasNewTokenInside

        public boolean hasNewTokenInside​(int channelIndex)
                                  throws IllegalActionException
        Return true if the specified channel has a token to deliver via the getInside() method. This differs from hasTokenInside(int) in that it does not return true just because the port is persistent or the most recently received input was a SmoothToken. If this port is not an output, or if the channel index is out of range, then throw an exception. Note that this does not report any tokens in receivers of an input port.
        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 output port, or if the channel index is out of range.
      • hasRoom

        public boolean hasRoom​(int channelIndex)
                        throws IllegalActionException
        Return true if the specified channel can accept a token via the put() method. If this port is not an output, or the channel index is out of range, then throw IllegalActionException. If there are multiple receivers in the group associated with the channel, then return true only if all the receivers can accept a token.
        Parameters:
        channelIndex - The channel index.
        Returns:
        True if there is room for a token in the channel.
        Throws:
        IllegalActionException - If the receivers do not support this query, if this is not an output port, or if the channel index is out of range.
      • hasRoomInside

        public boolean hasRoomInside​(int channelIndex)
                              throws IllegalActionException
        Return true if the specified channel can accept a token via the putInside() method. If this port is not an input, or the channel index is out of range, then throw IllegalActionException. If there are multiple receivers in the group associated with the channel, then return true only if all the receivers can accept a token.
        Parameters:
        channelIndex - The channel index.
        Returns:
        True if there is room for a token in the channel.
        Throws:
        IllegalActionException - If the receivers do not support this query, if this is not an input port, or if the channel index is out of range.
      • hasToken

        public boolean hasToken​(int channelIndex)
                         throws IllegalActionException
        Return true if the port is persistent (see defaultValue), or if the most recent input was an SmoothToken, or 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().
        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().
        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.
      • hasTokenInside

        public boolean hasTokenInside​(int channelIndex)
                               throws IllegalActionException
        Return true if the port is persisent or the specified channel has a token to deliver via the getInside() method. If this port is not an output, or if the channel index is out of range, then throw an exception. Note that this does not report any tokens in receivers of an input port.
        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 output port, or if the channel index is out of range.
      • hasWidthConstraints

        public boolean hasWidthConstraints()
        Return whether there are constraints on the width of this port. There are constraints in case the method setWidthEquals has been called.
        Returns:
        True when there are constraints on the width.
        See Also:
        setWidthEquals(Parameter), setWidthEquals(IOPort, boolean)
      • insertLink

        public void insertLink​(int index,
                               Relation relation)
                        throws IllegalActionException
        Override the base class to invalidate the schedule and resolved types of the director of the container, if there is one, in addition to what the base class does.
        Overrides:
        insertLink in class ComponentPort
        Parameters:
        index - The index at which to insert the link.
        relation - The relation to link to this port.
        Throws:
        IllegalActionException - If the link would cross levels of the hierarchy, or the relation is incompatible, or the port has no container, or the port is not in the same workspace as the relation, or if this port is not a multiport and the index is greater than zero or if another link already exists.
      • insideSinkPortList

        public java.util.List<IOPort> insideSinkPortList()
        Return a list of the ports that may accept data from this port when it sends on the inside. In this base class, this includes both input ports and opaque output ports that are connected on the inside to this port, which are the ports that will receive data from this one if data is sent on the inside. However, derived classes are free to return ports on this list that may receive data from this port, even if they are not actually currently connected. The wireless domain, for example, takes advantage of this and includes ports on the inside that share the same channel. This port must be an opaque input port, otherwise return an empty list.
        Returns:
        A list of IOPort objects.
        See Also:
        deepGetReceivers()
      • insideSourcePortList

        public java.util.List<IOPort> insideSourcePortList()
        Return a list of the ports that can send data to this port from the inside. This includes both output ports and opaque input ports that are connected on the inside to this port. These are the ports that will send data from this one from the inside. However, derived classes are free to return ports on this list that may send data to this port, even if they are not actually currently connected. The wireless domain, for example, takes advantage of this and includes ports on the inside that share the same channel. This port must be an opaque output port, otherwise return an empty list.
        Returns:
        A list of IOPort objects.
      • invalidateCommunicationAspects

        public void invalidateCommunicationAspects()
        Invalidate the communication aspect list.
      • isInput

        public boolean isInput()
        Return true if the port is an input. The port is an input if either setInput() has been called with a true argument, or it is connected on the inside to an input port, or if it is connected on the inside to the inside of an output port. In other words, it is an input if data can be put directly into it or sent through it to an input. This method is read-synchronized on the workspace.
        Returns:
        True if the port is an input.
      • isInsideConnected

        public boolean isInsideConnected()
        Return whether the port has relations connected on the inside.
        Returns:
        True when a relation != null is connected on the inside.
      • isKnown

        public boolean isKnown()
                        throws IllegalActionException
        Return true if all channels of this port have known state; that is, the tokens on each channel are known, or each channel is known not to have any tokens.

        This method supports domains, such as SR, which have fixed-point semantics. In such domains, an iteration of a model starts with the state of all channels unknown, and the iteration concludes when the state of all channels is known.

        Returns:
        True if it is known whether there is a token in each channel.
        Throws:
        IllegalActionException - If the receivers do not support this query, or if there is no director, and hence no receivers.
        See Also:
        isKnown(int), isKnownInside(int)
      • isKnown

        public boolean isKnown​(int channelIndex)
                        throws IllegalActionException
        Return true if the specified channel has known state; that is, the tokens on this channel are known, or this channel is known not to have any tokens. If the channel index is out of range, then throw an exception. If the port is an input and an output, then both the receivers in this port (for the input) and the remote receivers (for the output) must be known to return true. If the port is neither an input nor an output, then return true.

        This method supports domains, such as SR, which have fixed-point semantics. In such domains, an iteration of a model starts with the state of all channels unknown, and the iteration concludes when the state of all channels is known.

        Parameters:
        channelIndex - The channel index.
        Returns:
        True if it is known whether 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.
        See Also:
        isKnown(), *
      • isKnownInside

        public boolean isKnownInside​(int channelIndex)
                              throws IllegalActionException
        Return true if the specified inside channel has known state; that is, the tokens on this channel are known, or this channel is known not to have any tokens. If the channel index is out of range, then throw an exception. If the port is an input and an output, then both the receivers in this port (for the input) and the remote receivers (for the output) must be known to return true. If the port is neither an input nor an output, then return true.

        This method supports domains, such as SR, which have fixed-point semantics. In such domains, an iteration of a model starts with the state of all channels unknown, and the iteration concludes when the state of all channels is known.

        Parameters:
        channelIndex - The channel index.
        Returns:
        True if it is known whether 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, or if the inside channel index is out of range.
      • isMultiport

        public boolean isMultiport()
        Return true if the port is a multiport. The port is a multiport if setMultiport() has been called with a true argument.
        Returns:
        True if the port is a multiport.
      • isOutput

        public boolean isOutput()
        Return true if the port is an output. The port is an output if either setOutput() has been called with a true argument, or it is connected on the inside to an output port, or it is connected on the inside to the inside of an input port. This method is read-synchronized on the workspace.
        Returns:
        True if the port is an output.
      • isOutsideConnected

        public boolean isOutsideConnected()
        Return whether the port has relations connected on the outside.
        Returns:
        True when a relation != null is connected on the outside.
      • liberalLink

        public void liberalLink​(ComponentRelation relation)
                         throws IllegalActionException
        Override the base class to invalidate the schedule and resolved types of the director of the container, if there is one, in addition to what the base class does.
        Overrides:
        liberalLink in class ComponentPort
        Parameters:
        relation - The relation to link to.
        Throws:
        IllegalActionException - If the relation does not share the same workspace, or the port has no container.
      • link

        public void link​(Relation relation)
                  throws IllegalActionException
        Override the base class to invalidate the schedule and resolved types of the director of the container, if there is one, in addition to what the base class does.
        Overrides:
        link in class ComponentPort
        Parameters:
        relation - The relation to link to.
        Throws:
        IllegalActionException - If the link crosses levels of the hierarchy, or the port has no container, or the relation is not an instance of IORelation.
      • numberOfSinks

        public int numberOfSinks()
        Return the number of sink ports that may receive data from this one. This is the number of ports returned by sinkPortList(), but this method is more efficient to call than that one if you only need to know how many ports there are (because the result is cached). This method is typically used to determine whether an output port is connected (deeply) to any input port that can consume its data. Note that it is not sufficient to call getWidth() to determine this; it is possible for getWidth() to return a number greater than zero when this method returns zero. In particular, if this port is connected to the inside of an opaque output port, but that opaque output port is not connected on the outside, then this method will return zero, but getWidth() will return the width of the relation mediating the connection.
        Returns:
        The number of ports that can receive data from this one.
        See Also:
        sinkPortList(), numberOfSources(), getWidth()
      • numberOfSources

        public int numberOfSources()
        Return the number of source ports that may send data to this one. This is no greater than number of ports returned by sourcePortList(). This method is typically used to determine whether an input port is connected (deeply) to any output port that can supply it with data. Note that it is not sufficient to call getWidth() to determine this; it is possible for getWidth() to return a number greater than zero when this method returns zero. In particular, if this port is connected to the inside of an opaque input port, but that opaque input port is not connected on the outside, then this method will return zero, but getWidth() will return the width of the relation mediating the connection.
        Returns:
        The number of ports that can send data to this one.
        See Also:
        sourcePortList(), numberOfSinks(), getWidth()
      • removeIOPortEventListener

        public void removeIOPortEventListener​(IOPortEventListener listener)
        Unregister a token sent listener. If the specified listener has not been previously registered, then do nothing. Note that this method is basically the same as removeDebugListener in the class NamedObj.
        Parameters:
        listener - The listener to remove from the list of listeners to which token sent messages are sent.
        See Also:
        addIOPortEventListener(IOPortEventListener)
      • send

        public void send​(int channelIndex,
                         Token token)
                  throws IllegalActionException,
                         NoRoomException
        Send the specified token to all receivers connected to the specified channel. 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 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.

        If a null token is specified, this is interpreted as an assertion that no token is being sent. For some domains, specifically those that queue tokens such as PN and SDF, this has no effect. For others, specifically those that have a well-defined notion of "absent" inputs such as SR, modal, and Continuous, sending a null token corresponds to asserting that the inputs of destination actors will be absent in this round.

        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.

        Parameters:
        channelIndex - The index of the channel, from 0 to width-1
        token - The token to send, or null to send no token.
        Throws:
        NoRoomException - If there is no room in the receiver.
        IllegalActionException - Not thrown in this base class.
      • send

        public void send​(int channelIndex,
                         Token[] tokenArray,
                         int vectorLength)
                  throws IllegalActionException,
                         NoRoomException
        Send the specified portion of a token array to all receivers connected to the specified channel. 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.

        Parameters:
        channelIndex - The index of the channel, from 0 to width-1
        tokenArray - The token array to send
        vectorLength - The number of elements of of the token array to send.
        Throws:
        NoRoomException - If there is no room in the receiver.
        IllegalActionException - Not thrown in this base class.
      • sendClear

        public void sendClear​(int channelIndex)
                       throws IllegalActionException
        Set all destination receivers connected via the specified to channel to have no token. The transfer is accomplished by calling clear() on the appropriate receivers. If there are no destination receivers on the specified channel, or if this is not an output port, or if the array index is out of bounds, then do nothing. Some of this method is read-synchronized on the workspace.
        Parameters:
        channelIndex - The index of the channel, from 0 to width-1
        Throws:
        IllegalActionException - If a receiver does not support clear().
        See Also:
        broadcastClear(), sendClearInside(int)
      • sendClearInside

        public void sendClearInside​(int channelIndex)
                             throws IllegalActionException
        Set all destination receivers connected on the inside via the specified to channel to have no token. This is accomplished by calling clear() on the appropriate receivers. If there are no destination inside receivers on the specified channel, or if the channel index is out of bounds, then do nothing. Some of this method is read-synchronized on the workspace.
        Parameters:
        channelIndex - The index of the channel, from 0 to insideWidth-1.
        Throws:
        IllegalActionException - If a receiver does not support clear().
        See Also:
        sendClear(int)
      • sendInside

        public void sendInside​(int channelIndex,
                               Token token)
                        throws IllegalActionException,
                               NoRoomException
        Send the specified token to all receivers connected to the specified inside channel of this port. 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 on the inside, or receivers have not been created in the remote port, or the channel index is out of range, or the port is not an input port, then just silently return. This behavior makes it easy to leave external input ports of a composite unconnected when you are not interested in the received values. The transfer is accomplished by calling the put() method of the inside remote receivers. If the port is not connected to anything, or receivers have not been created in the remote port, then just return. This method is normally called only by the transferInputs method of directors of composite actors, as AtomicActors do not usually have any relations on the inside of their ports.

        If a null token is specified, this is interpreted as an assertion that no token is being sent. For some domains, specifically those that queue tokens such as PN and SDF, this has no effect. For others, specifically those that have a well-defined notion of "absent" inputs such as SR, modal, and Continuous, sending a null token corresponds to asserting that the inputs of destination actors will be absent in this round.

        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.

        Parameters:
        channelIndex - The index of the channel, from 0 to width-1
        token - The token to send, or null to send no token.
        Throws:
        NoRoomException - If there is no room in the receiver.
        IllegalActionException - Not thrown in this base class.
      • setContainer

        public void setContainer​(Entity container)
                          throws IllegalActionException,
                                 NameDuplicationException
        Override the base class to ensure that the proposed container implements the Actor interface (the base class ensures that the container is an instance of ComponentEntity) or null. A null argument will remove the port from the container. This method invalidates the schedule and type resolution of the director of the container, if there is one.
        Overrides:
        setContainer in class ComponentPort
        Parameters:
        container - The proposed container.
        Throws:
        IllegalActionException - If the proposed container is not a ComponentEntity, doesn't implement Actor, or has no name, or the port and container are not in the same workspace. Or it's not null
        NameDuplicationException - If the container already has a port with the name of this port.
        See Also:
        Port.getContainer(), Port._checkContainer(Entity)
      • setDefaultWidth

        public void setDefaultWidth​(int defaultWidth)
        Set the default width. In case there is no unique solution for a relation connected to this port the default width will be used. If the default width is not set, the value will be -1 which corresponds to no default width.
        Parameters:
        defaultWidth - The default width.
        See Also:
        getDefaultWidth()
      • setInput

        public void setInput​(boolean isInput)
                      throws IllegalActionException
        If the argument is true, make the port an input port. If the argument is false, make the port not an input port. If this is never called, and setOutput() is never called, and the port is a transparent port of a composite actor, then the input/output status will be inferred from the connection. This method invalidates the schedule and resolved types of the director of the container, if there is one. It is write-synchronized on the workspace, and increments the version of the workspace.
        Parameters:
        isInput - True to make the port an input.
        Throws:
        IllegalActionException - If changing the port status is not permitted (not thrown in this base class).
      • setMultiport

        public void setMultiport​(boolean isMultiport)
                          throws IllegalActionException
        If the argument is true, make the port a multiport. That is, make it capable of linking with multiple IORelations, or with IORelations that have width greater than one. If the argument is false, allow only links with a single IORelation of width one. This method invalidates the schedule and resolved types of the director of the container, if there is one. It is write-synchronized on the workspace.
        Parameters:
        isMultiport - True to make the port a multiport.
        Throws:
        IllegalActionException - If changing the port status is not permitted (not thrown in this base class).
      • setOutput

        public void setOutput​(boolean isOutput)
                       throws IllegalActionException
        If the argument is true, make the port an output port. If the argument is false, make the port not an output port. If this is never called, and setInput() is never called, and the port is a transparent port of a composite actor, then the input/output status will be inferred from the connection. This method invalidates the schedule and resolved types of the director of the container, if there is one. It is write-synchronized on the workspace, and increments the version of the workspace.
        Parameters:
        isOutput - True to make the port an output.
        Throws:
        IllegalActionException - If changing the port status is not permitted (not thrown in this base class).
      • setWidthEquals

        public void setWidthEquals​(Parameter parameter)
        Constrain the width of this port to be equal to the parameter.

        Actors that call this method should have a clone() method that repeats the width constraints that were specified in the constructor.

        Parameters:
        parameter - A parameter.
      • setWidthEquals

        public void setWidthEquals​(IOPort port,
                                   boolean bidirectional)
        Constrain the width of this port to be equal to the width of the IOPort port. If bidirectional equals true, the width of port can also be inferred from the width of this.

        Actors that call this method should have a clone() method that repeats the width constraints that were specified in the constructor.

        Parameters:
        port - A port.
        bidirectional - A flag that specifies whether the constraint work in two directions.
      • sinkPortList

        public java.util.List<IOPort> sinkPortList()
        Return a list of the ports that may accept data from this port when it sends on the outside. This includes opaque input ports that are connected on the outside to this port and opaque output ports that are connected on the inside to this one. These are the ports that will receive data from this one if data is sent on the outside. However, derived classes are free to return ports on this list that may receive data from this port, even if they are not actually currently connected. The wireless domain, for example, takes advantage of this and includes ports on the outside that share the same channel.
        Returns:
        A list of IOPort objects.
        See Also:
        getRemoteReceivers()
      • sourcePortList

        public java.util.List<IOPort> sourcePortList()
        Return a list of ports that may send data to this port from the outside. This includes all opaque output ports that are connected on the outside to this port, and opaque input ports that are connected on the inside to this port. These are the ports that will send data to this one. However, derived classes are free to return ports on this list that may send data to this port, even if they are not actually currently connected. The wireless domain, for example, takes advantage of this and includes ports on the outside that share the same channel.
        Returns:
        A list of IOPort objects, or an empty list if there are none.
      • transferInputs

        @Deprecated
        public boolean transferInputs()
                               throws IllegalActionException
        Deprecated.
        Domains should use sendInside directly to implement their transferInputs method.
        Transfer data from this port to the ports it is connected to on the inside. This port must be an opaque input port. If any channel of the this port has no data, then that channel is ignored. This method will transfer exactly one token on each input channel that has at least one token available.
        Returns:
        True if at least one data token is transferred.
        Throws:
        IllegalActionException - If this port is not an opaque input port.
      • transferOutputs

        @Deprecated
        public boolean transferOutputs()
                                throws IllegalActionException
        Deprecated.
        domains should use getInside directly to implement their transferOutputs method.
        Transfer data from this port to the ports it is connected to on the outside. This port must be an opaque output port. If any channel of this port has no data, then that channel is ignored. This method will transfer exactly one token on each output channel that has at least one token available.
        Returns:
        True if at least one data token is transferred.
        Throws:
        IllegalActionException - If the port is not an opaque output port.
      • unlink

        public void unlink​(int index)
        Unlink whatever relation is currently linked at the specified index number. If there is no such relation, do nothing. If a link is removed, then any links at higher index numbers will have their index numbers decremented by one. If there is a container, notify it by calling connectionsChanged(). Invalidate the schedule and resolved types of the director of the container, if there is one. This method is write-synchronized on the workspace and increments its version number.
        Overrides:
        unlink in class Port
        Parameters:
        index - The index number of the link to remove.
      • unlink

        public void unlink​(Relation relation)
        Unlink the specified Relation. The receivers associated with this relation, and any data they contain, are lost. If the Relation is not linked to this port, do nothing. If the relation is linked more than once, then unlink all occurrences. Invalidate the schedule and resolved types of the director of the container, if there is one. Invalidate the schedule and resolved types of the director of the container, if there is one. This method is write-synchronized on the workspace.
        Overrides:
        unlink in class ComponentPort
        Parameters:
        relation - The relation to unlink.
      • unlinkAll

        public void unlinkAll()
        Unlink all relations that are linked on the outside. This method is write-synchronized on the workspace.
        Overrides:
        unlinkAll in class ComponentPort
      • unlinkAllInside

        public void unlinkAllInside()
        Unlink all relations that are linked on the inside. This method is write-synchronized on the workspace.
        Overrides:
        unlinkAllInside in class ComponentPort
      • unlinkInside

        public void unlinkInside​(int index)
        Unlink whatever relation is currently linked on the inside with the specified index number. If the relation is not linked to this port on the inside, do nothing. If a link is removed, then any links at higher index numbers will have their index numbers decremented by one. If there is a container, notify it by calling connectionsChanged(). This method is write-synchronized on the workspace and increments its version number.
        Overrides:
        unlinkInside in class ComponentPort
        Parameters:
        index - The index number of the link to remove.
      • unlinkInside

        public void unlinkInside​(Relation relation)
        Unlink the specified Relation on the inside. The receivers associated with this relation, and any data they contain, are lost. If the Relation is not linked to this port, do nothing. If the relation is linked more than once, then unlink all occurrences. This method is write-synchronized on the workspace.
        Overrides:
        unlinkInside in class ComponentPort
        Parameters:
        relation - The relation to unlink.
      • _checkLiberalLink

        protected void _checkLiberalLink​(Relation relation)
                                  throws IllegalActionException
        Override parent method to ensure compatibility of the relation and validity of the width of the port. If this port is not a multiport, then the width of the relation is required to be specified to be one. This method allows level-crossing links. This method is not synchronized on the workspace, so the caller should be.
        Overrides:
        _checkLiberalLink in class ComponentPort
        Parameters:
        relation - The relation to link to on the inside.
        Throws:
        IllegalActionException - If this port has no container or the relation is not an IORelation, 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.
      • _checkLink

        protected void _checkLink​(Relation relation)
                           throws IllegalActionException
        Override parent method to ensure compatibility of the relation and validity of the width of the port. If this port is not a multiport, then the width of the relation is required to be specified to be one. This method is not synchronized on the workspace, so the caller should be.
        Overrides:
        _checkLink in class ComponentPort
        Parameters:
        relation - The relation to link to.
        Throws:
        IllegalActionException - If this port has no container or the relation is not an IORelation, 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.
      • _description

        protected java.lang.String _description​(int detail,
                                                int indent,
                                                int bracket)
                                         throws IllegalActionException
        Return a description of the object. The level of detail depends on the argument, which is an or-ing of the static final constants defined in the NamedObj class and in this class. Lines are indented according to to the level argument using the protected method _getIndentPrefix(). Zero, one or two brackets can be specified to surround the returned description. If one is specified it is the leading bracket. This is used by derived classes that will append to the description. Those derived classes are responsible for the closing bracket. An argument other than 0, 1, or 2 is taken to be equivalent to 0.

        If the detail argument sets the bit defined by the constant CONFIGURATION, then append to the description a field containing any subset of the words "input", "output", "multiport", and "opaque", separated by spaces, plus a subfield of the form "{width integer}", where the integer is the width of the port. The field keyword is "configuration".

        If the detail argument sets the bit defined by the constant RECEIVERS, then append to the description a field containing the receivers contained by this port. The keyword is "receivers" and the format is like the Receivers array, an array of groups, with each group receiving from a channel. Each group is a list of receiver descriptions (it may also be empty). If the detail argument sets the bit defined by the constant REMOTERECEIVERS, then also append to the description a field containing the remote receivers connected to this port. This method is read-synchronized on the workspace.

        Overrides:
        _description in class ComponentPort
        Parameters:
        detail - The level of detail.
        indent - The amount of indenting.
        bracket - The number of surrounding brackets (0, 1, or 2).
        Returns:
        A description of the object.
        Throws:
        IllegalActionException - If thrown while getting the description of subcomponents.
      • _exportMoMLContents

        protected void _exportMoMLContents​(java.io.Writer output,
                                           int depth)
                                    throws java.io.IOException
        Write a MoML description of the contents of this object, which in this class is the attributes plus possibly a special attribute to indicate whether the port is a multiport. This method is called by _exportMoML(). If there are attributes, then each attribute description is indented according to the specified depth and terminated with a newline character.
        Overrides:
        _exportMoMLContents in class NamedObj
        Parameters:
        output - The output stream to write to.
        depth - The depth in the hierarchy, to determine indenting.
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        NamedObj.exportMoML(Writer, int)
      • _getInsideWidth

        protected int _getInsideWidth​(IORelation except)
                               throws IllegalActionException
        Return the sums of the widths of the relations linked on the inside, except the specified relation. If any of these relations has not had its width specified, throw an exception. This is used by IORelation to infer the width of a bus with unspecified width and to determine whether more than one relation with unspecified width is linked on the inside, and by the liberalLink() method to check validity of the link. If the argument is null, all relations linked on the inside are checked. This method is not read-synchronized on the workspace, so the caller should be. This method ignores the relations for which the width still has to be inferred.
        Parameters:
        except - The relation to exclude.
        Returns:
        The sums of the width of the relations linked on the inside, except for the specified port.
        Throws:
        IllegalActionException - If thrown while checking if a relation needs width inference, while getting the width of the relation, while checking if the width or a relation is fixed.
      • _getOutsideWidth

        protected int _getOutsideWidth​(IORelation except)
                                throws IllegalActionException
        Return the sums of the widths of the relations linked on the outside, except the specified relation. If any of these relations has not had its width specified, throw an exception. This is used by IORelation to infer the width of a bus with unspecified width and to determine whether more than one relation with unspecified width is linked on the outside, and by the liberalLink() method to check validity of the link. If the argument is null, all relations linked on the inside are checked. This method is not read-synchronized on the workspace, so the caller should be. This method ignores the relations for which the width still has to be inferred.
        Parameters:
        except - The relation to exclude.
        Returns:
        The sums of the width of the relations linked on the outside, except for the specified port.
        Throws:
        IllegalActionException - If thrown while checking if a relation needs width inference, while getting the width of the relation, while checking if the width or a relation is fixed.
      • _getReceiversLinkedToGroup

        protected Receiver[][] _getReceiversLinkedToGroup​(IORelation relation,
                                                          int occurrence)
                                                   throws IllegalActionException
        If the port is an input, return receivers that handle incoming channels from the specified relation or any relation in its relation group. If the port is an opaque output and the relation is inside linked, return the receivers that handle incoming channels from the inside. Since the port may be linked multiple times to the specified relation, the occurrences argument specifies which of the links we wish to examine. The returned value is an array of arrays of the same form as that returned by getReceivers() with no arguments. Note that a single occurrence of a relation may represent multiple channels because it may be a bus. If there are no matching receivers, then return an empty array.

        This method handles relation groups. That is, given any relation in a relation group, it returns the combined receivers of all the relations in the relation group, in the order as returned by the getRelationGroup() method of Receiver.

        This method is read-synchronized on the workspace.

        Parameters:
        relation - Relations that are linked on the outside or inside.
        occurrence - The occurrence number that we are interested in, starting at 0.
        Returns:
        The local receivers, or an empty array if there are none.
        Throws:
        IllegalActionException - If the relation is not linked from the outside.
      • _newInsideReceiver

        protected Receiver _newInsideReceiver()
                                       throws IllegalActionException
        Create a new receiver compatible with the local director. This is done by asking the local director of the container for a new receiver, and then setting its container to this port. This allows actors to work across several domains, since often the only domain-specific part of of an actor is its receivers. Derived classes may choose to handle this directly, creating whatever specific type of receiver they want. This method is not read-synchronized on the workspace, so the caller should be.

        The returned receiver is either the new receiver, or another receiver wrapping it as specified in _wrapReceiver(Receiver, int).

        Returns:
        A new receiver.
        Throws:
        IllegalActionException - If the port has no container, or the container is unable to return a new receiver (for example if it has no local director).
      • _newInsideReceiver

        protected Receiver _newInsideReceiver​(int channel)
                                       throws IllegalActionException
        Create a new receiver compatible with the local director. This is done by asking the local director of the container for a new receiver, and then setting its container to this port. This allows actors to work across several domains, since often the only domain-specific part of of an actor is its receivers. Derived classes may choose to handle this directly, creating whatever specific type of receiver they want. This method is not read-synchronized on the workspace, so the caller should be.

        The returned receiver is either the new receiver, or another receiver wrapping it as specified in _wrapReceiver(Receiver, int).

        Parameters:
        channel - Used to determine source port.
        Returns:
        A new receiver.
        Throws:
        IllegalActionException - If the port has no container, or the container is unable to return a new receiver (for example if it has no local director).
      • _newReceiver

        protected Receiver _newReceiver()
                                 throws IllegalActionException
        Create a new receiver compatible with the executive director. This is done by asking the containing actor for a new receiver, and then setting its container to this port. This allows actors to work across several domains, since often the only domain-specific part of of an actor is its receivers. Derived classes may choose to handle this directly, creating whatever specific type of receiver they want. This method is not write-synchronized on the workspace, so the caller should be.

        The returned receiver is either the new receiver, or another receiver wrapping it as specified in _wrapReceiver(Receiver, int).

        Returns:
        A new receiver.
        Throws:
        IllegalActionException - If the port has no container, or the container is unable to return a new receiver (for example if it has no executive director).
      • _newReceiver

        protected Receiver _newReceiver​(int channel)
                                 throws IllegalActionException
        Create a new receiver compatible with the executive director. This is done by asking the containing actor for a new receiver, and then setting its container to this port. This allows actors to work across several domains, since often the only domain-specific part of of an actor is its receivers. Derived classes may choose to handle this directly, creating whatever specific type of receiver they want. This method is not write-synchronized on the workspace, so the caller should be.

        The returned receiver is either the new receiver, or another receiver wrapping it as specified in _wrapReceiver(Receiver, int).

        Parameters:
        channel - Channel id used to determine the source port.
        Returns:
        A new receiver.
        Throws:
        IllegalActionException - If the port has no container, or the container is unable to return a new receiver (for example if it has no executive director).
      • _removeReceivers

        protected void _removeReceivers​(Relation relation)
        Remove the receivers associated with the specified relation, if there are any. This sets the container of each receiver to null.
        Parameters:
        relation - The relation.
      • _notifyPortEventListeners

        protected final void _notifyPortEventListeners​(IOPortEvent event)
                                                throws IllegalActionException
        Send a PortEvent to all port event listeners that have registered with this IOPort.
        Parameters:
        event - The event.
        Throws:
        IllegalActionException - If thrown by portEvent().
      • _setConstant

        protected void _setConstant​(Token token,
                                    int limit)
        Set a constant token so that every call to get(int) or get(int,int) replaces the returned token(s) with this specified token. This is a rather specialized piece of functionality added to be able to support ConstantPublisherPort.
        Parameters:
        token - The token to return instead of received tokens, or null to cancel this functionality.
        limit - If a non-negative number is given here, then limit the number of constant tokens provided.
      • _wrapReceiver

        protected Receiver _wrapReceiver​(Receiver receiver,
                                         int channel)
                                  throws IllegalActionException
        If this port has parameters whose values are tokens that contain an object implementing CommunicationAspect, then wrap the receiver specified in the argument using those communication aspects. If there are no such parameters, then simply return the specified receiver. If there is one such parameter, then use the quantity manager to wrap the specified receiver in a new receiver, and return that receiver. If there are two such parameters, then use the second communication aspect to create a receiver that wraps that created by the first communication aspect. Etc.
        Parameters:
        receiver - The receiver to wrap.
        channel - Channel id used to determine the source port.
        Returns:
        Either a new receiver wrapping the specified receiver, or the specified receiver.
        Throws:
        IllegalActionException - If any parameter of the port cannot be evaluated.
        See Also:
        CommunicationAspect