objectdraw
Class ActiveObject

java.lang.Object
  extended by java.lang.Thread
      extended by objectdraw.ActiveObject
All Implemented Interfaces:
Runnable

public class ActiveObject
extends Thread

The class ActiveObject is used to define objects controlled by sequences of instructions that are executed independently of and simultaneously with other instructions in a program. The code that is to be executed independently should be placed in the body of a parameterless run method defined within a class definition that extends ActiveObject. When the start() method of an ActiveObject is invoked, the system will being to execute whatever code was placed in this run method.

ActiveObject is a simple extension of Java's native Thread class. ActiveObjects are automatically managed so that they are suspended and restarted when an applet is stopped and started. In addition, the sleep method provided in the Thread class is replaced with a similar pause method that does not require exception handling.

Version:
1.1.1 released February 2005

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActiveObject()
          Construct an ActiveObject.
ActiveObject(String name)
          Constructs an ActiveObject with a given name.
ActiveObject(ThreadGroup group, Runnable target, String name)
          Construct a new ActiveObject with the specified name using the Runnable and ThreadGroup parameters to determine its behavior.
 
Method Summary
(package private) static void initializeEventList()
          Initializes the event list that handles threads
(package private) static void introspect()
          The ActiveObject calling introspect calls the execute methods of the ActiveObjectEventInterface events it has been scheduled to call by calls to scheduleEvent and scheduleClassEvent.
static void pause(double millis)
          Suspend the execution of this ActiveObject for at least the time period specified.
static void pause(long millis)
          Suspend the execution of this ActiveObject for at least the time period specified.
static void pause(long millis, int nano)
          Suspend the execution of this ActiveObject for at least the time period specified.
(package private) static void scheduleClassEvent(ActiveObjectEventInterface event)
          Schedules event's execute method to be called once by all ActiveObjects not yet dead, including those yet to be created.
(package private)  void scheduleEvent(ActiveObjectEventInterface event)
          Schedules event's execute method to be called once by this ActiveObject.
static void yield()
          Briefly suspend the execution of this ActiveObject code to see if any other ActiveObject or Thread is waiting to execute.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActiveObject

public ActiveObject()
Construct an ActiveObject.


ActiveObject

public ActiveObject(String name)
Constructs an ActiveObject with a given name.

Parameters:
name - the name of the new ActiveObject.

ActiveObject

public ActiveObject(ThreadGroup group,
                    Runnable target,
                    String name)
Construct a new ActiveObject with the specified name using the Runnable and ThreadGroup parameters to determine its behavior. If the target argument is not null, the run method of the target is executed when this thread is started. If the target argument is null, this thread's run method is executed when this thread is started. If group is null and there is a security manager, the group is determined by the security manager's getThreadGroup method. If group is null and there is not a security manager, or the security manager's getThreadGroup method returns null, the group is set to be the same ThreadGroup as the thread that is creating the new thread. If there is a security manager, its checkAccess method is called with the ThreadGroup as its argument. This may result in a SecurityException.

Parameters:
group - the thread group.
target - the object whose run method is called.
name - the name of the new ActiveObject.
Method Detail

initializeEventList

static void initializeEventList()
Initializes the event list that handles threads


introspect

static void introspect()
The ActiveObject calling introspect calls the execute methods of the ActiveObjectEventInterface events it has been scheduled to call by calls to scheduleEvent and scheduleClassEvent. A native Thread calling introspect is unaffected.


pause

public static void pause(double millis)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(long millis)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(long millis,
                         int nano)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.
nano - additional number of nanoseconds to pause.

scheduleClassEvent

static void scheduleClassEvent(ActiveObjectEventInterface event)
Schedules event's execute method to be called once by all ActiveObjects not yet dead, including those yet to be created. "Schedules" means there is no guarantee as to how long before each ActiveObject calls event's execute method. Each ActiveObject calls event's execute method during the next time it calls introspect, or one of the methods that automatically calls introspect like pause.

Parameters:
event - event scheduled to be executed once by this ActiveObject.

scheduleEvent

void scheduleEvent(ActiveObjectEventInterface event)
Schedules event's execute method to be called once by this ActiveObject. "Schedules" means there is no guarantee as to how long before this ActiveObject calls event's execute method. This ActiveObject calls event's execute method during the next time it calls introspect, or one of the methods that automatically calls introspect like pause.

Parameters:
event - event scheduled to be executed once by this ActiveObject.

yield

public static void yield()
Briefly suspend the execution of this ActiveObject code to see if any other ActiveObject or Thread is waiting to execute. In addition, this method checks to see if the Controller has requested that this ActiveObject suspend or terminate its execution.