groovyx.gpars.forkjoin
Class AbstractForkJoinWorker<T>

java.lang.Object
  extended by jsr166y.ForkJoinTask<V>
      extended by jsr166y.RecursiveTask<T>
          extended by groovyx.gpars.forkjoin.AbstractForkJoinWorker<T>
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.Future<T>
Direct Known Subclasses:
FJWorker

public abstract class AbstractForkJoinWorker<T>
extends jsr166y.RecursiveTask<T>

Implements the ForkJoin worker contract. Subclasses need to implement the compute() to perform the actual Fork/Join algorithm leveraging the options provided by the AbstractForkJoinWorker class. The AbstractForJoinWorker class takes care of the child sub-processes.

Author: Vaclav Pech Date: Nov 1, 2009

See Also:
Serialized Form

Field Summary
private  java.util.List<AbstractForkJoinWorker<T>> children
          Stores the child workers
 
Constructor Summary
protected AbstractForkJoinWorker()
           
 
Method Summary
protected  T compute()
           
protected abstract  T computeTask()
           
protected  void forkOffChild(AbstractForkJoinWorker<T> child)
          Forks a child task.
 java.util.List<T> getChildrenResults()
          Waits for and returns the results of the child tasks.
 
Methods inherited from class jsr166y.RecursiveTask
exec, getRawResult, setRawResult
 
Methods inherited from class jsr166y.ForkJoinTask
adapt, adapt, adapt, cancel, complete, completeExceptionally, fork, get, get, getException, getPool, getQueuedTaskCount, getSurplusQueuedTaskCount, helpQuiesce, inForkJoinPool, invoke, invokeAll, invokeAll, invokeAll, isCancelled, isCompletedAbnormally, isCompletedNormally, isDone, join, peekNextLocalTask, pollNextLocalTask, pollTask, quietlyInvoke, quietlyJoin, reinitialize, tryUnfork
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

children

private java.util.List<AbstractForkJoinWorker<T>> children
Stores the child workers

Constructor Detail

AbstractForkJoinWorker

protected AbstractForkJoinWorker()
Method Detail

compute

protected final T compute()
Specified by:
compute in class jsr166y.RecursiveTask<T>

computeTask

protected abstract T computeTask()

forkOffChild

protected final void forkOffChild(AbstractForkJoinWorker<T> child)
Forks a child task. Makes sure it has a means to indicate back completion. The worker is stored in the internal list of workers for evidence and easy result retrieval through getChildrenResults().

Parameters:
child - The child task

getChildrenResults

public final java.util.List<T> getChildrenResults()
Waits for and returns the results of the child tasks.

Returns:
A list of results returned from the child tasks

Copyright © 2008–2012 Václav Pech. All Rights Reserved.