Class ProcessThread

  • All Implemented Interfaces:
    java.lang.Runnable, Debuggable
    Direct Known Subclasses:
    DDEThread

    public class ProcessThread
    extends PtolemyThread
    Thread class acting as a process for process oriented domains.

    In process oriented domains, each actor acts as a separate process and its execution is not centrally controlled by the director. Each process runs concurrently with other processes and is responsible for calling its execution methods.

    This class provides the mechanism to implement the above. An instance of this class can be created by passing an actor as an argument to the constructor. This class runs as a separate thread on being started and calls the execution methods on the actor, repeatedly. Specifically, it calls initialize(), and then repeatedly calls the prefire(), fire() and postfire() methods of the actor. Before termination, this calls the wrapup() method of the actor.

    If an actor returns false in its postfire() methods, the actor is never fired again and the thread or process terminates after calling wrapup() on the actor.

    An instance of this class is associated with an instance of ProcessDirector as well as an instance of Actor. The _increaseActiveCount() of the director is called from the constructor of this class, and the _decreaseActiveCount() method is called at the end of the run() method, just before the thread terminates.

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Mudit Goel, Neil Smyth, John S. Davis II, Contributors: Efrat Jaeger, Daniel Crawl
    Pt.AcceptedRating:
    Yellow (mudit)
    Pt.ProposedRating:
    Green (mudit)
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Constructor Summary

      Constructors 
      Constructor Description
      ProcessThread​(Actor actor, ProcessDirector director)
      Construct a thread to be used for the execution of the iteration methods of the actor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void _actorInitialized()
      Notify that the actor has been initialized.
      protected boolean _iterateActor()
      Iterate the actor associate with this thread.
      Actor getActor()
      Return the actor being executed by this thread.
      void run()
      Initialize the actor, iterate it through the execution cycle until it terminates.
      void wrapup()
      End the execution of the actor under the control of this thread.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

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

      • _actor

        protected Actor _actor
        The actor that to be executed.
      • _director

        protected ProcessDirector _director
        The director responsible for the execution of the actor.
      • _manager

        protected Manager _manager
        The Manager of the actor.
    • Constructor Detail

      • ProcessThread

        public ProcessThread​(Actor actor,
                             ProcessDirector director)
        Construct a thread to be used for the execution of the iteration methods of the actor. This increases the count of active actors in the director.
        Parameters:
        actor - The actor to be executed.
        director - The director responsible for the execution of the actor.
    • Method Detail

      • getActor

        public Actor getActor()
        Return the actor being executed by this thread.
        Returns:
        The actor being executed by this thread.
      • run

        public void run()
        Initialize the actor, iterate it through the execution cycle until it terminates. At the end of the termination, calls wrapup on the actor.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • wrapup

        public void wrapup()
                    throws IllegalActionException
        End the execution of the actor under the control of this thread. Subclasses are encouraged to override this method as necessary for domain specific functionality.
        Throws:
        IllegalActionException - If an error occurs while ending execution of the actor under the control of this thread.
      • _actorInitialized

        protected void _actorInitialized()
        Notify that the actor has been initialized. This base class does nothing.
      • _iterateActor

        protected boolean _iterateActor()
                                 throws IllegalActionException
        Iterate the actor associate with this thread.
        Returns:
        True if either prefire() returns false or postfire returns true.
        Throws:
        IllegalActionException - If the actor throws it.