@Experimental public abstract class BaseAsyncInterceptor extends Object implements AsyncInterceptor
Modifier and Type | Field and Description |
---|---|
protected Configuration |
cacheConfiguration |
Constructor and Description |
---|
BaseAsyncInterceptor() |
Modifier and Type | Method and Description |
---|---|
Object |
asyncInvokeNext(InvocationContext ctx,
VisitableCommand command,
Collection<? extends CompletionStage<?>> delays)
Suspend invocation until all
delays complete, then if successful invoke the next interceptor. |
Object |
asyncInvokeNext(InvocationContext ctx,
VisitableCommand command,
CompletionStage<?> delay)
Suspend the invocation until
delay completes, then if successful invoke the next interceptor. |
Object |
asyncInvokeNext(InvocationContext ctx,
VisitableCommand command,
InvocationStage invocationStage)
Suspend the invocation until
invocationStage completes, then if successful invoke the next interceptor. |
static InvocationStage |
asyncValue(CompletionStage<?> valueFuture)
Suspend the invocation until
valueFuture completes, then return its result without running
the remaining interceptors. |
static Object |
delayedNull(CompletionStage<Void> stage)
The same as
delayedValue(CompletionStage, Object) , except that it is optimizes cases where the return
value is null. |
static Object |
delayedValue(CompletionStage<?> stage,
Object syncValue)
Returns an InvocationStage if the provided CompletionStage is null, not completed or completed via exception.
|
static Object |
delayedValue(CompletionStage<?> stage,
Object syncValue,
Throwable throwable)
This method should be used instead of
delayedValue(CompletionStage, Object) when a
InvocationFinallyFunction is used to properly handle the exception if any is present. |
Object |
invokeNext(InvocationContext ctx,
VisitableCommand command)
Invoke the next interceptor, possibly with a new command.
|
<C extends VisitableCommand> |
invokeNextAndExceptionally(InvocationContext ctx,
C command,
InvocationExceptionFunction<C> function)
Invoke the next interceptor, possibly with a new command, and execute an
InvocationCallback
after all the interceptors have finished with an exception. |
<C extends VisitableCommand> |
invokeNextAndFinally(InvocationContext ctx,
C command,
InvocationFinallyAction<C> action)
Invoke the next interceptor, possibly with a new command, and execute an
InvocationCallback
after all the interceptors have finished, with or without an exception. |
<C extends VisitableCommand> |
invokeNextAndHandle(InvocationContext ctx,
C command,
InvocationFinallyFunction<C> function)
Invoke the next interceptor, possibly with a new command, and execute an
InvocationCallback
after all the interceptors have finished, with or without an exception. |
<C extends VisitableCommand> |
invokeNextThenAccept(InvocationContext ctx,
C command,
InvocationSuccessAction<C> action)
Invoke the next interceptor, possibly with a new command, and execute an
InvocationCallback
after all the interceptors have finished successfully. |
<C extends VisitableCommand> |
invokeNextThenApply(InvocationContext ctx,
C command,
InvocationSuccessFunction<C> function)
Invoke the next interceptor, possibly with a new command, and execute an
InvocationCallback
after all the interceptors have finished successfully. |
protected static boolean |
isSuccessfullyDone(Object maybeStage) |
static InvocationStage |
makeStage(Object rv)
Encode the result of an
invokeNext(InvocationContext, VisitableCommand) in an InvocationStage . |
void |
setNextInterceptor(AsyncInterceptor nextInterceptor)
Used internally to set up the interceptor.
|
static Object |
valueOrException(Object rv,
Throwable throwable)
Return the value if
throwable != null , throw the exception otherwise. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
visitCommand
protected Configuration cacheConfiguration
public final void setNextInterceptor(AsyncInterceptor nextInterceptor)
setNextInterceptor
in interface AsyncInterceptor
public final Object invokeNext(InvocationContext ctx, VisitableCommand command)
Use invokeNextThenApply(InvocationContext, VisitableCommand, InvocationSuccessFunction)
or invokeNextThenAccept(InvocationContext, VisitableCommand, InvocationSuccessAction)
instead
if you need to process the return value of the next interceptor.
Note: invokeNext(ctx, command)
does not throw exceptions. In order to handle exceptions from the
next interceptors, you must use
invokeNextAndHandle(InvocationContext, VisitableCommand, InvocationFinallyFunction)
,
invokeNextAndFinally(InvocationContext, VisitableCommand, InvocationFinallyAction)
,
or invokeNextAndExceptionally(InvocationContext, VisitableCommand, InvocationExceptionFunction)
.
public final <C extends VisitableCommand> Object invokeNextThenApply(InvocationContext ctx, C command, InvocationSuccessFunction<C> function)
InvocationCallback
after all the interceptors have finished successfully.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final <C extends VisitableCommand> Object invokeNextThenAccept(InvocationContext ctx, C command, InvocationSuccessAction<C> action)
InvocationCallback
after all the interceptors have finished successfully.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final <C extends VisitableCommand> Object invokeNextAndExceptionally(InvocationContext ctx, C command, InvocationExceptionFunction<C> function)
InvocationCallback
after all the interceptors have finished with an exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final <C extends VisitableCommand> Object invokeNextAndFinally(InvocationContext ctx, C command, InvocationFinallyAction<C> action)
InvocationCallback
after all the interceptors have finished, with or without an exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final <C extends VisitableCommand> Object invokeNextAndHandle(InvocationContext ctx, C command, InvocationFinallyFunction<C> function)
InvocationCallback
after all the interceptors have finished, with or without an exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public static InvocationStage asyncValue(CompletionStage<?> valueFuture)
valueFuture
completes, then return its result without running
the remaining interceptors.
The caller can add a callback that will run when valueFuture
completes, e.g.
asyncValue(v).thenApply(ctx, command, (rCtx, rCommand, rv, t) -> invokeNext(rCtx, rCommand))
.
For this particular scenario, however, it's simpler to use
asyncInvokeNext(InvocationContext, VisitableCommand, CompletionStage)
.
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, CompletionStage<?> delay)
delay
completes, then if successful invoke the next interceptor.
If delay
is null or already completed normally, immediately invoke the next interceptor in this thread.
If delay
completes exceptionally, skip the next interceptor and continue with the exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, InvocationStage invocationStage)
invocationStage
completes, then if successful invoke the next interceptor.
If invocationStage
completes exceptionally, skip the next interceptor and continue with the exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, Collection<? extends CompletionStage<?>> delays)
delays
complete, then if successful invoke the next interceptor.
If the list is empty or null, invoke the next interceptor immediately.
If any of delays
completes exceptionally, skip the next interceptor and continue with the exception.
You need to wrap the result with makeStage(Object)
if you need to add another handler.
public static Object valueOrException(Object rv, Throwable throwable) throws Throwable
throwable != null
, throw the exception otherwise.Throwable
public static InvocationStage makeStage(Object rv)
invokeNext(InvocationContext, VisitableCommand)
in an InvocationStage
.
May not create a new instance, if the result is already an InvocationStage
.
public static Object delayedValue(CompletionStage<?> stage, Object syncValue)
stage
- wait for completion of this if not nullsyncValue
- sync value to return if stage is complete or as stage valuepublic static Object delayedValue(CompletionStage<?> stage, Object syncValue, Throwable throwable)
delayedValue(CompletionStage, Object)
when a
InvocationFinallyFunction
is used to properly handle the exception if any is present.stage
- syncValue
- throwable
- public static Object delayedNull(CompletionStage<Void> stage)
delayedValue(CompletionStage, Object)
, except that it is optimizes cases where the return
value is null.stage
- wait for completion of this if not nullprotected static boolean isSuccessfullyDone(Object maybeStage)
Copyright © 2021 JBoss by Red Hat. All rights reserved.