Class InvocationStage
- Direct Known Subclasses:
ExceptionSyncInvocationStage,SimpleAsyncInvocationStage,SyncInvocationStage
It is similar to a CompletionStage, but it allows more callback functions
to be stateless by passing the context and the invoked command as parameters.
Unlike CompletionStage, adding a callback can delay the completion
of the initial stage and change its result.
- Since:
- 9.0
- Author:
- Dan Berindei
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract <C extends VisitableCommand>
ObjectaddCallback(InvocationContext ctx, C command, InvocationCallback<C> function) After the current stage completes, invokefunctionand return its result.<C extends VisitableCommand>
ObjectandExceptionally(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) After the current stage completes exceptionally, invokefunctionand return its result.<C extends VisitableCommand>
InvocationStageandExceptionallyMakeStage(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) After the current stage completes exceptionally, invokefunctionand return its result.<C extends VisitableCommand>
ObjectandFinally(InvocationContext ctx, C command, InvocationFinallyAction<C> action) After the current stage completes, invokeaction.<C extends VisitableCommand>
InvocationStageandFinallyMakeStage(InvocationContext ctx, C command, InvocationFinallyAction<C> action) After the current stage completes, invokeaction.<C extends VisitableCommand>
ObjectandHandle(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) After the current stage completes, invokefunctionand return its result.<C extends VisitableCommand>
InvocationStageandHandleMakeStage(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) After the current stage completes, invokefunctionand return its result.static InvocationStageabstract Objectget()Wait for the invocation to complete and return its value.abstract booleanisDone()static InvocationStageIfmaybeStageis not anInvocationStage, wrap it, otherwise cast it to anInvocationStage.<C extends VisitableCommand>
ObjectthenAccept(InvocationContext ctx, C command, InvocationSuccessAction<C> action) After the current stage completes successfully, invokeaction.<C extends VisitableCommand>
InvocationStagethenAcceptMakeStage(InvocationContext ctx, C command, InvocationSuccessAction<C> action) After the current stage completes successfully, invokeaction.<C extends VisitableCommand>
ObjectthenApply(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) After the current stage completes successfully, invokefunctionand return its result.<C extends VisitableCommand>
InvocationStagethenApplyMakeStage(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) After the current stage completes successfully, invokefunctionand return its result.thenReturn(InvocationContext ctx, VisitableCommand command, Object returnValue) Overrides the return value of thisInvocationStageif it is completed successfully.abstract CompletableFuture<Object> CompletableFutureconversion.
-
Constructor Details
-
InvocationStage
public InvocationStage()
-
-
Method Details
-
get
Wait for the invocation to complete and return its value.- Throws:
Throwable- Any exception raised during the invocation.
-
isDone
public abstract boolean isDone()- Returns:
trueif the invocation is complete.
-
toCompletableFuture
CompletableFutureconversion. -
thenApply
public <C extends VisitableCommand> Object thenApply(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) After the current stage completes successfully, invokefunctionand return its result.The result may be either a plain value,
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
thenAccept
public <C extends VisitableCommand> Object thenAccept(InvocationContext ctx, C command, InvocationSuccessAction<C> action) After the current stage completes successfully, invokeaction.The result may be either a plain value,
this, or a newInvocationStage. Ifactionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andExceptionally
public <C extends VisitableCommand> Object andExceptionally(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) After the current stage completes exceptionally, invokefunctionand return its result.The result may be either a plain value,
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andFinally
public <C extends VisitableCommand> Object andFinally(InvocationContext ctx, C command, InvocationFinallyAction<C> action) After the current stage completes, invokeaction.The result may be either a plain value,
this, or a newInvocationStage. Ifactionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andHandle
public <C extends VisitableCommand> Object andHandle(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) After the current stage completes, invokefunctionand return its result.The result may be either a plain value,
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
addCallback
public abstract <C extends VisitableCommand> Object addCallback(InvocationContext ctx, C command, InvocationCallback<C> function) After the current stage completes, invokefunctionand return its result.The result may be either a plain value, or a new
InvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
thenApplyMakeStage
public <C extends VisitableCommand> InvocationStage thenApplyMakeStage(InvocationContext ctx, C command, InvocationSuccessFunction<C> function) After the current stage completes successfully, invokefunctionand return its result.The result may be either
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
thenAcceptMakeStage
public <C extends VisitableCommand> InvocationStage thenAcceptMakeStage(InvocationContext ctx, C command, InvocationSuccessAction<C> action) After the current stage completes successfully, invokeaction.The result may be either
this, or a newInvocationStage. Ifactionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andExceptionallyMakeStage
public <C extends VisitableCommand> InvocationStage andExceptionallyMakeStage(InvocationContext ctx, C command, InvocationExceptionFunction<C> function) After the current stage completes exceptionally, invokefunctionand return its result.The result may be either
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andFinallyMakeStage
public <C extends VisitableCommand> InvocationStage andFinallyMakeStage(InvocationContext ctx, C command, InvocationFinallyAction<C> action) After the current stage completes, invokeaction.The result may be either
this, or a newInvocationStage. Ifactionthrows an exception, the resultInvocationStagewill complete with the same exception. -
andHandleMakeStage
public <C extends VisitableCommand> InvocationStage andHandleMakeStage(InvocationContext ctx, C command, InvocationFinallyFunction<C> function) After the current stage completes, invokefunctionand return its result.The result may be either
this, or a newInvocationStage. Iffunctionthrows an exception, the resultInvocationStagewill complete with the same exception. -
makeStage
IfmaybeStageis not anInvocationStage, wrap it, otherwise cast it to anInvocationStage. -
completedNullStage
- Returns:
- an
InvocationStageinstance completed successfully with valuenull.
-
thenReturn
Overrides the return value of thisInvocationStageif it is completed successfully. The result may be eitherrv, a newInvocationStageorthis
-