Class DEReceiver

  • All Implemented Interfaces:
    Receiver
    Direct Known Subclasses:
    ATCReceiver, MetroIIPtidesReceiver, PtidesReceiver, TCSReceiver, WirelessReceiver

    public class DEReceiver
    extends AbstractReceiver
    An implementation of the ptolemy.actor.Receiver interface for the DE domain.

    The put() method stores the given token in this receiver and posts a trigger event to the director. The director is responsible to dequeue that trigger event and invoke the actor that contains this receiver. The get() method returns the first available token from the receiver.

    Before firing an actor, the director is expected to put at least one token into at least one of the receivers contained by the actor.

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Lukito Muliadi, Edward A. Lee, Jie Liu, Haiyang Zheng
    Pt.AcceptedRating:
    Yellow (hyzheng)
    Pt.ProposedRating:
    Green (hyzheng)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected long _directorVersion
      The version of the workspace of container, used for caching by _getDirector().
      protected java.util.LinkedList _tokens
      List for storing tokens.
    • Constructor Summary

      Constructors 
      Constructor Description
      DEReceiver()
      Construct an empty DEReceiver with no container.
      DEReceiver​(IOPort container)
      Construct an empty DEReceiver with the specified container.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear this receiver of any contained tokens.
      java.util.List<Token> elementList()
      Return a list with tokens that are currently in the receiver available for get() or getArray(), beginning with the oldest one.
      Token get()
      Get the first token from the receiver.
      boolean hasRoom()
      Return true, indicating that there is always room.
      boolean hasRoom​(int tokens)
      Return true if the receiver has room for putting the given number of tokens into it (via the put() method).
      boolean hasToken()
      Return true if there is at least one token available to the get() method.
      boolean hasToken​(int numberOfTokens)
      Return true if there are numberOfTokens tokens tokens available to the get() method.
      void put​(Token token)
      Put a token into this receiver and post a trigger event to the director.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • _directorVersion

        protected long _directorVersion
        The version of the workspace of container, used for caching by _getDirector(). Derived classes that modify the cache may need to update this variable.
      • _tokens

        protected java.util.LinkedList _tokens
        List for storing tokens. Access with clear(), add(), and take().
    • Constructor Detail

      • DEReceiver

        public DEReceiver()
        Construct an empty DEReceiver with no container.
      • DEReceiver

        public DEReceiver​(IOPort container)
                   throws IllegalActionException
        Construct an empty DEReceiver with the specified container.
        Parameters:
        container - The container.
        Throws:
        IllegalActionException - If the container does not accept this receiver.
    • Method Detail

      • elementList

        public java.util.List<Token> elementList()
        Return a list with tokens that are currently in the receiver available for get() or getArray(), beginning with the oldest one.
        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 the first token from the receiver. The token returned is one that was put in the receiver with a timestamp equal to or earlier than the current time. If there is no token, throw an exception. If this receiver contains more than one event, the oldest event is removed first. In other words, this receiver has a FIFO behavior.
        Specified by:
        get in interface Receiver
        Specified by:
        get in class AbstractReceiver
        Returns:
        A token.
        Throws:
        NoTokenException - If there are no more tokens. This is a runtime exception, so it need not to be declared explicitly.
      • 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 boolean hasRoom​(int tokens)
        Return true if the receiver has room for putting the given number of tokens into it (via the put() method). Returning true in this method should also guarantee that calling the put() method will not result in an exception.
        Specified by:
        hasRoom in interface Receiver
        Specified by:
        hasRoom in class AbstractReceiver
        Parameters:
        tokens - An int indicating the number of spaces available.
        Returns:
        True.
      • hasToken

        public 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 boolean hasToken​(int numberOfTokens)
        Return true if there are numberOfTokens tokens tokens available to the get() method.
        Specified by:
        hasToken in interface Receiver
        Specified by:
        hasToken in class AbstractReceiver
        Parameters:
        numberOfTokens - An int indicating how many tokens are needed.
        Returns:
        True if there are numberOfTokens tokens available.
      • put

        public void put​(Token token)
                 throws IllegalActionException,
                        NoRoomException
        Put a token into this receiver and post a trigger event to the director. The director will be responsible to dequeue the trigger event at the correct timestamp and microstep and invoke the corresponding actor whose input port contains this receiver. This receiver may contain more than one events.
        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.
        Throws:
        IllegalActionException - If cannot get the director or if the current microstep is zero.
        NoRoomException - Not thrown in this class.