Class BaseAsyncInterceptor
- All Implemented Interfaces:
AsyncInterceptor
- Direct Known Subclasses:
DDAsyncInterceptor
- Since:
- 9.0
- Author:
- Dan Berindei
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal Object
asyncInvokeNext
(InvocationContext ctx, VisitableCommand command, Collection<? extends CompletionStage<?>> delays) Suspend invocation until alldelays
complete, then if successful invoke the next interceptor.final Object
asyncInvokeNext
(InvocationContext ctx, VisitableCommand command, CompletionStage<?> delay) Suspend the invocation untildelay
completes, then if successful invoke the next interceptor.final Object
asyncInvokeNext
(InvocationContext ctx, VisitableCommand command, InvocationStage invocationStage) Suspend the invocation untilinvocationStage
completes, then if successful invoke the next interceptor.static InvocationStage
asyncValue
(CompletionStage<?> valueFuture) Suspend the invocation untilvalueFuture
completes, then return its result without running the remaining interceptors.static Object
delayedNull
(CompletionStage<Void> stage) The same asdelayedValue(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 ofdelayedValue(CompletionStage, Object)
when aInvocationFinallyFunction
is used to properly handle the exception if any is present.final Object
invokeNext
(InvocationContext ctx, VisitableCommand command) Invoke the next interceptor, possibly with a new command.final <C extends VisitableCommand>
ObjectinvokeNextAndExceptionally
(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished with an exception.final <C extends VisitableCommand>
ObjectinvokeNextAndFinally
(InvocationContext ctx, C command, InvocationFinallyAction<C> action) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished, with or without an exception.final <C extends VisitableCommand>
ObjectinvokeNextAndHandle
(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished, with or without an exception.final <C extends VisitableCommand>
ObjectinvokeNextThenAccept
(InvocationContext ctx, C command, InvocationSuccessAction<C> action) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished successfully.final <C extends VisitableCommand>
ObjectinvokeNextThenApply
(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished successfully.protected static boolean
isSuccessfullyDone
(Object maybeStage) static InvocationStage
Encode the result of aninvokeNext(InvocationContext, VisitableCommand)
in anInvocationStage
.final void
setNextInterceptor
(AsyncInterceptor nextInterceptor) Used internally to set up the interceptor.static Object
valueOrException
(Object rv, Throwable throwable) Return the value ifthrowable != null
, throw the exception otherwise.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.infinispan.interceptors.AsyncInterceptor
visitCommand
-
Field Details
-
cacheConfiguration
-
-
Constructor Details
-
BaseAsyncInterceptor
public BaseAsyncInterceptor()
-
-
Method Details
-
setNextInterceptor
Used internally to set up the interceptor.- Specified by:
setNextInterceptor
in interfaceAsyncInterceptor
-
invokeNext
Invoke the next interceptor, possibly with a new command.Use
invokeNextThenApply(InvocationContext, VisitableCommand, InvocationSuccessFunction)
orinvokeNextThenAccept(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 useinvokeNextAndHandle(InvocationContext, VisitableCommand, InvocationFinallyFunction)
,invokeNextAndFinally(InvocationContext, VisitableCommand, InvocationFinallyAction)
, orinvokeNextAndExceptionally(InvocationContext, VisitableCommand, InvocationExceptionFunction)
. -
invokeNextThenApply
public final <C extends VisitableCommand> Object invokeNextThenApply(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished successfully.You need to wrap the result with
makeStage(Object)
if you need to add another handler. -
invokeNextThenAccept
public final <C extends VisitableCommand> Object invokeNextThenAccept(InvocationContext ctx, C command, InvocationSuccessAction<C> action) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
after all the interceptors have finished successfully.You need to wrap the result with
makeStage(Object)
if you need to add another handler. -
invokeNextAndExceptionally
public final <C extends VisitableCommand> Object invokeNextAndExceptionally(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
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. -
invokeNextAndFinally
public final <C extends VisitableCommand> Object invokeNextAndFinally(InvocationContext ctx, C command, InvocationFinallyAction<C> action) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
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. -
invokeNextAndHandle
public final <C extends VisitableCommand> Object invokeNextAndHandle(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) Invoke the next interceptor, possibly with a new command, and execute anInvocationCallback
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. -
asyncValue
Suspend the invocation untilvalueFuture
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 useasyncInvokeNext(InvocationContext, VisitableCommand, CompletionStage)
. -
asyncInvokeNext
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, CompletionStage<?> delay) Suspend the invocation untildelay
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. -
asyncInvokeNext
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, InvocationStage invocationStage) Suspend the invocation untilinvocationStage
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. -
asyncInvokeNext
public final Object asyncInvokeNext(InvocationContext ctx, VisitableCommand command, Collection<? extends CompletionStage<?>> delays) Suspend invocation until alldelays
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. -
valueOrException
Return the value ifthrowable != null
, throw the exception otherwise.- Throws:
Throwable
-
makeStage
Encode the result of aninvokeNext(InvocationContext, VisitableCommand)
in anInvocationStage
.May not create a new instance, if the result is already an
InvocationStage
. -
delayedValue
Returns an InvocationStage if the provided CompletionStage is null, not completed or completed via exception. If these are not true the sync value is returned directly.- Parameters:
stage
- wait for completion of this if not nullsyncValue
- sync value to return if stage is complete or as stage value- Returns:
- invocation stage or sync value
-
delayedValue
This method should be used instead ofdelayedValue(CompletionStage, Object)
when aInvocationFinallyFunction
is used to properly handle the exception if any is present.- Parameters:
stage
-syncValue
-throwable
-- Returns:
-
delayedNull
The same asdelayedValue(CompletionStage, Object)
, except that it is optimizes cases where the return value is null.- Parameters:
stage
- wait for completion of this if not null- Returns:
- invocation stage or null sync value
-
isSuccessfullyDone
-