Infinispan Distribution 5.2.6.Final-redhat-2

org.infinispan.distexec
Class DefaultExecutorService

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by org.infinispan.distexec.DefaultExecutorService
All Implemented Interfaces:
Executor, ExecutorService, DistributedExecutorService

public class DefaultExecutorService
extends AbstractExecutorService
implements DistributedExecutorService

Infinispan's implementation of an 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.

Since:
5.0
Author:
Vladimir Blagojevic

Field Summary
protected  AdvancedCache cache
           
protected  CancellationService cancellationService
           
protected  CommandsFactory factory
           
protected  InterceptorChain invoker
           
protected  AtomicBoolean isShutdown
           
static Address LOCAL_MODE_ADDRESS
           
protected  ExecutorService localExecutorService
           
protected  Marshaller marshaller
           
static DistributedTaskFailoverPolicy NO_FAILOVER
           
static DistributedTaskFailoverPolicy RANDOM_NODE_FAILOVER
           
protected  RpcManager rpc
           
protected  boolean takeExecutorOwnership
           
 
Constructor Summary
DefaultExecutorService(Cache<?,?> masterCacheNode)
          Creates a new DefaultExecutorService given a master cache node for local task execution.
DefaultExecutorService(Cache<?,?> masterCacheNode, 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, 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.
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
           
protected
<T> Callable<T>
clone(Callable<T> task)
           
<T> DistributedTaskBuilder<T>
createDistributedTaskBuilder(Callable<T> callable)
          Returns DistributedTaskBuilder for this DistributedExecutorService and a given Callable.
protected
<T,K> org.infinispan.distexec.DefaultExecutorService.DistributedTaskPart<T>
createDistributedTaskPart(DistributedTask<T> task, DistributedExecuteCommand<T> c, Address target, int failoverCount)
           
protected
<T,K> org.infinispan.distexec.DefaultExecutorService.DistributedTaskPart<T>
createDistributedTaskPart(DistributedTask<T> task, DistributedExecuteCommand<T> c, List<K> inputKeys, Address target, int failoverCount)
           
 void execute(Runnable command)
           
protected
<T> List<Address>
executionCandidates(DistributedTask<T> task)
           
protected  List<Address> getMembers()
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
           
 boolean isShutdown()
           
 boolean isTerminated()
           
protected
<K> Map<Address,List<K>>
keysToExecutionNodes(DistributedTaskExecutionPolicy policy, K... input)
           
protected
<T> RunnableFuture<T>
newTaskFor(Callable<T> callable)
           
protected
<T> RunnableFuture<T>
newTaskFor(Runnable runnable, T value)
           
protected  List<Address> randomClusterMembers(List<Address> members, int numNeeded)
           
protected
<T> Address
selectExecutionNode(DistributedTask<T> task)
           
protected  Address selectExecutionNode(List<Address> candidates)
           
 void shutdown()
           
 List<Runnable> shutdownNow()
           
<T> Future<T>
submit(Address target, Callable<T> task)
          Submits the given Callable task for execution on the specified target Infinispan node.
<T> Future<T>
submit(Address target, DistributedTask<T> task)
          Submits the given DistributedTask for execution on the specified target Infinispan node.
<T> NotifyingFuture<T>
submit(Callable<T> task)
           
<T,K> Future<T>
submit(Callable<T> task, K... input)
          Submits the given Callable task for execution on a single Infinispan node.
<T,K> Future<T>
submit(DistributedTask<T> task, K... input)
          Submits the given DistributedTask for execution on a single Infinispan node.
<T> NotifyingFuture<T>
submit(Runnable task, T result)
           
<T> List<Future<T>>
submitEverywhere(Callable<T> task)
          Submits the given Callable task for execution on all available Infinispan nodes.
<T,K> List<Future<T>>
submitEverywhere(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> List<Future<T>>
submitEverywhere(DistributedTask<T> task)
          Submits the given DistributedTask for execution on all available Infinispan nodes.
<T,K> List<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.
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, submit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.ExecutorService
invokeAll, invokeAll, submit
 

Field Detail

LOCAL_MODE_ADDRESS

public static final Address LOCAL_MODE_ADDRESS

NO_FAILOVER

public static final DistributedTaskFailoverPolicy NO_FAILOVER

RANDOM_NODE_FAILOVER

public static final DistributedTaskFailoverPolicy RANDOM_NODE_FAILOVER

isShutdown

protected final AtomicBoolean isShutdown

cache

protected final AdvancedCache cache

rpc

protected final RpcManager rpc

invoker

protected final InterceptorChain invoker

factory

protected final CommandsFactory factory

marshaller

protected final Marshaller marshaller

localExecutorService

protected final ExecutorService localExecutorService

cancellationService

protected final CancellationService cancellationService

takeExecutorOwnership

protected final boolean takeExecutorOwnership
Constructor Detail

DefaultExecutorService

public DefaultExecutorService(Cache<?,?> masterCacheNode)
Creates a new DefaultExecutorService given a master cache node for local task execution. All distributed task executions will be initiated from this Infinispan cache node

Parameters:
masterCacheNode - Cache node initiating distributed task

DefaultExecutorService

public DefaultExecutorService(Cache<?,?> masterCacheNode,
                              ExecutorService localExecutorService)
Creates a new DefaultExecutorService given a master cache node and an ExecutorService for parallel execution of tasks ran on this node. All distributed task executions will be initiated from this Infinispan cache node.

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)

Parameters:
masterCacheNode - Cache node initiating distributed task
localExecutorService - ExecutorService to run local tasks

DefaultExecutorService

public DefaultExecutorService(Cache<?,?> masterCacheNode,
                              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. All distributed task executions will be initiated from this Infinispan cache node.

Parameters:
masterCacheNode - Cache node initiating distributed task
localExecutorService - ExecutorService to run local tasks
takeExecutorOwnership - if true ExecutorService.shutdown() and ExecutorService.shutdownNow() method will shutdown localExecutorService as well
Method Detail

createDistributedTaskBuilder

public <T> DistributedTaskBuilder<T> createDistributedTaskBuilder(Callable<T> callable)
Description copied from interface: DistributedExecutorService
Returns DistributedTaskBuilder for this DistributedExecutorService and a given Callable. As it name implies clients can use DistributedTaskBuilder to create DistributedTask instances.

Specified by:
createDistributedTaskBuilder in interface DistributedExecutorService
Parameters:
callable - the execution unit of DistributedTask
Returns:
DistributedTaskBuilder to create DistributedTask

submit

public <T> NotifyingFuture<T> submit(Runnable task,
                                     T result)
Specified by:
submit in interface ExecutorService
Overrides:
submit in class AbstractExecutorService

submit

public <T> NotifyingFuture<T> submit(Callable<T> task)
Specified by:
submit in interface ExecutorService
Overrides:
submit in class AbstractExecutorService

shutdown

public void shutdown()
Specified by:
shutdown in interface ExecutorService

getMembers

protected List<Address> getMembers()

executionCandidates

protected <T> List<Address> executionCandidates(DistributedTask<T> task)

shutdownNow

public List<Runnable> shutdownNow()
Specified by:
shutdownNow in interface ExecutorService

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface ExecutorService

isTerminated

public boolean isTerminated()
Specified by:
isTerminated in interface ExecutorService

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
Specified by:
awaitTermination in interface ExecutorService
Throws:
InterruptedException

invokeAny

public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
            throws InterruptedException,
                   ExecutionException
Specified by:
invokeAny in interface ExecutorService
Overrides:
invokeAny in class AbstractExecutorService
Throws:
InterruptedException
ExecutionException

invokeAny

public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
                       long timeout,
                       TimeUnit unit)
            throws InterruptedException,
                   ExecutionException,
                   TimeoutException
Specified by:
invokeAny in interface ExecutorService
Overrides:
invokeAny in class AbstractExecutorService
Throws:
InterruptedException
ExecutionException
TimeoutException

execute

public void execute(Runnable command)
Specified by:
execute in interface Executor

newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Runnable runnable,
                                           T value)
