objectdraw
Class ActiveObject

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--objectdraw.ActiveObject
All Implemented Interfaces:
java.lang.Runnable

public class ActiveObject
extends java.lang.Thread

ActiveObject is a flexible version of Java's native Thread. It allows the programmer to specify the behavior of Threads more easily and safely. ActiveObject provides a superset of Java's native Thread functionality, which means it only adds to the native functionality, and does not change it. Thus ActiveObject can be used in any context Java's native Thread is used to the exact same effect.


Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActiveObject()
          Same as corresponding Thread constructor.
ActiveObject(java.lang.Runnable target)
          Same as corresponding Thread constructor.
ActiveObject(java.lang.Runnable target, java.lang.String name)
          Same as corresponding Thread constructor.
ActiveObject(java.lang.String name)
          Same as corresponding Thread constructor.
ActiveObject(java.lang.ThreadGroup group, java.lang.Runnable target)
          Same as corresponding Thread constructor.
ActiveObject(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
          Same as corresponding Thread constructor.
ActiveObject(java.lang.ThreadGroup group, java.lang.String name)
          Same as corresponding Thread constructor.
 
Method Summary
static void defer()
          Same as native yield except introspect is called automatically.
static double getTime()
          Returns the current time in milliseconds
static void initializeEventList()
          Initializes the event list that handles threads
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)
          Same as native sleep except a) introspect is called automatically, b) the paused ActiveObject unblocks when interrupted without throwing an InterruptedException, and c) the parameter is a double
static void pause(long millis)
          Same as native sleep except introspect is called automatically and the paused ActiveObject unblocks when interrupted without throwing an InterruptedException.
static void pause(long millis, int nano)
          Same as native sleep except introspect is called automatically and the paused ActiveObject unblocks when interrupted without throwing an InterruptedException.
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.
 void scheduleEvent(ActiveObjectEventInterface event)
          Schedules event's execute method to be called once by this ActiveObject.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, 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

ActiveObject

public ActiveObject()
Same as corresponding Thread constructor. Constructs an ActiveObject.

ActiveObject

public ActiveObject(java.lang.Runnable target)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
target - the object whose run method is called.

ActiveObject

public ActiveObject(java.lang.Runnable target,
                    java.lang.String name)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
target - the object whose run method is called.
name - the name of the new ActiveObject.

ActiveObject

public ActiveObject(java.lang.String name)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
name - the name of the new ActiveObject.

ActiveObject

public ActiveObject(java.lang.ThreadGroup group,
                    java.lang.Runnable target)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
group - the thread group.
target - the object whose run method is called.

ActiveObject

public ActiveObject(java.lang.ThreadGroup group,
                    java.lang.Runnable target,
                    java.lang.String name)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
group - the thread group.
target - the object whose run method is called.
name - the name of the new ActiveObject.

ActiveObject

public ActiveObject(java.lang.ThreadGroup group,
                    java.lang.String name)
Same as corresponding Thread constructor. Constructs an ActiveObject.
Parameters:
group - the thread group.
name - the name of the new ActiveObject.
Method Detail

scheduleEvent

public 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.

introspect

public 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.

defer

public static void defer()
Same as native yield except introspect is called automatically.

pause

public static void pause(long millis)
Same as native sleep except introspect is called automatically and the paused ActiveObject unblocks when interrupted without throwing an InterruptedException.
Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(double millis)
Same as native sleep except a) introspect is called automatically, b) the paused ActiveObject unblocks when interrupted without throwing an InterruptedException, and c) the parameter is a double
Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(long millis,
                         int nano)
Same as native sleep except introspect is called automatically and the paused ActiveObject unblocks when interrupted without throwing an InterruptedException.
Parameters:
millis - number of milliseconds to pause.
nano - number of nanoseconds to pause.

getTime

public static double getTime()
Returns the current time in milliseconds

scheduleClassEvent

public 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.

initializeEventList

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