ExecutorT
- The type of the implementation.public abstract class BaseRequestContextExecutor<ExecutorT extends BaseRequestContextExecutor<ExecutorT>> extends Object
RequestContext
.
The implementations can be called in a fluent way like:
new Implementation().withListeners(...).execute(() -> System.out.println("Called inside a request context!"));
Constructor and Description |
---|
BaseRequestContextExecutor() |
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(Callable<T> callable)
Executes the given
Callable as if it was called inside a RequestContext . |
void |
execute(Executable executable)
Executes the given
Executable as if it was called inside a RequestContext . |
protected abstract ExecutorT |
getThis()
Getter needed to allow for a type safe return in the builder methods.
|
ExecutorT |
withListeners(RequestContextListener... listeners)
Adds the specified listeners to the life-cycle of the
RequestContext . |
ExecutorT |
withoutDefaultListeners()
Removes all SDK provided listeners on the classpath from the executor call.
|
ExecutorT |
withoutListener(Class<? extends RequestContextListener> listener)
Removes the listener with the specified class from the life-cycle of the
RequestContext . |
ExecutorT |
withoutListeners(Collection<Class<? extends RequestContextListener>> listeners)
Removes the listeners with any of the specified classes from the life-cycle of the
RequestContext . |
ExecutorT |
withRequestContext(RequestContext requestContext)
The given custom
RequestContext is used for the call made with the execute(Executable) and
execute(Callable) methods. |
@Nonnull protected abstract ExecutorT getThis()
protected ImplementingType getThis() { return this; }in the subclasses.
@Nonnull public ExecutorT withRequestContext(@Nonnull RequestContext requestContext)
RequestContext
is used for the call made with the execute(Executable)
and
execute(Callable)
methods. If this method is not invoked a default RequestContext
is used
instead.requestContext
- The request context to be used by this executor.@Nonnull public ExecutorT withoutDefaultListeners()
The various libraries of the SDK provide several different implementations of the RequestContextListener
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 RequestContextListener... listeners)
RequestContext
.listeners
- The listeners to use during creation and destruction of the RequestContext
.@Nonnull public ExecutorT withoutListener(@Nonnull Class<? extends RequestContextListener> listener)
RequestContext
.
As RequestContextListener
have a unique priority assigned only a single instance of a specific class can
be present at any given time. This single listener gets removed, if
instance.getClass().equals(listener)for the given
listener
.listener
- The class of the listener to remove.@Nonnull public ExecutorT withoutListeners(@Nonnull Collection<Class<? extends RequestContextListener>> listeners)
RequestContext
.
As RequestContextListener
have a unique priority assigned only a single instance of a specific class can
be present at any given time. This single listener gets removed, if
instance.getClass().equals(listener)for any of the given
listeners
.listeners
- The classes of the listeners to remove.public <T> T execute(@Nonnull Callable<T> callable) throws Exception
Callable
as if it was called inside a RequestContext
.T
- The return type of the given Callable
.callable
- The Callable
to execute inside a RequestContext
.Callable
.Exception
- If there is an issue while computing the value.public void execute(@Nonnull Executable executable) throws Exception
Executable
as if it was called inside a RequestContext
.executable
- The Executable
to execute inside a RequestContext
.Exception
- If there is an issue while executing the Executable
.Copyright © 2018 SAP SE. All rights reserved.