ptolemy.actor.process
Class ProcessThread

java.lang.Object
  extended byjava.lang.Thread
      extended byptolemy.kernel.util.PtolemyThread
          extended byptolemy.actor.process.ProcessThread
All Implemented Interfaces:
Debuggable, java.lang.Runnable
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. In specific, it 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 would terminate after calling wrapup() on the actor.

The initialize() method of the actor is not called from this class. It should be called before starting this thread.

In process oriented domains, the director needs to keep a count of the number of active processes in the system. This is used for detection of deadlocks, termination, and possibly some other reasons. For this two methods, _increaseActiveCount() and _decreaseActiveCount(), are defined in the ProcessDirector. _increaseActiveCount() is called on the director from the constructor of this class and the _decreaseActiveCount() method is called at the end of the run() method, i.e. before the thread terminates.

Since:
Ptolemy II 0.2
Version:
$Id: ProcessThread.java,v 1.72.2.2 2004/06/22 01:09:33 cxh Exp $
Author:
Mudit Goel, Neil Smyth, John S. Davis II
Accepted Rating:
Yellow (mudit)
Proposed Rating:
Green (mudit)

Field Summary
 
Fields inherited from class ptolemy.kernel.util.PtolemyThread
_debugging, _debugListeners
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ProcessThread(Actor actor, ProcessDirector director)
          Construct a thread to be used for the execution of the iteration methods of the actor.
 
Method Summary
 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 ptolemy.kernel.util.PtolemyThread
_debug, _debug, addDebugListener, removeDebugListener
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 that needs to be executed.
director - The director responsible for the execution of this 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.


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.