public class DefaultExecutorService extends java.util.concurrent.AbstractExecutorService implements DistributedExecutorService
ExecutorService
and DistributedExecutorService
.
This ExecutorService provides methods to submit tasks for an execution on a cluster of Infinispan
nodes.
Note that due to potential task migration to another nodes every Callable
,
Runnable
and/or DistributedCallable
submitted must be either Serializable
or Externalizable
. Also the value returned from a callable must be Serializable
or Externalizable
. Unfortunately if the value returned is not serializable then a
NotSerializableException
will be thrown.
Modifier and Type | Class and Description |
---|---|
private class |
DefaultExecutorService.DefaultDistributedTaskBuilder<T> |
private class |
DefaultExecutorService.DistributedTaskPart<V>
DistributedTaskPart represents a unit of work sent to remote VM and executed there
|
(package private) static interface |
DefaultExecutorService.NodeFilter
NodeFilter allows selection of nodes according to
DistributedTaskExecutionPolicy |
private static class |
DefaultExecutorService.NoTaskFailoverPolicy |
private static class |
DefaultExecutorService.RandomNodeTaskFailoverPolicy |
private static class |
DefaultExecutorService.RunnableAdapter<T> |
Modifier and Type | Field and Description |
---|---|
private static DefaultExecutorService.NodeFilter |
ALL_FILTER |
protected AdvancedCache |
cache |
protected org.infinispan.commands.CancellationService |
cancellationService |
protected org.infinispan.interceptors.locking.ClusteringDependentLogic |
clusterDependentLogic |
protected org.infinispan.commands.CommandsFactory |
factory |
protected org.infinispan.interceptors.InterceptorChain |
invoker |
protected java.util.concurrent.atomic.AtomicBoolean |
isShutdown |
protected java.util.concurrent.ExecutorService |
localExecutorService |
private static org.infinispan.util.logging.Log |
log |
protected Marshaller |
marshaller |
static DistributedTaskFailoverPolicy |
NO_FAILOVER |
static DistributedTaskFailoverPolicy |
RANDOM_NODE_FAILOVER |
protected org.infinispan.remoting.rpc.RpcManager |
rpc |
private static DefaultExecutorService.NodeFilter |
SAME_MACHINE_FILTER |
private static DefaultExecutorService.NodeFilter |
SAME_RACK_FILTER |
private static DefaultExecutorService.NodeFilter |
SAME_SITE_FILTER |
protected boolean |
takeExecutorOwnership |
private org.infinispan.util.TimeService |
timeService |
private static boolean |
trace |
Constructor and Description |
---|
DefaultExecutorService(Cache<?,?> masterCacheNode)
Creates a new DefaultExecutorService given a master cache node for local task execution.
|
DefaultExecutorService(Cache<?,?> masterCacheNode,
java.util.concurrent.ExecutorService localExecutorService)
Creates a new DefaultExecutorService given a master cache node and an ExecutorService for
parallel execution of tasks ran on this node.
|
DefaultExecutorService(Cache<?,?> masterCacheNode,
java.util.concurrent.ExecutorService localExecutorService,
boolean takeExecutorOwnership)
Creates a new DefaultExecutorService given a master cache node and an ExecutorService for
parallel execution of task ran on this node.
|
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
private <T,K> void |
checkExecutionPolicy(DistributedTask<T> task,
java.util.Map<org.infinispan.remoting.transport.Address,java.util.List<K>> nodesKeysMap,
K... input) |
protected <T> java.util.concurrent.Callable<T> |
clone(java.util.concurrent.Callable<T> task) |
<T> DistributedTaskBuilder<T> |
createDistributedTaskBuilder(java.util.concurrent.Callable<T> callable)
Returns DistributedTaskBuilder for this DistributedExecutorService and a given Callable.
|
protected <T,K> DefaultExecutorService.DistributedTaskPart<T> |
createDistributedTaskPart(DistributedTask<T> task,
org.infinispan.commands.read.DistributedExecuteCommand<T> c,
org.infinispan.remoting.transport.Address target,
int failoverCount) |
protected <T,K> DefaultExecutorService.DistributedTaskPart<T> |
createDistributedTaskPart(DistributedTask<T> task,
org.infinispan.commands.read.DistributedExecuteCommand<T> c,
java.util.List<K> inputKeys,
org.infinispan.remoting.transport.Address target,
int failoverCount) |
private <T> T |
doInvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
boolean timed,
long nanos)
the main mechanics of invokeAny.
|
private void |
ensureProperCacheState(AdvancedCache<?,?> cache) |
void |
execute(java.lang.Runnable command) |
protected <T> java.util.List<org.infinispan.remoting.transport.Address> |
executionCandidates(DistributedTask<T> task) |
private java.util.List<org.infinispan.remoting.transport.Address> |
filterMembers(DistributedTaskExecutionPolicy policy,
java.util.List<org.infinispan.remoting.transport.Address> members) |
private org.infinispan.remoting.transport.Address |
getAddress() |
protected java.util.List<org.infinispan.remoting.transport.Address> |
getMembers() |
private <K> boolean |
inputKeysSpecified(K... input) |
<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 <K> java.util.Map<org.infinispan.remoting.transport.Address,java.util.List<K>> |
keysToExecutionNodes(DistributedTaskExecutionPolicy policy,
K... input) |
protected <T> java.util.concurrent.RunnableFuture<T> |
newTaskFor(java.util.concurrent.Callable<T> callable) |
protected <T> java.util.concurrent.RunnableFuture<T> |
newTaskFor(java.lang.Runnable runnable,
T value) |
protected java.util.List<org.infinispan.remoting.transport.Address> |
randomClusterMembers(java.util.List<org.infinispan.remoting.transport.Address> members,
int numNeeded) |
private java.util.List<java.lang.Runnable> |
realShutdown(boolean interrupt) |
protected <T> org.infinispan.remoting.transport.Address |
selectExecutionNode(DistributedTask<T> task) |
protected org.infinispan.remoting.transport.Address |
selectExecutionNode(java.util.List<org.infinispan.remoting.transport.Address> candidates) |
void |
shutdown() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
<T> java.util.concurrent.Future<T> |
submit(org.infinispan.remoting.transport.Address target,
java.util.concurrent.Callable<T> task)
Submits the given Callable task for execution on the specified target Infinispan node.
|
<T> java.util.concurrent.Future<T> |
submit(org.infinispan.remoting.transport.Address target,
DistributedTask<T> task)
Submits the given DistributedTask for execution on the specified target Infinispan node.
|
<T> |
submit(java.util.concurrent.Callable<T> task) |
<T,K> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task,
K... input)
Submits the given Callable task for execution on a single Infinispan node.
|
<T,K> java.util.concurrent.Future<T> |
submit(DistributedTask<T> task,
K... input)
Submits the given DistributedTask for execution on a single Infinispan node.
|
<T> |
submit(java.lang.Runnable task,
T result) |
<T> java.util.List<java.util.concurrent.Future<T>> |
submitEverywhere(java.util.concurrent.Callable<T> task)
Submits the given Callable task for execution on all available Infinispan nodes.
|
<T,K> java.util.List<java.util.concurrent.Future<T>> |
submitEverywhere(java.util.concurrent.Callable<T> task,
K... input)
Submits the given Callable task for execution on all available Infinispan nodes using input
keys specified by K input.
|
<T> java.util.List<java.util.concurrent.Future<T>> |
submitEverywhere(DistributedTask<T> task)
Submits the given DistributedTask for execution on all available Infinispan nodes.
|
<T,K> java.util.List<java.util.concurrent.Future<T>> |
submitEverywhere(DistributedTask<T> task,
K... input)
Submits the given DistributedTask for execution on all available Infinispan nodes using input
keys specified by K input.
|
invokeAll, invokeAll, submit
private static final DefaultExecutorService.NodeFilter SAME_MACHINE_FILTER
private static final DefaultExecutorService.NodeFilter SAME_RACK_FILTER
private static final DefaultExecutorService.NodeFilter SAME_SITE_FILTER
private static final DefaultExecutorService.NodeFilter ALL_FILTER
public static final DistributedTaskFailoverPolicy NO_FAILOVER
public static final DistributedTaskFailoverPolicy RANDOM_NODE_FAILOVER
private static final org.infinispan.util.logging.Log log
private static final boolean trace
protected final java.util.concurrent.atomic.AtomicBoolean isShutdown
protected final AdvancedCache cache
protected final org.infinispan.remoting.rpc.RpcManager rpc
protected final org.infinispan.interceptors.InterceptorChain invoker
protected final org.infinispan.commands.CommandsFactory factory
protected final Marshaller marshaller
protected final java.util.concurrent.ExecutorService localExecutorService
protected final org.infinispan.commands.CancellationService cancellationService
protected final org.infinispan.interceptors.locking.ClusteringDependentLogic clusterDependentLogic
protected final boolean takeExecutorOwnership
private final org.infinispan.util.TimeService timeService
public DefaultExecutorService(Cache<?,?> masterCacheNode)
masterCacheNode
- Cache node initiating distributed taskpublic DefaultExecutorService(Cache<?,?> masterCacheNode, java.util.concurrent.ExecutorService localExecutorService)
Note that DefaultExecutorService will not shutdown client supplied localExecutorService once
this DefaultExecutorService is shutdown. Lifecycle management of a supplied ExecutorService is
left to the client
Also note that client supplied ExecutorService should not execute tasks in the caller's thread
( i.e rejectionHandler of ThreadPoolExecutor
configured with {link
ThreadPoolExecutor.CallerRunsPolicy
)
masterCacheNode
- Cache node initiating distributed tasklocalExecutorService
- ExecutorService to run local taskspublic DefaultExecutorService(Cache<?,?> masterCacheNode, java.util.concurrent.ExecutorService localExecutorService, boolean takeExecutorOwnership)
masterCacheNode
- Cache node initiating distributed tasklocalExecutorService
- ExecutorService to run local taskstakeExecutorOwnership
- if true ExecutorService.shutdown()
and
ExecutorService.shutdownNow()
method will shutdown
localExecutorService as wellpublic <T> DistributedTaskBuilder<T> createDistributedTaskBuilder(java.util.concurrent.Callable<T> callable)
DistributedExecutorService
createDistributedTaskBuilder
in interface DistributedExecutorService
callable
- the execution unit of DistributedTaskDistributedTask
public <T>submit(java.lang.Runnable task, T result)
submit
in interface java.util.concurrent.ExecutorService
submit
in class java.util.concurrent.AbstractExecutorService
public <T>submit(java.util.concurrent.Callable<T> task)
submit
in interface java.util.concurrent.ExecutorService
submit
in class java.util.concurrent.AbstractExecutorService
public void shutdown()
shutdown
in interface java.util.concurrent.ExecutorService
protected java.util.List<org.infinispan.remoting.transport.Address> getMembers()
protected <T> java.util.List<org.infinispan.remoting.transport.Address> executionCandidates(DistributedTask<T> task)
private org.infinispan.remoting.transport.Address getAddress()
private java.util.List<java.lang.Runnable> realShutdown(boolean interrupt)
public java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow
in interface java.util.concurrent.ExecutorService
public boolean isShutdown()
isShutdown
in interface java.util.concurrent.ExecutorService
public boolean isTerminated()
isTerminated
in interface java.util.concurrent.ExecutorService
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
awaitTermination
in interface java.util.concurrent.ExecutorService
java.lang.InterruptedException
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
invokeAny
in interface java.util.concurrent.ExecutorService
invokeAny
in class java.util.concurrent.AbstractExecutorService
java.lang.InterruptedException
java.util.concurrent.ExecutionException
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
invokeAny
in interface java.util.concurrent.ExecutorService
invokeAny
in class java.util.concurrent.AbstractExecutorService
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
private <T> T doInvokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, boolean timed, long nanos) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
AbstractExecutorService
doInvokeAny except that we replaced the
ExecutorCompletionService
with our DistributedExecutionCompletionService
.java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
public void execute(java.lang.Runnable command)
execute
in interface java.util.concurrent.Executor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.lang.Runnable runnable, T value)
newTaskFor
in class java.util.concurrent.AbstractExecutorService
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
newTaskFor
in class java.util.concurrent.AbstractExecutorService
public <T> java.util.concurrent.Future<T> submit(org.infinispan.remoting.transport.Address target, java.util.concurrent.Callable<T> task)
DistributedExecutorService
submit
in interface DistributedExecutorService
target
- address of Infinispan node selected for execution of the tasktask
- a task to execute on selected Infinispan nodepublic <T> java.util.concurrent.Future<T> submit(org.infinispan.remoting.transport.Address target, DistributedTask<T> task)
DistributedExecutorService
submit
in interface DistributedExecutorService
target
- address of Infinispan node selected for execution of the tasktask
- a task to execute on selected Infinispan nodepublic <T,K> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task, K... input)
DistributedExecutorService
Execution environment will chose an arbitrary node N hosting some or all of the keys specified as input. If all keys are not available locally at node N they will be retrieved from the cluster.
submit
in interface DistributedExecutorService
task
- a task to execute across Infinispan clusterinput
- input keys for this task, effective if and only if task is instance of DistributedCallable
public <T,K> java.util.concurrent.Future<T> submit(DistributedTask<T> task, K... input)
DistributedExecutorService
Execution environment will chose an arbitrary node N hosting some or all of the keys specified as input. If all keys are not available locally at node N they will be retrieved from the cluster.
submit
in interface DistributedExecutorService
task
- a DistributedTask to execute across Infinispan clusterinput
- input keys for this task, effective if and only if task's callable is instance of
DistributedCallable
public <T> java.util.List<java.util.concurrent.Future<T>> submitEverywhere(java.util.concurrent.Callable<T> task)
DistributedExecutorService
submitEverywhere
in interface DistributedExecutorService
task
- a task to execute across Infinispan clusterpublic <T> java.util.List<java.util.concurrent.Future<T>> submitEverywhere(DistributedTask<T> task)
DistributedExecutorService
submitEverywhere
in interface DistributedExecutorService
task
- a task to execute across Infinispan clusterpublic <T,K> java.util.List<java.util.concurrent.Future<T>> submitEverywhere(java.util.concurrent.Callable<T> task, K... input)
DistributedExecutorService
Execution environment will chose all nodes in Infinispan cluster where input keys are local, migrate given Callable instance to those nodes, execute it and return result as a list of Futures
submitEverywhere
in interface DistributedExecutorService
task
- a task to execute across Infinispan clusterinput
- input keys for this task, effective if and only if task is instance of DistributedCallable
public <T,K> java.util.List<java.util.concurrent.Future<T>> submitEverywhere(DistributedTask<T> task, K... input)
DistributedExecutorService
Execution environment will chose all nodes in Infinispan cluster where input keys are local, migrate given Callable instance to those nodes, execute it and return result as a list of Futures
submitEverywhere
in interface DistributedExecutorService
task
- a task to execute across Infinispan clusterinput
- input keys for this task, effective if and only if task is instance of DistributedCallable
protected <T> java.util.concurrent.Callable<T> clone(java.util.concurrent.Callable<T> task)
protected <T,K> DefaultExecutorService.DistributedTaskPart<T> createDistributedTaskPart(DistributedTask<T> task, org.infinispan.commands.read.DistributedExecuteCommand<T> c, java.util.List<K> inputKeys, org.infinispan.remoting.transport.Address target, int failoverCount)
protected <T,K> DefaultExecutorService.DistributedTaskPart<T> createDistributedTaskPart(DistributedTask<T> task, org.infinispan.commands.read.DistributedExecuteCommand<T> c, org.infinispan.remoting.transport.Address target, int failoverCount)
private <T,K> void checkExecutionPolicy(DistributedTask<T> task, java.util.Map<org.infinispan.remoting.transport.Address,java.util.List<K>> nodesKeysMap, K... input)
private <K> boolean inputKeysSpecified(K... input)
protected org.infinispan.remoting.transport.Address selectExecutionNode(java.util.List<org.infinispan.remoting.transport.Address> candidates)
protected <T> org.infinispan.remoting.transport.Address selectExecutionNode(DistributedTask<T> task)
protected java.util.List<org.infinispan.remoting.transport.Address> randomClusterMembers(java.util.List<org.infinispan.remoting.transport.Address> members, int numNeeded)
protected <K> java.util.Map<org.infinispan.remoting.transport.Address,java.util.List<K>> keysToExecutionNodes(DistributedTaskExecutionPolicy policy, K... input)
private java.util.List<org.infinispan.remoting.transport.Address> filterMembers(DistributedTaskExecutionPolicy policy, java.util.List<org.infinispan.remoting.transport.Address> members)
private void ensureProperCacheState(AdvancedCache<?,?> cache) throws java.lang.NullPointerException, java.lang.IllegalStateException
java.lang.NullPointerException
java.lang.IllegalStateException