|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
S
- indicates the type of the input work item.T
- indicates the type of the output work item.public interface MasterWorker<S,T>
This is a simple master/worker pattern. The master thread creates an instance of the pattern, provides work items to be processed, and is signaled upon completion. The master thread may wait for completion (synchronous) or may poll for completion (asynchronous). A master/worker pattern may be static or dynamic. In a static master/worker, execution proceeds in two distinct phases - first all of the work items are submitted and then the workers execute by consuming work items. Work items may not be submitted once execution has begun. In a dynamic master/worker, submission of work and the execution of workers proceeds concurrently. Furthermore, a worker task may opt to add new work items during its execution.
Nested Class Summary | |
---|---|
static class |
MasterWorker.ResultKey
An abstract type used to hold keys for result values. |
Method Summary | |
---|---|
boolean |
execute()
Begin processing of the work items submitted. |
boolean |
execute(long timeout,
java.util.concurrent.TimeUnit unit)
Begin processing of the work items submitted. |
void |
finished()
Indicate to the master/worker that there is not more work coming. |
java.util.Collection<T> |
getAllResults()
Obtain all of the results from the processing work items. |
boolean |
isCompleted()
Poll an executing master/worker for completion. |
boolean |
isStatic()
Determine if a master/worker is static. |
int |
numWorkers()
Get the number of active workers. |
T |
result(MasterWorker.ResultKey k)
Obtain the results from the processing of a work item. |
void |
shutdown()
Shutdown the master/worker. |
MasterWorker.ResultKey |
submit(S w)
Submit a work item for processing. |
MasterWorker.ResultKey |
submit(S w,
long timeout,
java.util.concurrent.TimeUnit unit)
Submit a work item for processing and block until it is either submitted successfully or the specified timeout period has expired. |
boolean |
waitForCompletion()
Wait until all workers have completed. |
boolean |
waitForCompletion(long timeout,
java.util.concurrent.TimeUnit unit)
Wait until all workers have completed or the specified timeout period expires. |
Method Detail |
---|
int numWorkers()
MasterWorker.ResultKey submit(S w)
w
- Work item.
MasterWorker.ResultKey submit(S w, long timeout, java.util.concurrent.TimeUnit unit)
w
- Work item.timeout
- Time out value.unit
- Time out unit.
void finished()
boolean execute(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException, java.lang.InterruptedException
timeout
- The timeout value.unit
- The time units.
java.util.concurrent.TimeoutException
- If the specified timeout period expired before completion of
all work items.
java.lang.InterruptedException
- If execution of any of the threads was interrupted.
java.util.concurrent.ExecutionException
- If any of the worker threads encounted some runtime
exception.boolean execute()
boolean isStatic()
boolean isCompleted()
boolean waitForCompletion(long timeout, java.util.concurrent.TimeUnit unit)
timeout
- time outunit
- time unit
boolean waitForCompletion()
T result(MasterWorker.ResultKey k)
k
- A result key, obtained from a prior call to "submit"
java.util.Collection<T> getAllResults()
void shutdown()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |