org.drools.concurrent
Class ExternalExecutorService

java.lang.Object
  extended by org.drools.concurrent.ExternalExecutorService
All Implemented Interfaces:
Executor, ExecutorService

public class ExternalExecutorService
extends Object
implements ExecutorService

This class wraps up an externally managed executor service, meaning that the life cycle of the service is not managed by Drools. So, we intercept calls to shutdown() and shutdownNow() to not shutdown the external pool. Also, we need to maintain a list of tasks submitted to the external pool, so that they can be properly cancelled on a shutdown.


Nested Class Summary
protected static class ExternalExecutorService.ObservableCallable<V>
          This class is a wrapper around a Callable task that will notify a listener when the task starts executing and when it finishes executing.
protected static class ExternalExecutorService.ObservableRunnable
          This class is a wrapper around a Runnable task that will notify a listener when the task starts executing and when it finishes executing.
protected static interface ExternalExecutorService.ObservableTask
          A super interface for ObservableTasks
protected static class ExternalExecutorService.TaskManager
          An implementation of the TaskObserver interface that keeps a map of submitted, but not executed tasks.
protected static interface ExternalExecutorService.TaskObserver
          Interface that defines the methods to be implemented by a task observer.
 
Constructor Summary
ExternalExecutorService(ExecutorService delegate)
           
 
Method Summary
 boolean awaitTermination(long timeout, TimeUnit unit)
          Always returns true, if a shutdown was requested, since the life cycle of this executor is externally maintained.
 void execute(Runnable command)
          
 List invokeAll(Collection tasks)
          
 List invokeAll(Collection tasks, long timeout, TimeUnit unit)
          
 Object invokeAny(Collection tasks)
          
 Object invokeAny(Collection tasks, long timeout, TimeUnit unit)
          
 boolean isShutdown()
          
 boolean isTerminated()
          
 void shutdown()
          
 List<Runnable> shutdownNow()
          
<T> Future<T>
submit(Callable<T> task)
          
 Future<?> submit(Runnable task)
          
<T> Future<T>
submit(Runnable task, T result)
          
 void waitUntilEmpty()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExternalExecutorService

public ExternalExecutorService(ExecutorService delegate)
Method Detail

waitUntilEmpty

public void waitUntilEmpty()

awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
Always returns true, if a shutdown was requested, since the life cycle of this executor is externally maintained.

Specified by:
awaitTermination in interface ExecutorService
Throws:
InterruptedException

execute

public void execute(Runnable command)

Specified by:
execute in interface Executor

invokeAll

public List invokeAll(Collection tasks,
                      long timeout,
                      TimeUnit unit)
               throws InterruptedException

Specified by:
invokeAll in interface ExecutorService
Throws:
InterruptedException

invokeAll

public List invokeAll(Collection tasks)
               throws InterruptedException

Specified by:
invokeAll in interface ExecutorService
Throws:
InterruptedException

invokeAny

public Object invokeAny(Collection tasks,
                        long timeout,
                        TimeUnit unit)
                 throws InterruptedException,
                        ExecutionException,
                        TimeoutException

Specified by:
invokeAny in interface ExecutorService
Throws:
InterruptedException
ExecutionException
TimeoutException

invokeAny

public Object invokeAny(Collection tasks)
                 throws InterruptedException,
                        ExecutionException

Specified by:
invokeAny in interface ExecutorService
Throws:
InterruptedException
ExecutionException

isShutdown

public boolean isShutdown()

Specified by:
isShutdown in interface ExecutorService

isTerminated

public boolean isTerminated()

Specified by:
isTerminated in interface ExecutorService

shutdown

public void shutdown()

Specified by:
shutdown in interface ExecutorService

shutdownNow

public List<Runnable> shutdownNow()

Specified by:
shutdownNow in interface ExecutorService

submit

public <T> Future<T> submit(Callable<T> task)

Specified by:
submit in interface ExecutorService

submit

public <T> Future<T> submit(Runnable task,
                            T result)

Specified by:
submit in interface ExecutorService

submit

public Future<?> submit(Runnable task)

Specified by:
submit in interface ExecutorService


Copyright © 2001-2012 JBoss by Red Hat. All Rights Reserved.