Class CallMappingExecutorService
- java.lang.Object
-
- nl.talsmasoftware.context.delegation.Wrapper<ExecutorService>
-
- nl.talsmasoftware.context.delegation.DelegatingExecutorService
-
- nl.talsmasoftware.context.delegation.CallMappingExecutorService
-
- All Implemented Interfaces:
Executor,ExecutorService
- Direct Known Subclasses:
ContextAwareExecutorService
public abstract class CallMappingExecutorService extends DelegatingExecutorService
Abstract base-class that makes it a little easier to schedule tasks (RunnableorCallableobjects) using an existingExecutorServicewhile providing a custommappingfor all tasks before they get scheduled.- Author:
- Sjoerd Talsma
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCallMappingExecutorService(ExecutorService delegate)Constructor to create a new wrapper around the specifiedservice delegate.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract <V> Callable<V>map(Callable<V> callable)The call mapping that needs to be implemented: map the given callable object into a desired variant before scheduling.protected Runnablewrap(Runnable runnable)protected <V> Callable<V>wrap(Callable<V> callable)Wrapping a callable object is delegated to the abstractmap(Callable)method.-
Methods inherited from class nl.talsmasoftware.context.delegation.DelegatingExecutorService
awaitTermination, equals, execute, hashCode, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit, toString, wrap, wrapFutures, wrapTasks
-
Methods inherited from class nl.talsmasoftware.context.delegation.Wrapper
delegate, nonNullDelegate
-
-
-
-
Constructor Detail
-
CallMappingExecutorService
protected CallMappingExecutorService(ExecutorService delegate)
Constructor to create a new wrapper around the specifiedservice delegate.- Parameters:
delegate- The delegate executor service that does the heavy lifting of executing all tasks once they are mapped.
-
-
Method Detail
-
map
protected abstract <V> Callable<V> map(Callable<V> callable)
The call mapping that needs to be implemented: map the given callable object into a desired variant before scheduling.- Type Parameters:
V- The type of result being returned by the callable object.- Parameters:
callable- The callable to be mapped.- Returns:
- The mapped callable object.
-
wrap
protected final <V> Callable<V> wrap(Callable<V> callable)
Wrapping a callable object is delegated to the abstractmap(Callable)method.- Overrides:
wrapin classDelegatingExecutorService- Type Parameters:
V- The type of result being returned by the callable object.- Parameters:
callable- The callable to be mapped.- Returns:
- The mapped callable object.
- See Also:
map(Callable)
-
wrap
protected Runnable wrap(Runnable runnable)
Default implementation to wrapRunnableobjects before scheduling:wrapit into aCallableobject and return an unwrappedRunnableimplementation that simply runs by calling the mappedCallableobject.- Overrides:
wrapin classDelegatingExecutorService- Parameters:
runnable- The runnable object to be wrapped.- Returns:
- The wrapped runnable (the default implementation re-uses the callable mapping).
- See Also:
wrap(Callable)
-
-