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.AbstractExecutorService
This is a JGroups implementation of an ExecutorService, where the consumers are running on any number of nodes. The nodes should runExecutionRunner
to start picking up requests.Every future object returned will be a
NotifyingFuture
which 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
Serializable
orStreamable
. Also the value returned from a callable mustSerializable
orStreamable
. Unfortunately if the value returned is not serializable then aNotSerializableException
will be thrown as the cause.- Since:
- 2.12.0
- Author:
- wburns
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExecutionService.DistributedFuture<V>
This is basically a copy of the FutureTask in java.util.concurrent but added serializable to it.protected static class
ExecutionService.RunnableAdapter<T>
This is copied fromExecutors
class which contains RunnableAdapter.
-
Field Summary
Fields Modifier and Type Field Description protected Executing
_execProt
protected java.util.concurrent.atomic.AtomicBoolean
_shutdown
protected java.util.concurrent.locks.Condition
_unfinishedCondition
protected java.util.Set<java.util.concurrent.Future<?>>
_unfinishedFutures
protected java.util.concurrent.locks.Lock
_unfinishedLock
protected JChannel
ch
-
Constructor Summary
Constructors Constructor Description ExecutionService()
ExecutionService(JChannel ch)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
void
execute(java.lang.Runnable command)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
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)
void
setChannel(JChannel ch)
void
shutdown()
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:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.util.concurrent.AbstractExecutorService
-
submit
public <T> NotifyingFuture<T> submit(java.util.concurrent.Callable<T> task)
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in 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:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.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:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Overrides:
invokeAny
in classjava.util.concurrent.AbstractExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.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:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
-