Package aQute.libg.forker
Class Forker<T>
- java.lang.Object
-
- aQute.libg.forker.Forker<T>
-
- Type Parameters:
T-
public class Forker<T> extends java.lang.ObjectA Forker is good in parallel scheduling tasks with dependencies. You can add tasks withdoWhen(Collection, Object, Runnable). The collection is the list of dependencies, the object is the target, and the runnable is run to update the target. The runnable will only run when all its dependencies have ran their associated runnable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classForker.JobHelper class to model a Job
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.atomic.AtomicBooleancanceledprivate intcount(package private) java.util.Set<Forker.Job>executing(package private) java.util.concurrent.Executorexecutor(package private) java.util.Map<T,Forker.Job>waiting
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(long ms)Cancel the forker.private voidcheck()(package private) voiddone(Forker.Job done)Called when the target has ran by the Job.voiddoWhen(java.util.Collection<? extends T> dependencies, T target, java.lang.Runnable runnable)Schedule a job for execution when the dependencies are done of target are done.intgetCount()private voidschedule()voidstart(long ms)voidsync(long ms)
-
-
-
Field Detail
-
executor
final java.util.concurrent.Executor executor
-
waiting
final java.util.Map<T,Forker.Job> waiting
-
executing
final java.util.Set<Forker.Job> executing
-
canceled
final java.util.concurrent.atomic.AtomicBoolean canceled
-
count
private int count
-
-
Method Detail
-
doWhen
public void doWhen(java.util.Collection<? extends T> dependencies, T target, java.lang.Runnable runnable)
Schedule a job for execution when the dependencies are done of target are done.- Parameters:
dependencies- the dependencies that must have runtarget- the target, is removed from all the dependencies when it ranrunnable- the runnable to run
-
start
public void start(long ms) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
check
private void check()
-
sync
public void sync(long ms) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
schedule
private void schedule()
-
done
void done(Forker.Job done)
Called when the target has ran by the Job.- Parameters:
done-
-
cancel
public void cancel(long ms) throws java.lang.InterruptedExceptionCancel the forker.- Throws:
java.lang.InterruptedException
-
getCount
public int getCount()
-
-