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.

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.