Interface NexusServiceClient<T>

Type Parameters:
T - the Nexus service interface this client is bound to
All Superinterfaces:
UntypedNexusServiceClient

@Experimental public interface NexusServiceClient<T> extends UntypedNexusServiceClient
Typed client for invoking standalone Nexus operations on a specific service interface T.

Operations are dispatched via method references on T (or equivalent Functions.Func2 / Functions.Func1 lambdas); the client extracts the operation name from the invocation and delegates to NexusClient. For visibility queries (list/count) across operations, use NexusClient directly.

Usage

Given a Nexus service interface:


 @Service
 public interface GreeterService {
   @Operation String greet(String name);     // input + output
   @Operation String now();                  // no input, output
   @Operation Void log(String message);      // input, no output
 }
 

Build a client and dispatch by method reference:


 NexusClient nexusClient = NexusClient.newInstance(workflowServiceStubs);
 NexusServiceClient<GreeterService> client =
     nexusClient.newNexusServiceClient(GreeterService.class, "greeter-endpoint");

 StartNexusOperationOptions options = StartNexusOperationOptions.newBuilder()
     .setId(UUID.randomUUID().toString())
     .build();

 // Operation that takes an input (Func2 overload):
 String hi = client.execute(GreeterService::greet, options, "Ada");

 // Operation with no input (Func1 overload):
 String t = client.execute(GreeterService::now, options);

 // Operation that returns Void: the same overloads work, R is just Void.
 client.execute(GreeterService::log, options, "hello");

 // Get a handle instead of blocking:
 NexusOperationHandle<String> handle = client.start(GreeterService::greet, options, "Ada");
 String result = handle.getResult();

 // Run asynchronously:
 CompletableFuture<String> future =
     client.executeAsync(GreeterService::greet, options, "Ada");
 
See Also:
  • Method Details

    • execute

      <U, R> R execute(Functions.Func2<T,U,R> operation, StartNexusOperationOptions options, U input)
      Executes an operation synchronously with per-call options.
      Parameters:
      operation - a method reference on T identifying the operation
      options - per-call options controlling timeouts, search attributes, etc.
      input - the operation input
      Returns:
      the operation result
      Throws:
      NexusOperationException - if the operation failed, timed out, or was cancelled
    • start

      <U, R> NexusOperationHandle<R> start(Functions.Func2<T,U,R> operation, StartNexusOperationOptions options, U input)
      Starts an operation with per-call options and returns a typed handle.
      Parameters:
      operation - a method reference on T identifying the operation
      options - per-call options controlling timeouts, search attributes, etc.
      input - the operation input
      Returns:
      a typed handle bound to the started operation
    • executeAsync

      <U, R> CompletableFuture<R> executeAsync(Functions.Func2<T,U,R> operation, StartNexusOperationOptions options, U input)
      Async variant of execute(Functions.Func2, StartNexusOperationOptions, Object). Returns a CompletableFuture that completes with the typed result, or completes exceptionally if the operation fails.
      Parameters:
      operation - a method reference on T identifying the operation
      options - per-call options controlling timeouts, search attributes, etc.
      input - the operation input
    • execute

      <R> R execute(Functions.Func1<T,R> operation, StartNexusOperationOptions options)
      Executes a no-input operation synchronously with per-call options. Use this overload for Nexus operations declared without an input parameter on T (e.g. R operation()).
      Parameters:
      operation - a method reference on T identifying the no-input operation
      options - per-call options controlling timeouts, search attributes, etc.
      Returns:
      the operation result
      Throws:
      NexusOperationException - if the operation failed, timed out, or was cancelled
    • start

      <R> NexusOperationHandle<R> start(Functions.Func1<T,R> operation, StartNexusOperationOptions options)
      Starts a no-input operation with per-call options and returns a typed handle. Use this overload for Nexus operations declared without an input parameter on T.
      Parameters:
      operation - a method reference on T identifying the no-input operation
      options - per-call options controlling timeouts, search attributes, etc.
      Returns:
      a typed handle bound to the started operation
    • executeAsync

      <R> CompletableFuture<R> executeAsync(Functions.Func1<T,R> operation, StartNexusOperationOptions options)
      Async variant of execute(Functions.Func1, StartNexusOperationOptions) for no-input operations. Returns a CompletableFuture that completes with the typed result, or completes exceptionally if the operation fails.
      Parameters:
      operation - a method reference on T identifying the no-input operation
      options - per-call options controlling timeouts, search attributes, etc.