ExecutorT
- The type of the implementation.public abstract class AbstractThreadContextExecutor<ExecutorT extends AbstractThreadContextExecutor<ExecutorT>> extends Object
ThreadContext
.
The implementations can be called in a fluent way like:
new Implementation().withListeners(...).execute(() -> System.out.println("Called inside a thread context."));
Constructor and Description |
---|
AbstractThreadContextExecutor() |
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(Callable<T> callable)
Executes the given
Callable as if it was called inside a ThreadContext . |
void |
execute(Executable executable)
Executes the given
Executable as if it was called inside a ThreadContext . |
List<ThreadContextDecorator> |
getDecoratorsOrderedByPriority()
Returns
ThreadContextDecorator s by their priority. |
List<ThreadContextListener> |
getListenersOrderedByPriority()
Returns
ThreadContextListener s by their priority. |
protected abstract ExecutorT |
getThis()
Getter needed to allow for a type safe return in the builder methods.
|
ExecutorT |
withDecorators(Iterable<ThreadContextDecorator> decorators)
Adds the specified decorators to the life-cycle of the
ThreadContext . |
ExecutorT |
withDecorators(ThreadContextDecorator... decorators)
Adds the specified decorators to the life-cycle of the
ThreadContext . |
ExecutorT |
withListeners(Iterable<ThreadContextListener> listeners)
Adds the specified listeners to the life-cycle of the
ThreadContext . |
ExecutorT |
withListeners(ThreadContextListener... listeners)
Adds the specified listeners to the life-cycle of the
ThreadContext . |
ExecutorT |
withoutDecorators(Integer... decoratorPriorities)
Removes the decorators with the given priorities from the life-cycle of the
ThreadContext . |
ExecutorT |
withoutDecorators(Iterable<Integer> decoratorPriorities)
Removes the decorators with the given priorities from the life-cycle of the
ThreadContext . |
ExecutorT |
withoutDefaultDecorators()
Removes all SDK-provided decorators on the classpath from the executor call.
|
ExecutorT |
withoutDefaultListeners()
Removes all SDK provided listeners on the classpath from the executor call.
|
ExecutorT |
withoutListeners(Integer... listenerPriorities)
Removes the listeners with the given priorities from the life-cycle of the
ThreadContext . |
ExecutorT |
withoutListeners(Iterable<Integer> listenerPriorities)
Removes the listeners with the given priorities from the life-cycle of the
ThreadContext . |
ExecutorT |
withoutParentThreadContext()
Specifies that no existing parent
ThreadContext should be used by this executor. |
ExecutorT |
withThreadContext(ThreadContext threadContext)
The given
ThreadContext is used for the call made with the execute(Callable) or
execute(Executable) methods. |
@Nonnull protected abstract ExecutorT getThis()
protected ImplementingType getThis() { return this; }in the subclasses.
@Nonnull public ExecutorT withThreadContext(@Nonnull ThreadContext threadContext)
ThreadContext
is used for the call made with the execute(Callable)
or
execute(Executable)
methods. If this method is not invoked, the currently set ThreadContext
is
inherited, or if no context currently is set, a new ThreadContext
is used.threadContext
- The thread context to be used by this executor.@Nonnull public ExecutorT withoutParentThreadContext()
ThreadContext
should be used by this executor.@Nonnull public ExecutorT withoutDefaultListeners()
The various libraries of the SDK provide several different implementations of the ThreadContextListener
which are loaded automatically if their libraries are part of the classpath. To fine tune the used listeners this
method allows to ignore those automatically loaded implementation.
@Nonnull public ExecutorT withListeners(@Nonnull ThreadContextListener... listeners)
ThreadContext
.listeners
- The listeners to use during creation and destruction of the ThreadContext
.@Nonnull public ExecutorT withListeners(@Nonnull Iterable<ThreadContextListener> listeners)
ThreadContext
.listeners
- The listeners to use during creation and destruction of the ThreadContext
.@Nonnull public ExecutorT withoutListeners(@Nonnull Integer... listenerPriorities)
ThreadContext
.listenerPriorities
- The priorities of the listeners to remove.@Nonnull public ExecutorT withoutListeners(@Nonnull Iterable<Integer> listenerPriorities)
ThreadContext
.listenerPriorities
- The priorities of the listeners to remove.@Nonnull public List<ThreadContextListener> getListenersOrderedByPriority()
ThreadContextListener
s by their priority.@Nonnull public ExecutorT withoutDefaultDecorators()
The various libraries of the SDK provide several different implementations of the ThreadContextDecorator
which are loaded automatically if their libraries are part of the classpath. To fine tune the used decorators
this method allows to ignore those automatically loaded implementation.
@Nonnull public ExecutorT withDecorators(@Nonnull ThreadContextDecorator... decorators)
ThreadContext
.decorators
- The decorators to use during creation and destruction of the ThreadContext
.@Nonnull public ExecutorT withDecorators(@Nonnull Iterable<ThreadContextDecorator> decorators)
ThreadContext
.decorators
- The decorators to use during creation and destruction of the ThreadContext
.@Nonnull public ExecutorT withoutDecorators(@Nonnull Integer... decoratorPriorities)
ThreadContext
.decoratorPriorities
- The priorities of the decorators to remove.@Nonnull public ExecutorT withoutDecorators(@Nonnull Iterable<Integer> decoratorPriorities)
ThreadContext
.decoratorPriorities
- The priorities of the decorators to remove.@Nonnull public List<ThreadContextDecorator> getDecoratorsOrderedByPriority()
ThreadContextDecorator
s by their priority.@Nullable public <T> T execute(@Nonnull Callable<T> callable) throws ThreadContextExecutionException
Callable
as if it was called inside a ThreadContext
.T
- The return type of the given Callable
.callable
- The Callable
to execute inside a ThreadContext
.Callable
.ThreadContextExecutionException
- If there is an issue while computing the value.public void execute(@Nonnull Executable executable) throws ThreadContextExecutionException
Executable
as if it was called inside a ThreadContext
.executable
- The Executable
to execute inside a ThreadContext
.ThreadContextExecutionException
- If there is an issue while running the Executable
.Copyright © 2019 SAP SE. All rights reserved.