Class DelegatingExecutorService
- java.lang.Object
-
- nl.talsmasoftware.context.delegation.Wrapper<ExecutorService>
-
- nl.talsmasoftware.context.delegation.DelegatingExecutorService
-
- All Implemented Interfaces:
Executor,ExecutorService
- Direct Known Subclasses:
CallMappingExecutorService
public abstract class DelegatingExecutorService extends Wrapper<ExecutorService> implements ExecutorService
Abstract baseclass that makes it a little easier to wrap existingExecutorServiceimplementations by forwarding all methods to adelegateexecutor service.
The class also provides overridablewrappermethods for all complex input (e.g.Callable,Runnable) and result types (e.g.Future).Although this class does implements all required methods of
ExecutorServiceit is still declared as an abstract class.
This is because it does not provide any value in itself.- Author:
- Sjoerd Talsma
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDelegatingExecutorService(ExecutorService delegate)Creates a new executor service that delegates all methods to the specifieddelegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)booleanequals(Object other)voidexecute(Runnable command)inthashCode()<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> TinvokeAny(Collection<? extends Callable<T>> tasks)<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)booleanisShutdown()booleanisTerminated()voidshutdown()List<Runnable>shutdownNow()Future<?>submit(Runnable task)<T> Future<T>submit(Runnable task, T result)<T> Future<T>submit(Callable<T> task)StringtoString()protected Runnablewrap(Runnable source)protected <T> Callable<T>wrap(Callable<T> source)protected <T> Future<T>wrap(Future<T> source)protected <T> List<Future<T>>wrapFutures(Collection<? extends Future<T>> futures)Default way of mapping aCollectionofFutureobjects: Create a new list and add eachindividually wrappedobject into it.protected <T> Collection<? extends Callable<T>>wrapTasks(Collection<? extends Callable<T>> tasks)Default way of mapping aCollectionofCallableobjects: Create a new collection and add eachindividually wrappedobject into it.-
Methods inherited from class nl.talsmasoftware.context.delegation.Wrapper
delegate, nonNullDelegate
-
-
-
-
Constructor Detail
-
DelegatingExecutorService
protected DelegatingExecutorService(ExecutorService delegate)
Creates a new executor service that delegates all methods to the specifieddelegate.- Parameters:
delegate- The delegate ExecutorService being wrapped. This may only benullif thedelegate()method is overridden to provide an alternative non-nullresult.- See Also:
Wrapper.delegate()
-
-
Method Detail
-
wrapTasks
protected <T> Collection<? extends Callable<T>> wrapTasks(Collection<? extends Callable<T>> tasks)
Default way of mapping aCollectionofCallableobjects: Create a new collection and add eachindividually wrappedobject into it.- Type Parameters:
T- The common result type for the collection of tasks.- Parameters:
tasks- The tasks to be mapped.- Returns:
- A collection with each individual task wrapped.
- See Also:
wrap(Callable)
-
wrapFutures
protected <T> List<Future<T>> wrapFutures(Collection<? extends Future<T>> futures)
Default way of mapping aCollectionofFutureobjects: Create a new list and add eachindividually wrappedobject into it.- Type Parameters:
T- The common result type for the collection of futures.- Parameters:
futures- The futures to be mapped.- Returns:
- A list with each individual future wrapped.
- See Also:
wrap(Future)
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submitin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAllin interfaceExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAnyin interfaceExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classWrapper<ExecutorService>
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classWrapper<ExecutorService>
-
toString
public String toString()
- Overrides:
toStringin classWrapper<ExecutorService>- Returns:
- The class name and the delegate string representation.
-
-