Package org.jgroups.blocks.executor
Class ExecutionService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- org.jgroups.blocks.executor.ExecutionService
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public class ExecutionService extends java.util.concurrent.AbstractExecutorServiceThis is a JGroups implementation of an ExecutorService, where the consumers are running on any number of nodes. The nodes should runExecutionRunnerto start picking up requests.Every future object returned will be a
NotifyingFuturewhich allows for not having to query the future and have a callback instead. This can then be used as a workflow to submit other tasks sequentially or also to query the future for the value at that time.Every callable or runnable submitted must be either
SerializableorStreamable. Also the value returned from a callable mustSerializableorStreamable. Unfortunately if the value returned is not serializable then aNotSerializableExceptionwill be thrown as the cause.- Since:
- 2.12.0
- Author:
- wburns
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExecutionService.DistributedFuture<V>This is basically a copy of the FutureTask in java.util.concurrent but added serializable to it.protected static classExecutionService.RunnableAdapter<T>This is copied fromExecutorsclass which contains RunnableAdapter.
-
Field Summary
Fields Modifier and Type Field Description protected Executing_execProtprotected java.util.concurrent.atomic.AtomicBoolean_shutdownprotected java.util.concurrent.locks.Condition_unfinishedConditionprotected java.util.Set<java.util.concurrent.Future<?>>_unfinishedFuturesprotected java.util.concurrent.locks.Lock_unfinishedLockprotected JChannelch
-
Constructor Summary
Constructors Constructor Description ExecutionService()ExecutionService(JChannel ch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)voidexecute(java.lang.Runnable command)<T> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)<T> TinvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)booleanisShutdown()booleanisTerminated()protected <T> java.util.concurrent.RunnableFuture<T>newTaskFor(java.lang.Runnable runnable, T value)protected <T> java.util.concurrent.RunnableFuture<T>newTaskFor(java.util.concurrent.Callable<T> callable)voidsetChannel(JChannel ch)voidshutdown()java.util.List<java.lang.Runnable>shutdownNow()<T> NotifyingFuture<T>submit(java.lang.Runnable task, T result)<T> NotifyingFuture<T>submit(java.util.concurrent.Callable<T> task)
-
-
-
Field Detail
-
ch
protected JChannel ch
-
_execProt
protected Executing _execProt
-
_unfinishedLock
protected java.util.concurrent.locks.Lock _unfinishedLock
-
_unfinishedCondition
protected java.util.concurrent.locks.Condition _unfinishedCondition
-
_unfinishedFutures
protected java.util.Set<java.util.concurrent.Future<?>> _unfinishedFutures
-
_shutdown
protected java.util.concurrent.atomic.AtomicBoolean _shutdown
-
-
Constructor Detail
-
ExecutionService
public ExecutionService()
-
ExecutionService
public ExecutionService(JChannel ch)
-
-
Method Detail
-
setChannel
public void setChannel(JChannel ch)
-
submit
public <T> NotifyingFuture<T> submit(java.lang.Runnable task, T result)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService
-
submit
public <T> NotifyingFuture<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.AbstractExecutorService
-
shutdown
public void shutdown()
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
-
isShutdown
public boolean isShutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException- Specified by:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAnyin classjava.util.concurrent.AbstractExecutorService- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException- Specified by:
invokeAnyin interfacejava.util.concurrent.ExecutorService- Overrides:
invokeAnyin classjava.util.concurrent.AbstractExecutorService- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
execute
public void execute(java.lang.Runnable command)
-
newTaskFor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.lang.Runnable runnable, T value)- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
-