Class MetroIIPNDirector

  • All Implemented Interfaces:
    java.lang.Cloneable, Executable, Initializable, GetFirable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class MetroIIPNDirector
    extends PNDirector
    implements GetFirable

    MetroIIPNDirector extends PNDirector and implements the MetroIIEventHandler interface. In addition to being blocked on read or write, the actors governed by MetroIIPNDirector may be blocked by MetroII events: 'Get.End' or 'Put.Begin'. 'Get.End' is PROPOSED after a token is successfully obtained from the receiver. And the actor is blocked until 'Get.End' is NOTIFIED. 'Put.Begin' is PROPOSED before trying to put a token into the receiver. Similarly, the actor is blocked until 'Put.Begin' is NOTIFIED.

    Known issue: threads created by Yieldadapter correctly stop but the ones created by ProcessDirector do not. It seems stop() is called for each thread in ProcessDirector.stop() but no effect can be observed. Don't know why. BTW, stop() is a deprecated function in java.

    The implementation is obsolete and needs to be updated.

    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Liangpeng Guo
    Pt.AcceptedRating:
    Red (glp)
    Pt.ProposedRating:
    Red (glp)
    • Field Detail

      • _metroIIEventBlockedThreads

        protected java.util.Set _metroIIEventBlockedThreads
        The set of threads that are blocked on an MetroII event.
    • Constructor Detail

      • MetroIIPNDirector

        public MetroIIPNDirector​(CompositeEntity container,
                                 java.lang.String name)
                          throws IllegalActionException,
                                 NameDuplicationException
        Constructs a director in the given container with the given name. If the container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace. Initialize an eventLock vector.
        Parameters:
        container - Container of the director.
        name - Name of this director.
        Throws:
        IllegalActionException - If the director is not compatible with the specified container. Thrown in derived classes.
        NameDuplicationException - If the container not a CompositeActor and the name collides with an entity in the container.
    • Method Detail

      • newReceiver

        public Receiver newReceiver()
        The same as super class except replacing the PNQueueReceiver by MetroIIPNQueueReceiver.
        Overrides:
        newReceiver in class PNDirector
        Returns:
        A new PNQueueReceiver.
      • addProposedMetroIIEvent

        public void addProposedMetroIIEvent​(metroIIcomm.Event.Builder e)
        Adds a proposed MetroII event into the director's event list.
        Parameters:
        e - the event to be added.
      • adapter

        public net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>> adapter()
        Returns the iterator for the caller function of getfire().
        Specified by:
        adapter in interface GetFirable
        Returns:
        iterator the iterator for the caller function of getfire()
      • getfire

        public void getfire​(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler)
                     throws net.jimblackler.Utils.CollectionAbortedException
        Implements fire() with MetroII event handling. In each iteration, getfire() waits until all other threads are blocked and yield returns MetroII events. When getfire() continues, notify the threads blocked on MetroII events based on the event status. A thread blocked on MetroII event is not notified until the blocking MetroII event is NOTIFIED. The rest of the function is copied from fire() of ProcessDirector
        Specified by:
        getfire in interface GetFirable
        Parameters:
        resultHandler - iterable of events 'yield returned'.
        Throws:
        net.jimblackler.Utils.CollectionAbortedException
      • proposeMetroIIEvent

        public void proposeMetroIIEvent​(java.lang.String suffix)
                                 throws java.lang.InterruptedException
        Creates a MetroII event with the name: thread.getName()+suffix Add the MetroII event into the director's event list. Block the thread calling proposeMetroIIEvent().
        Parameters:
        suffix - The suffix of MetroII event name
        Throws:
        java.lang.InterruptedException
      • _getMetroIIEventBlockedThreadsCount

        protected final int _getMetroIIEventBlockedThreadsCount()
        Returns the number of threads that are currently blocked on a MetroII event.
        Returns:
        Return the number of threads that are currently blocked on a MetroII event.
      • _requestFinishOnReceivers

        protected void _requestFinishOnReceivers()
        Notifies all the threads blocked on MetroII events. Request finish on all the receivers.
        Overrides:
        _requestFinishOnReceivers in class ProcessDirector