Class AwaitableExecutorService
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.util.concurrent.ForwardingExecutorService
-
- org.opendaylight.infrautils.testutils.concurrent.AwaitableExecutorService
-
- All Implemented Interfaces:
Executor
,ExecutorService
public class AwaitableExecutorService extends com.google.common.util.concurrent.ForwardingExecutorService
Executable service wrapper allowing callers to await completion.
-
-
Constructor Summary
Constructors Constructor Description AwaitableExecutorService(ExecutorService delegate)
Create a new wrapper for the givenExecutorService
, adding the ability to wait for job completion.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitCompletion(long timeout, TimeUnit unit)
Wait for completion: this method will wait until all submitted jobs have completed, subject to the provided timeout.protected ExecutorService
delegate()
void
execute(Runnable command)
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
boolean
isCompleted()
Indicates whether all submitted jobs have completed.Future<?>
submit(Runnable task)
<T> Future<T>
submit(Runnable task, T result)
<T> Future<T>
submit(Callable<T> task)
-
-
-
Constructor Detail
-
AwaitableExecutorService
public AwaitableExecutorService(ExecutorService delegate)
Create a new wrapper for the givenExecutorService
, adding the ability to wait for job completion.- Parameters:
delegate
- The executor service to wrap.
-
-
Method Detail
-
delegate
protected ExecutorService delegate()
- Specified by:
delegate
in classcom.google.common.util.concurrent.ForwardingExecutorService
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.ForwardingExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.ForwardingExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
- Overrides:
submit
in classcom.google.common.util.concurrent.ForwardingExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Overrides:
invokeAll
in classcom.google.common.util.concurrent.ForwardingExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Overrides:
invokeAll
in classcom.google.common.util.concurrent.ForwardingExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Overrides:
invokeAny
in classcom.google.common.util.concurrent.ForwardingExecutorService
- 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 interfaceExecutorService
- Overrides:
invokeAny
in classcom.google.common.util.concurrent.ForwardingExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
execute
public void execute(Runnable command)
-
awaitCompletion
public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
Wait for completion: this method will wait until all submitted jobs have completed, subject to the provided timeout. This is inherently racy if external job submission is continuing; if the submitted jobs themselves submit new jobs, this will wait for those newly-submitted jobs to complete too.- Parameters:
timeout
- The maximum time to wait.unit
- The unit used for the timeout.- Returns:
true
if the submitted jobs have completed,false
if they haven’t.- Throws:
InterruptedException
-
isCompleted
public boolean isCompleted()
Indicates whether all submitted jobs have completed.- Returns:
true
if all submitted jobs have completed,false
otherwise.
-
-