Package ch.tocco.nice2.util.invokables
Class AbstractInvoker<S>
java.lang.Object
ch.tocco.nice2.util.invokables.AbstractInvoker<S>
- All Implemented Interfaces:
Invoker
- Direct Known Subclasses:
EmptyInvoker
,PredefinedAnswersInvoker
,RemoteContextInvoker
,UpdatePublishStatusContext.Invoker
,UriConversionEntityInterceptorContext.Invoker
An abstract implementation of invoker. Extending classes should only override
preInvoke()
and postInvoke()
.
This class takes care of all exception handling.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCombines `this` and the givenInvoker
by calling `other` inside `this` invoker.static Invoker
Creates a new invoker that is a combination of the given ones, where the first invoker in the list is the outer-most invoker.void
Invokes the specifiedRunnable
.<T> T
Invokes the specifiedCallable
.<T,
E1 extends Exception>
TInvokes the specifiedCallable
expecting the specified exception.Invokes the specifiedCallable
expecting the specified exceptions.Invokes the specifiedCallable
expecting the specified exceptions.<F,
T> T Invokes the specifiedFunction
with the specified input.<T> T
Invokes the specifiedCallable
not expecting any checked exceptions.protected abstract void
postInvoke
(S state, @Nullable Object result, @Nullable Throwable thrown) Called after the given invokable has been invoked.protected abstract S
Called before the given invokable is invoked.
-
Constructor Details
-
AbstractInvoker
public AbstractInvoker()
-
-
Method Details
-
invoke
Description copied from interface:Invoker
Invokes the specifiedRunnable
. -
invoke
Description copied from interface:Invoker
Invokes the specifiedCallable
. -
invokeRTE
Description copied from interface:Invoker
Invokes the specifiedCallable
not expecting any checked exceptions. -
invoke
Description copied from interface:Invoker
Invokes the specifiedCallable
expecting the specified exception. -
invoke
public <T,E1 extends Exception, T invokeE2 extends Exception> (Callable<T> callable, Class<E1> e1, Class<E2> e2) throws E1, E2 Description copied from interface:Invoker
Invokes the specifiedCallable
expecting the specified exceptions. -
invoke
public <T,E1 extends Exception, T invokeE2 extends Exception, E3 extends Exception> (Callable<T> callable, Class<E1> e1, Class<E2> e2, Class<E3> e3) throws E1, E2, E3 Description copied from interface:Invoker
Invokes the specifiedCallable
expecting the specified exceptions. -
invoke
Description copied from interface:Invoker
Invokes the specifiedFunction
with the specified input. -
andThen
Description copied from interface:Invoker
Combines `this` and the givenInvoker
by calling `other` inside `this` invoker. Thus, ```java SecurityManager sm = ... BusinessUnitManager bm = ... sm.privileged().andThen(bm.withBusinessUnit("m2")).invoke(new MyCallable...) ``` is equivalent to ```java sm.privileged().invoke(new Callable { public T call() throws Exception { bm.withBusinessUnit("m2").invoke(new MyCallable { }) } } ``` Which will both invoke `MyCallable` inside the BU-Invoker, which in turn is invoked within the Security-Manager-Invoker. This is to avoid too deep nesting of anonymous classes. The former variant takes also care of exception propagation, when the inner invoker expects different throwables to be thrown. You can also create an invoker from a list using the utility functionfrom(Invoker...)
-
preInvoke
Called before the given invokable is invoked.- Returns:
- An optional state which will be passed to
postInvoke()
.
-
postInvoke
protected abstract void postInvoke(S state, @Nullable @Nullable Object result, @Nullable @Nullable Throwable thrown) Called after the given invokable has been invoked. This will be called in a finally block regardless of whether the invokable throw an exception or not. If the invokable threw an exception and this method throws again, the exception thrown will be added as suppressed exception to the exception originally thrown by the invokable.- Parameters:
state
- The state as returned previously bypreInvoke()
.result
- The return value of the invokable or `null`.thrown
- The exception thrown by the invokable or `null`.- See Also:
-
from
Creates a new invoker that is a combination of the given ones, where the first invoker in the list is the outer-most invoker. If the list is empty, theempty invoker
is returned.- Parameters:
invokers
- the invokers to combine- Returns:
- the combined invoker
-