|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.droids.impl.MultiThreadedTaskMaster<T>
T - public class MultiThreadedTaskMaster<T extends Task>
This task master provides a base implementation that support multithreaded task processing powered by a ThreadPoolExecutor.
By default, the ThreadPoolExecutor uses a bounded blocking queue with a size as same as the maxThreads. As long as there is any outstanding task in the Task Queue and the Executor has spare capacity, a new Thread will be created to poll and handle one task from the Task Queue. User may set to use another 'pool' implementation, and the nextTask() method may be overriden by sub-class. This Task Master doesn't support: pausing, monitoring etc. TaskExceptionHandler is unimplemented. And there is no failure handling mechanism, e.g. if the JVM of Task Master is crashed, any task polled from the Task Queue will be loss. (this point makes sense only if the Task Queue is persistent)
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.apache.droids.api.TaskMaster |
|---|
TaskMaster.ExecutionState |
| Field Summary | |
|---|---|
protected java.util.concurrent.atomic.AtomicLong |
completedCount
|
protected DelayTimer |
delayTimer
|
protected Droid<T> |
droid
|
protected TaskExceptionHandler |
exHandler
|
protected java.util.Date |
finishedWorking
|
protected T |
lastCompletedTask
|
protected org.apache.commons.logging.Log |
log
|
protected int |
maxThreads
|
protected WorkMonitor<T> |
monitor
|
protected java.lang.String |
name
|
protected java.util.concurrent.ThreadPoolExecutor |
pool
|
protected TaskQueue<T> |
queue
|
protected java.util.Date |
startedWorking
|
protected TaskMaster.ExecutionState |
state
|
| Constructor Summary | |
|---|---|
MultiThreadedTaskMaster()
|
|
| Method Summary | |
|---|---|
void |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
|
long |
getCompletedTasks()
|
DelayTimer |
getDelayTimer()
|
TaskMaster.ExecutionState |
getExecutionState()
|
java.util.Date |
getFinishedWorking()
|
T |
getLastCompletedTask()
|
int |
getMaxThreads()
Get number of maximum allowed threads |
WorkMonitor<T> |
getMonitor()
|
java.lang.String |
getName()
|
java.util.Date |
getStartTime()
|
void |
processAllTasks(TaskQueue<T> queue,
Droid<T> droid)
The queue has been initialized |
void |
setDelayTimer(DelayTimer delayTimer)
|
void |
setExceptionHandler(TaskExceptionHandler exHandler)
|
void |
setMaxThreads(int count)
Set the maximum allowed thread count. |
void |
setMonitor(WorkMonitor<T> monitor)
|
void |
setName(java.lang.String name)
|
void |
shutdownAndAwaitTermination()
Shutdown all threads, close the pools and leave. |
protected java.util.concurrent.Future |
submitNewTaskRunner(java.util.concurrent.ExecutorService executor,
TaskQueue<? extends T> queue)
This method is designed for sub-classing TODO: refactor and create a specialized thread that - construct with the delayTimer and transparently apply the delay - construct with the Task and transparent set the lastCompleteTask TODO: consider to provide all variables as argument so that the method overrider needs not to call the parent variables TODO: caller of this method could use the Future to track the task completion and perform the termination and other checking. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final org.apache.commons.logging.Log log
protected java.lang.String name
protected java.util.concurrent.ThreadPoolExecutor pool
protected int maxThreads
protected TaskQueue<T extends Task> queue
protected Droid<T extends Task> droid
protected DelayTimer delayTimer
protected WorkMonitor<T extends Task> monitor
protected java.util.Date startedWorking
protected java.util.Date finishedWorking
protected T extends Task lastCompletedTask
protected volatile TaskMaster.ExecutionState state
protected java.util.concurrent.atomic.AtomicLong completedCount
protected TaskExceptionHandler exHandler
| Constructor Detail |
|---|
public MultiThreadedTaskMaster()
| Method Detail |
|---|
public void processAllTasks(TaskQueue<T> queue,
Droid<T> droid)
processAllTasks in interface TaskMaster<T extends Task>
protected java.util.concurrent.Future submitNewTaskRunner(java.util.concurrent.ExecutorService executor,
TaskQueue<? extends T> queue)
executor - queue -
public void setMaxThreads(int count)
count - public int getMaxThreads()
public TaskMaster.ExecutionState getExecutionState()
getExecutionState in interface TaskMaster<T extends Task>public void shutdownAndAwaitTermination()
public void awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface TaskMaster<T extends Task>java.lang.InterruptedExceptionpublic final void setExceptionHandler(TaskExceptionHandler exHandler)
public DelayTimer getDelayTimer()
public void setDelayTimer(DelayTimer delayTimer)
public long getCompletedTasks()
getCompletedTasks in interface TaskMaster<T extends Task>public java.util.Date getFinishedWorking()
getFinishedWorking in interface TaskMaster<T extends Task>public T getLastCompletedTask()
getLastCompletedTask in interface TaskMaster<T extends Task>public java.util.Date getStartTime()
getStartTime in interface TaskMaster<T extends Task>public WorkMonitor<T> getMonitor()
public void setMonitor(WorkMonitor<T> monitor)
public java.lang.String getName()
public void setName(java.lang.String name)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||