util
Class ExitThread

java.lang.Object
  extended by java.lang.Thread
      extended by util.ExitThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
AsynchronousCcdDriver.ExposureThread, SynchronousCcdDriver.ExposureThread

public abstract class ExitThread
extends Thread

An exit thread monitors the start and end time of its execution. Additionally, it allows recording of exceptions thrown during it's execution. Subclasses must provide a runner() method, that should return true on successful runs.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  long entertime
          The time the exposure thread started.
private  Exception error
          The exception thrown, if an error occured.
private  long exittime
          The time the exposure thread exited.
private  boolean success
          The outcome of the execution.
private  boolean syncthis
          If true, we syncronize on this during the run method.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected ExitThread()
          Constructs a new exit thread without synchronization in the run method.
protected ExitThread(boolean sync)
          Specifies, if the constructed thread should synchronize on itself at the run method or not.
 
Method Summary
private  void clear()
          Resets all field to invalid.
private  void dorun()
          This method is called either synchronized or in an unsynchronized state directly from the run method.
 long getEnterTime()
          Returns the enter time of the thread.
 Exception getError()
          Returns the exception that occured during the runner() method.
 long getExecutionTime()
          Returns the execution span as monitored by this thread.
 long getExitTime()
          Returns the exit time of the thread.
 void run()
          We monitor the enter and exit time, additionally, we notify any waiting object on exit.
protected abstract  boolean runner()
          This method is the modified run method.
 boolean wasSuccess()
          Returns true, if the last execution was successful.
 
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, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

syncthis

private boolean syncthis
If true, we syncronize on this during the run method.


entertime

private long entertime
The time the exposure thread started.


exittime

private long exittime
The time the exposure thread exited.


error

private Exception error
The exception thrown, if an error occured.


success

private boolean success
The outcome of the execution.

Constructor Detail

ExitThread

protected ExitThread()
Constructs a new exit thread without synchronization in the run method.


ExitThread

protected ExitThread(boolean sync)
Specifies, if the constructed thread should synchronize on itself at the run method or not. Calls the super constructor and clears errors.

Method Detail

clear

private void clear()
Resets all field to invalid. Should be called after the constructor.


run

public void run()
We monitor the enter and exit time, additionally, we notify any waiting object on exit. This method is not synchronized. If an error occurs during the execution of the runner() method, this thread is interrupted.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

dorun

private void dorun()
This method is called either synchronized or in an unsynchronized state directly from the run method. It records entry and exit time, plus the success of the runner() method.


getError

public Exception getError()
Returns the exception that occured during the runner() method.


getExitTime

public long getExitTime()
Returns the exit time of the thread. Zero if thread is still running or has not yet been started.


getEnterTime

public long getEnterTime()
Returns the enter time of the thread. Zero if thread has not yet been started.


getExecutionTime

public long getExecutionTime()
Returns the execution span as monitored by this thread. If thread is still running or has not been started, zero is returned.


wasSuccess

public boolean wasSuccess()
Returns true, if the last execution was successful.


runner

protected abstract boolean runner()
                           throws Exception
This method is the modified run method. Subclasses of this class should provide a body to this method that might throw exceptions and should return true, if execution was successful.

Throws:
Exception