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.
For the common case (default cancel behavior), prefer TemporalOperation, which
collapses the operation factory into the method itself. Subclass this class only when you need to
customize cancel behavior. Override cancelWorkflowRun(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelWorkflowRunInput), cancelUpdateWorkflow(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelUpdateWorkflowInput), or
cancelActivityExecution(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelActivityExecutionInput) to change how the corresponding cancellation is 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.
Custom-cancel example:
@OperationImpl
public OperationHandler<TransferInput, TransferResult> startTransfer() {
return new TemporalOperationHandler<TransferInput, TransferResult>(
(context, client, input) ->
client.startWorkflow(
TransferWorkflow.class,
TransferWorkflow::transfer,
input,
WorkflowOptions.newBuilder()
.setWorkflowId("transfer-" + input.getTransferId())
.build())) {
@Override
protected void cancelWorkflowRun(
TemporalOperationCancelContext ctx, CancelWorkflowRunInput input) {
// custom 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),cancelUpdateWorkflow(io.temporal.nexus.TemporalOperationCancelContext, io.temporal.nexus.CancelUpdateWorkflowInput), 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
-