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, 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 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.

  • Constructor Details

  • Method Details

    • create

      public static <T, R> TemporalOperationHandler<T,R> create(TemporalOperationHandler.StartHandler<T,R> startHandler)
      Parameters:
      startHandler - the handler to invoke on start operation requests
      Returns:
      an operation handler backed by the given start handler
    • start

      public final io.nexusrpc.handler.OperationStartResult<R> start(io.nexusrpc.handler.OperationContext ctx, io.nexusrpc.handler.OperationStartDetails details, T input)
      Specified by:
      start in interface io.nexusrpc.handler.OperationHandler<T,R>
    • cancel

      public final void cancel(io.nexusrpc.handler.OperationContext ctx, io.nexusrpc.handler.OperationCancelDetails details)
      Specified by:
      cancel in interface io.nexusrpc.handler.OperationHandler<T,R>
    • 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 context
      input - describes the workflow run to cancel