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. 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  Cache cache
           
protected  CommandsFactory factory
           
protected  InterceptorChain invoker
           
protected  AtomicBoolean isShutdown
           
protected  RpcManager rpc
           
 
Constructor Summary
DefaultExecutorService(Cache cache)
           
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
           
 void execute(Runnable command)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
           
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
           
protected
<T> void
invokeLocally(org.infinispan.distexec.DefaultExecutorService.DistributedRunnableFuture<T> future)
           
 boolean isShutdown()
           
 boolean isTerminated()
           
protected
<K> Map<Address,List<K>>
mapKeysToNodes(K... input)
           
protected
<T> RunnableFuture<T>
newTaskFor(Callable<T> callable)
           
protected
<T> RunnableFuture<T>
newTaskFor(Runnable runnable, T value)
           
protected  Address randomClusterMemberExcludingSelf(List<Address> members)
           
protected  Address randomClusterMemberOtherThanSelf()
           
protected  List<Address> randomClusterMembers(int numNeeded)
           
protected  List<Address> randomClusterMembers(List<Address> members, int numNeeded)
           
protected
<T> void
sendForRemoteExecution(Address address, org.infinispan.distexec.DefaultExecutorService.DistributedRunnableFuture<T> f)
           
 void shutdown()
           
 List<Runnable> shutdownNow()
           
<T> NotifyingFuture<T>
submit(Callable<T> task)
           
<T,K> Future<T>
submit(Callable<T> task, K... input)
          Submits given Callable task for an 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 an execution on all available Infinispan nodes.
<T,K> List<Future<T>>
submitEverywhere(Callable<T> task, K... input)
          Submits the given Callable task for an 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

isShutdown

protected final AtomicBoolean isShutdown

cache

protected final Cache cache

rpc

protected final RpcManager rpc

invoker

protected final InterceptorChain invoker

factory

protected final CommandsFactory factory
Constructor Detail

DefaultExecutorService

public DefaultExecutorService(Cache cache)
Method Detail

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

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,K> Future<T> submit(Callable<T> task,
                              K... input)
Description copied from interface: DistributedExecutorService
Submits given Callable task for an 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
Returns:

submitEverywhere

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

Specified by:
submitEverywhere in interface DistributedExecutorService
Returns:

submitEverywhere

public <T,K> List<Future<T>> submitEverywhere(Callable<T> task,
                                              K... input)
Description copied from interface: DistributedExecutorService
Submits the given Callable task for an 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
Returns:

sendForRemoteExecution

protected <T> void sendForRemoteExecution(Address address,
                                          org.infinispan.distexec.DefaultExecutorService.DistributedRunnableFuture<T> f)

invokeLocally

protected <T> void invokeLocally(org.infinispan.distexec.DefaultExecutorService.DistributedRunnableFuture<T> future)

mapKeysToNodes

protected <K> Map<Address,List<K>> mapKeysToNodes(K... input)

randomClusterMembers

protected List<Address> randomClusterMembers(int numNeeded)

randomClusterMemberExcludingSelf

protected Address randomClusterMemberExcludingSelf(List<Address> members)

randomClusterMemberOtherThanSelf

protected Address randomClusterMemberOtherThanSelf()

randomClusterMembers

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

-->

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