Class TMReceiver

  • All Implemented Interfaces:
    Receiver

    public class TMReceiver
    extends AbstractReceiver
    The receiver for the TM domain. This receiver contains a FIFO queue. Upon receiving a token, it creates a TMEvent. The properties of the TM events are:
    • The destination receiver is this receiver.
    • The destination actor is the container's container of this receiver.
    • The token is the received token.
    • The priority is the value of the parameter with name priority of the container of this receiver. If the container does not has a parameter with that name, then look at the actor. If none of them has the parameter, then use the default priority value, which is java.Thread.NORMAL_PRIORITY.
    • The flag hasStarted is false.
    • The processing time is obtained from the container or the container's container of this receiver, similar to the way obtaining the priority value. If none of them has the parameter, then use the default value 0.
    The event is then queued with the director, so it is not immediately available by the get() method. Later, the director may make the token available again by calling the _triggerEvent() method. See the TMDirector class for the event dispatching mechanism.
    Since:
    Ptolemy II 2.0
    Version:
    $Id$
    Author:
    Edward A. Lee, Jie Liu
    See Also:
    TMDirector
    Pt.AcceptedRating:
    Yellow (janneck)
    Pt.ProposedRating:
    Yellow (liuj)
    • Constructor Summary

      Constructors 
      Constructor Description
      TMReceiver()
      Construct an empty TMReceiver with no container.
    • Constructor Detail

      • TMReceiver

        public TMReceiver()
        Construct an empty TMReceiver with no container.
    • Method Detail

      • elementList

        public java.util.List<Token> elementList()
        Return a list with the tokens currently in the receiver, or an empty list if there are no such tokens.
        Specified by:
        elementList in interface Receiver
        Overrides:
        elementList in class AbstractReceiver
        Returns:
        A list of instances of Token.
      • get

        public Token get()
                  throws NoTokenException
        Get a token from the receiver. The token returned is one that was put in the receiver that is ready for process. A token is ready to be processed if it has the highest priority among all the appending events (system wide), and the resource is ready to be allocated to its destination actor. Whether the resource is ready depends on whether there is any active tasks, and whether the execution is preemptive. Note that there might be multiple such tokens in the receiver. In that case, FIFO behaviour is used with respect to the put() method. If there is no such token, throw an exception. This method is synchronized since the actor may not execute in the same thread as the director.
        Specified by:
        get in interface Receiver
        Specified by:
        get in class AbstractReceiver
        Returns:
        A token.
        Throws:
        NoTokenException - Not thrown in this base class.
      • getDirector

        public TMDirector getDirector()
                               throws IllegalActionException
        Return the director that created this receiver. If this receiver is an inside receiver of an output port of an opaque composite actor, then the director will be the local director of the container of its port. Otherwise, it's the executive director of the container of its port. Note that the director returned is guaranteed to be non-null. This method is read synchronized on the workspace.
        Returns:
        An instance of TMDirector that creates this receiver.
        Throws:
        IllegalActionException - If there is no container port, or if the port has no container actor, or if the actor has no director, or if the director is not an instance of TMDirector.
      • hasRoom

        public final boolean hasRoom()
        Return true, indicating that there is always room.
        Specified by:
        hasRoom in interface Receiver
        Specified by:
        hasRoom in class AbstractReceiver
        Returns:
        True.
      • hasRoom

        public final boolean hasRoom​(int tokens)
        Return true, indicating that there is always room for any number of tokens.
        Specified by:
        hasRoom in interface Receiver
        Specified by:
        hasRoom in class AbstractReceiver
        Parameters:
        tokens - The number of tokens, currently ignored.
        Returns:
        True.
      • hasToken

        public final boolean hasToken()
        Return true if there is at least one token available to the get() method.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Returns:
        True if there are more tokens.
      • hasToken

        public final boolean hasToken​(int numberOfTokens)
        Return true if there are numberOfTokens tokens available to the get() method.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Parameters:
        numberOfTokens - The number of tokens, currently ignored.
        Returns:
        True if there are numberOfTokens tokens available.
      • put

        public void put​(Token token)
        Put a token into this receiver. Note that this token does not become immediately available to the get() method. Instead, the token is queued with the director, and the director must put the token back into this receiver using the _triggerEvent() protected method in order for the token to become available to the get() method. By default, this token will be enqueued by the director with the default priority -- 5. However, by setting a priority parameter to the container of this receiver, or the container's container, you can enqueue the event with any priority. This method is synchronized since the actor may not execute in the same thread as the director.
        Specified by:
        put in interface Receiver
        Specified by:
        put in class AbstractReceiver
        Parameters:
        token - The token to be put, or null to put no token.
      • _triggerEvent

        protected void _triggerEvent​(Token token)
        Make a token available to the get() method. Normally, only a director will call this method.
        Parameters:
        token - The token to make available to get().