Overrides:
newTaskFor in class AbstractExecutorService

newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
Overrides:
newTaskFor in class AbstractExecutorService

submit

public <T> Future<T> submit(Address target,
                            Callable<T> task)
Description copied from interface: DistributedExecutorService
Submits the given Callable task for execution on the specified target Infinispan node.

Specified by:
submit in interface DistributedExecutorService
Parameters:
target - address of Infinispan node selected for execution of the task
task - a task to execute on selected Infinispan node
Returns:
a Future representing pending completion of the task

submit

public <T> Future<T> submit(Address target,
                            DistributedTask<T> task)
Description copied from interface: DistributedExecutorService
Submits the given DistributedTask for execution on the specified target Infinispan node.

Specified by:
submit in interface DistributedExecutorService
Parameters:
target - address of Infinispan node selected for execution of the task
task - a task to execute on selected Infinispan node
Returns:
a Future representing pending completion of the task

submit

public <T,K> Future<T> submit(Callable<T> task,
                              K... input)
Description copied from interface: DistributedExecutorService
Submits the given Callable task for execution on a single Infinispan node.

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.

Specified by:
submit in interface DistributedExecutorService
Parameters:
task - a task to execute across Infinispan cluster
input - input keys for this task, effective if and only if task is instance of DistributedCallable
Returns:
a Future representing pending completion of the task

