foxtrot.workers
Class SingleWorkerThread

java.lang.Object
  extended by foxtrot.AbstractWorkerThread
      extended by foxtrot.workers.SingleWorkerThread
All Implemented Interfaces:
WorkerThread, Runnable
Direct Known Subclasses:
MultiWorkerThread

public class SingleWorkerThread
extends AbstractWorkerThread
implements Runnable

Full implementation of WorkerThread that uses a single worker thread to run Tasks subclasses.
Tasks execution is serialized: tasks are enqueued and executed one after the other.

Version:
$Revision: 255 $

Constructor Summary
SingleWorkerThread()
           
 
Method Summary
protected  String getThreadName()
          Returns the name of the worker thread used by this WorkerThread.
 boolean isAlive()
          Returns whether this WorkerThread is alive.
protected  boolean isThreadInterrupted()
          Returns whether the worker thread has been interrupted or not.
 boolean isWorkerThread()
          Returns whether the current thread is a thread used by the implementation of this WorkerThread to run Tasks.
 void postTask(Task t)
          Posts the given Task onto an internal queue.
 void run()
          The worker thread dequeues one Task from the internal queue via takeTask() and then executes it.
protected  void run(Task task)
          Executes the given Task.
 void start()
          Starts this WorkerThread, responsible for running Tasks (not in the Event Dispatch Thread).
protected  void stop()
          Stops abruptly this WorkerThread.
protected  Task takeTask()
          Removes and returns the first available Task from the internal queue.
 
Methods inherited from class foxtrot.AbstractWorkerThread
runTask
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleWorkerThread

public SingleWorkerThread()
Method Detail

start

public void start()
Description copied from interface: WorkerThread
Starts this WorkerThread, responsible for running Tasks (not in the Event Dispatch Thread). Applets can stop threads used by implementations of this WorkerThread in any moment, and this method also can be used to restart this WorkerThread if it results that it is not alive anymore.

Specified by:
start in interface WorkerThread
See Also:
WorkerThread.isAlive()

getThreadName

protected String getThreadName()
Returns the name of the worker thread used by this WorkerThread.


stop

protected void stop()
Stops abruptly this WorkerThread. If a Task is executing, its execution will be completed, but pending tasks will not be executed until a restart()


isAlive

public boolean isAlive()
Description copied from interface: WorkerThread
Returns whether this WorkerThread is alive. It is not enough to return whether this WorkerThread has been started, because Applets can stop threads used by implementations of this WorkerThread in any moment. If this WorkerThread is not alive, it must be restarted.

Specified by:
isAlive in interface WorkerThread
See Also:
WorkerThread.start()

isWorkerThread

public boolean isWorkerThread()
Description copied from interface: WorkerThread
Returns whether the current thread is a thread used by the implementation of this WorkerThread to run Tasks.

Specified by:
isWorkerThread in interface WorkerThread

postTask

public void postTask(Task t)
Posts the given Task onto an internal queue.

Specified by:
postTask in interface WorkerThread
See Also:
takeTask()

takeTask

protected Task takeTask()
                 throws InterruptedException
Removes and returns the first available Task from the internal queue. If no Tasks are available, this method blocks until a Task is posted via postTask(foxtrot.Task)

Throws:
InterruptedException

isThreadInterrupted

protected boolean isThreadInterrupted()
Returns whether the worker thread has been interrupted or not.

See Also:
Thread.isInterrupted()

run

public void run()
The worker thread dequeues one Task from the internal queue via takeTask() and then executes it.

Specified by:
run in interface Runnable

run

protected void run(Task task)
Executes the given Task. This implementation will just call AbstractWorkerThread.runTask(foxtrot.Task).



Copyright © 2011 KnowledgePlaza. All Rights Reserved.