Class TemporalOperationHandler<T,R>
java.lang.Object
io.temporal.nexus.TemporalOperationHandler<T,R>
- Type Parameters:
T- the input typeR- 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.
-
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 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)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
-