submit

public <T,K> Future<T> submit(DistributedTask<T> task,
                              K... input)
Description copied from interface: DistributedExecutorService
Submits the given DistributedTask for execution on a single Infinispan node.

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.

Specified by:
submit in interface DistributedExecutorService
Parameters:
task - a DistributedTask to execute across Infinispan cluster
input - input keys for this task, effective if and only if task's callable is instance of DistributedCallable
Returns:
a Future representing pending completion of the task

submitEverywhere

public <T> List<Future<T>> submitEverywhere(Callable<T> task)
Description copied from interface: DistributedExecutorService
Submits the given Callable task for execution on all available Infinispan nodes.

Specified by:
submitEverywhere in interface DistributedExecutorService
Parameters:
task - a task to execute across Infinispan cluster
Returns:
a list of Futures, one future per Infinispan cluster node where task was executed

submitEverywhere

public <T> List<Future<T>> submitEverywhere(DistributedTask<T> task)
Description copied from interface: DistributedExecutorService
Submits the given DistributedTask for execution on all available Infinispan nodes.

Specified by:
submitEverywhere in interface DistributedExecutorService
Parameters:
task - a task to execute across Infinispan cluster
Returns:
a list of Futures, one future per Infinispan cluster node where task was executed

submitEverywhere

public <T,K> List<Future<T>> submitEverywhere(Callable<T> task,
                                              K... input)
Description copied from interface: DistributedExecutorService
Submits the given Callable task for execution on all available Infinispan nodes using input keys specified by K input.

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

Specified by:
submitEverywhere in interface DistributedExecutorService
Parameters:
task - a task to execute across Infinispan cluster
input - input keys for this task, effective if and only if task is instance of DistributedCallable
Returns:
a list of Futures, one future per Infinispan cluster node where task was executed

submitEverywhere

public <T,K> List<Future<T>> submitEverywhere(DistributedTask<T> task,
                                              K... input)
Description copied from interface: DistributedExecutorService
Submits the given DistributedTask for execution on all available Infinispan nodes using input keys specified by K input.

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

Specified by:
submitEverywhere in interface DistributedExecutorService
Parameters:
task - a task to execute across Infinispan cluster
input - input keys for this task, effective if and only if task is instance of DistributedCallable
Returns:
a list of Futures, one future per Infinispan cluster node where task was executed

clone

protected <T> Callable<T> clone(Callable<T> task)

createDistributedTaskPart

protected <T,K> org.infinispan.distexec.DefaultExecutorService.DistributedTaskPart<T> createDistributedTaskPart(DistributedTask<T> task,
                                                                                                                DistributedExecuteCommand<T> c,
                                                                                                                List<K> inputKeys,
                                                                                                                Address target,
                                                                                                                int failoverCount)

createDistributedTaskPart

protected <T,K> org.infinispan.distexec.DefaultExecutorService.DistributedTaskPart<T> createDistributedTaskPart(DistributedTask<T> task,
                                                                                                                DistributedExecuteCommand<T> c,
                                                                                                                Address target,
                                                                                                                int failoverCount)

selectExecutionNode

protected Address selectExecutionNode(List<Address> candidates)

selectExecutionNode

protected <T> Address selectExecutionNode(DistributedTask<T> task)

randomClusterMembers

protected List<Address> randomClusterMembers(List<Address> members,
                                             int numNeeded)

keysToExecutionNodes

protected <K> Map<Address,List<K>> keysToExecutionNodes(DistributedTaskExecutionPolicy policy,
                                                        K... input)

Infinispan Distribution 5.2.6.Final-redhat-2

Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.