de.unikassel.android.sdcframework.util
Class AbstractWorkerThread

Package class diagram package AbstractWorkerThread
java.lang.Object
  extended by java.lang.Thread
      extended by de.unikassel.android.sdcframework.util.AbstractWorkerThread
All Implemented Interfaces:
WorkerThread, Runnable
Direct Known Subclasses:
AbstractAsynchrounousSampleObserver, AbstractEventDispatcherImpl, LogfileManager, SampleReceivingDeviceScanner.ScanWorkerThread, TimeProvider.UpdateThread, TransferManagerImpl

public abstract class AbstractWorkerThread
extends Thread
implements WorkerThread

Abstract base class for any thread in the SDC Framework.

Does provide the following features:


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  AtomicBoolean doLog
          The logging state flag
private  AtomicBoolean hasTerminated
          The terminated state flag
private  AtomicBoolean isNew
          The new created state flag
private  AtomicBoolean isWorking
          The isWorking state flag
private  Object syncLock
          Synchronization lock
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractWorkerThread()
          Constructor
 
Method Summary
protected abstract  void doCleanUp()
          The clean up method executed on termination
private  void doRun()
          Does send the thread into running mode either by starting it if not alive or by waking a sleeping thread up.
 void doTerminate()
          Does stop current work and trigger thread termination
protected abstract  void doWork()
          The working method executed in the running loop if started
 boolean hasTerminated()
          Getter for the terminated flag
 boolean isLogging()
          Getter for the logging flag
 boolean isWorking()
          Getter for the working flag
protected  void logMessage(String message)
          Does log a message if logging is enabled
 void run()
           
 void setLogging(boolean doLog)
          Setter for the logging flag
 void start()
           
 void startWork()
          Does start working if thread is not in working state
 void stopWork()
          Does stop working if thread is in working state
 
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, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isNew

private final AtomicBoolean isNew
The new created state flag


hasTerminated

private final AtomicBoolean hasTerminated
The terminated state flag


isWorking

private final AtomicBoolean isWorking
The isWorking state flag


doLog

private final AtomicBoolean doLog
The logging state flag


syncLock

private final Object syncLock
Synchronization lock

Constructor Detail

AbstractWorkerThread

public AbstractWorkerThread()
Constructor

Method Detail

isWorking

public final boolean isWorking()
Description copied from interface: WorkerThread
Getter for the working flag

Specified by:
isWorking in interface WorkerThread
Returns:
the working flag

setLogging

public final void setLogging(boolean doLog)
Description copied from interface: WorkerThread
Setter for the logging flag

Specified by:
setLogging in interface WorkerThread
Parameters:
doLog - flag if logging should be done

isLogging

public final boolean isLogging()
Description copied from interface: WorkerThread
Getter for the logging flag

Specified by:
isLogging in interface WorkerThread
Returns:
the logging flag

hasTerminated

public final boolean hasTerminated()
Description copied from interface: WorkerThread
Getter for the terminated flag

Specified by:
hasTerminated in interface WorkerThread
Returns:
the terminated flag

start

public final void start()
Overrides:
start in class Thread

run

public final void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

startWork

public final void startWork()
Description copied from interface: WorkerThread
Does start working if thread is not in working state

Specified by:
startWork in interface WorkerThread

doRun

private final void doRun()
Does send the thread into running mode either by starting it if not alive or by waking a sleeping thread up.


stopWork

public final void stopWork()
Description copied from interface: WorkerThread
Does stop working if thread is in working state

Specified by:
stopWork in interface WorkerThread

doTerminate

public final void doTerminate()
Description copied from interface: WorkerThread
Does stop current work and trigger thread termination

Specified by:
doTerminate in interface WorkerThread

logMessage

protected final void logMessage(String message)
Does log a message if logging is enabled

Parameters:
message - the message to log

doCleanUp

protected abstract void doCleanUp()
The clean up method executed on termination


doWork

protected abstract void doWork()
The working method executed in the running loop if started