com.partnersoft.gadgets
Class TriggeredThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.partnersoft.gadgets.TriggeredThread
All Implemented Interfaces:
java.lang.Runnable

public class TriggeredThread
extends java.lang.Thread

Takes care of the (surprisingly annoying) case of running a task on a separate thread whenever some event occurs. It waits otherwise.

Author:
Paul Reavis Copyright 2004 Partner Software, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TriggeredThread()
           
TriggeredThread(java.lang.String name)
           
TriggeredThread(java.lang.String name, java.lang.Runnable task)
           
 
Method Summary
 double getMeasuredSpeed()
          Total measured speed, in runs per second.
 double getRecentMeasuredSpeed()
          Actual task frequency, in runs per second, over the last 100 samples.
 java.lang.Runnable getTask()
           
 void run()
           
 void runTask()
          By default, this runs the runnable.
 void setTask(java.lang.Runnable newTask)
           
 void stopRunning()
          Tells the thread to quit looping.
 void trigger()
          Tickles the thread and tells it to run its action.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

TriggeredThread

public TriggeredThread()

TriggeredThread

public TriggeredThread(java.lang.String name)

TriggeredThread

public TriggeredThread(java.lang.String name,
                       java.lang.Runnable task)
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

trigger

public void trigger()
Tickles the thread and tells it to run its action. Multiple calls to this during a run are quashed, to prevent scheduling some ridiculous number of runs. Generally used to indicate that some change in state has happened that requires the task to be rerun.


runTask

public void runTask()
             throws java.lang.Exception
By default, this runs the runnable. Subclasses may also override it directly (e.g. in anonymous or inner classes). Exceptions will be caught and reported but will stop the thread.

Throws:
java.lang.Exception

stopRunning

public void stopRunning()
Tells the thread to quit looping. Waits for it to complete.


setTask

public void setTask(java.lang.Runnable newTask)

getTask

public java.lang.Runnable getTask()

getMeasuredSpeed

public double getMeasuredSpeed()
Total measured speed, in runs per second.


getRecentMeasuredSpeed

public double getRecentMeasuredSpeed()
Actual task frequency, in runs per second, over the last 100 samples.