Class TemporalOperationHandler<T,R>
- Type Parameters:
T- the input typeR- the result type
- All Implemented Interfaces:
io.nexusrpc.handler.OperationHandler<T,R>
OperationHandler and
provides a composable way to map Temporal operations (start workflow, start activity, etc.) to
Nexus operations.
Usage example:
@OperationImpl
public OperationHandler<TransferInput, TransferResult> startTransfer() {
return TemporalOperationHandler.create((context, client, input) -> {
return client.startWorkflow(
TransferWorkflow.class,
TransferWorkflow::transfer, input.getFromAccount(), input.getToAccount(),
WorkflowOptions.newBuilder()
.setWorkflowId("transfer-" + input.getTransferId())
.build());
});
}
This class supports subclassing to customize cancel behavior. Override cancelWorkflowRun(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelWorkflowRunInput) to change how workflow-run (token type t:1) cancellations are
handled, or cancelActivityExecution(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelActivityExecutionInput) to change how activity-execution (token type
t:2) cancellations are handled. The start(io.nexusrpc.handler.OperationContext, io.nexusrpc.handler.OperationStartDetails, T) and cancel(io.nexusrpc.handler.OperationContext, io.nexusrpc.handler.OperationCancelDetails) methods should not be
overridden — they contain the core dispatch logic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandler invoked when a Nexus start operation request is received. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTemporalOperationHandler(TemporalOperationHandler.StartHandler<T, R> startHandler) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcancel(io.nexusrpc.handler.OperationContext ctx, io.nexusrpc.handler.OperationCancelDetails details) protected voidCalled when a cancel request is received for an activity-execution token (type=2).protected voidCalled when a cancel request is received for a workflow update token.protected voidcancelWorkflowRun(TemporalOperationCancelContext context, CancelWorkflowRunInput input) Called when a cancel request is received for a workflow-run token (type=1).static <T,R> TemporalOperationHandler <T, R> create(TemporalOperationHandler.StartHandler<T, R> startHandler) Creates aTemporalOperationHandlerfrom a start handler.final io.nexusrpc.handler.OperationStartResult<R> start(io.nexusrpc.handler.OperationContext ctx, io.nexusrpc.handler.OperationStartDetails details, T input)
-
Constructor Details
-
TemporalOperationHandler
-
-
Method Details
-
create
public static <T,R> TemporalOperationHandler<T,R> create(TemporalOperationHandler.StartHandler<T, R> startHandler) Creates aTemporalOperationHandlerfrom a start handler. Subclass and overridecancelWorkflowRun(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelWorkflowRunInput)orcancelActivityExecution(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelActivityExecutionInput)to customize cancel behavior.- Parameters:
startHandler- the handler to invoke on start operation requests- Returns:
- an operation handler backed by the given start handler
-
start
-
cancel
-
cancelWorkflowRun
protected void cancelWorkflowRun(TemporalOperationCancelContext context, CancelWorkflowRunInput input) Called when a cancel request is received for a workflow-run token (type=1). Override to customize cancel behavior.Default behavior: cancels the underlying workflow.
- Parameters:
context- the cancel contextinput- describes the workflow run to cancel
-
cancelUpdateWorkflow
protected void cancelUpdateWorkflow(TemporalOperationCancelContext context, CancelUpdateWorkflowInput input) Called when a cancel request is received for a workflow update token. Override to customize cancel behavior.Default behavior: not implemented. There is no server primitive to cancel an in-flight workflow update.
- Parameters:
context- the cancel contextinput- describes the update to cancel
-
cancelActivityExecution
protected void cancelActivityExecution(TemporalOperationCancelContext context, CancelActivityExecutionInput input) Called when a cancel request is received for an activity-execution token (type=2). Override to customize cancel behavior.Default behavior: requests cancellation of the underlying standalone activity execution.
- Parameters:
context- the cancel contextinput- describes the activity execution to cancel
-