Class TemporalOperationHandler<T,R>

java.lang.Object
io.temporal.nexus.TemporalOperationHandler<T,R>
Type Parameters:
T - the input type
R - the result type
All Implemented Interfaces:
io.nexusrpc.handler.OperationHandler<T,R>

@Experimental public class TemporalOperationHandler<T,R> extends Object implements io.nexusrpc.handler.OperationHandler<T,R>
Generic Nexus operation handler backed by Temporal. Implements 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
     }
   };
 }