Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions temporal-sdk/src/main/java/io/temporal/client/NexusClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.temporal.client;

import io.temporal.common.Experimental;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.CountNexusOperationExecutionsInput;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.CountNexusOperationExecutionsOutput;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.ListNexusOperationExecutionsInput;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.ListNexusOperationExecutionsOutput;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.StartNexusOperationExecutionInput;
import io.temporal.common.interceptors.NexusClientCallsInterceptor.StartNexusOperationExecutionOutput;
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.lang.reflect.Type;
import javax.annotation.Nullable;

/**
* Client for managing standalone Nexus operation executions.
*
* <p>Per-operation actions (describe, cancel, terminate, delete, get result) live on {@link
* NexusClientHandle}; obtain a handle via {@link #getHandle}.
*/
@Experimental
public interface NexusClient {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static NexusClient newInstance(WorkflowServiceStubs service) {
return NexusClientImpl.newInstance(service, NexusClientOperationOptions.getDefaultInstance());
}

static NexusClient newInstance(
WorkflowServiceStubs service, NexusClientOperationOptions options) {
return NexusClientImpl.newInstance(service, options);
}

/** Returns the underlying gRPC stubs this client routes RPCs through. */
WorkflowServiceStubs getWorkflowServiceStubs();

/**
* Obtain an untyped handle to an existing operation; targets the latest run. To bind a result
* type, wrap the returned handle with {@link NexusClientHandle#fromUntyped}.
*/
UntypedNexusClientHandle getHandle(String operationId);

/**
* Obtain an untyped handle to an existing operation, optionally pinned to a specific run. To bind
* a result type, wrap the returned handle with {@link NexusClientHandle#fromUntyped}.
*/
UntypedNexusClientHandle getHandle(String operationId, @Nullable String runId);

/** Obtain a typed handle to an existing operation, bound to {@code resultClass}. */
<R> NexusClientHandle<R> getHandle(
String operationId, @Nullable String runId, Class<R> resultClass);

/**
* Obtain a typed handle to an existing operation, bound to {@code resultClass}/{@code
* resultType}. Use the {@code resultType} variant when the result is a generic type whose
* parameters cannot be captured by {@link Class} alone (e.g. {@code List<String>}).
*/
<R> NexusClientHandle<R> getHandle(
String operationId, @Nullable String runId, Class<R> resultClass, @Nullable Type resultType);

/** Build an untyped service client targeting {@code endpoint}/{@code serviceName}. */
UntypedNexusServiceClient newUntypedNexusServiceClient(String endpoint, String serviceName);

/**
* Build a typed service client for {@code serviceInterface}, targeting {@code endpoint}. The
* service name is extracted from {@code serviceInterface} via {@link
* io.nexusrpc.ServiceDefinition#fromClass}.
*/
<T> NexusServiceClient<T> newNexusServiceClient(Class<T> serviceInterface, String endpoint);

/** Start a new standalone Nexus operation execution. */
StartNexusOperationExecutionOutput startNexusOperationExecution(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should not be on the NexusClient

StartNexusOperationExecutionInput input);

/** List standalone Nexus operation executions matching a query. */
ListNexusOperationExecutionsOutput listNexusOperationExecutions(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client should not be returning interceptor types here, Look at other clients like https://github.com/temporalio/sdk-java/blob/master/temporal-sdk/src/main/java/io/temporal/client/ActivityClient.java#L37

ListNexusOperationExecutionsInput input);

/** Count standalone Nexus operation executions matching a query. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CountNexusOperationExecutionsOutput countNexusOperationExecutions(
CountNexusOperationExecutionsInput input);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.temporal.client;

import java.lang.reflect.Type;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nullable;

/**
* Typed handle for interacting with an existing standalone Nexus operation execution. Add a result
* type binding to an {@link UntypedNexusClientHandle} (returned by {@link
* NexusClient#getHandle(String)}) by calling one of the {@link #fromUntyped} factories.
*/
public interface NexusClientHandle<R> extends UntypedNexusClientHandle {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public interface NexusClientHandle<R> extends UntypedNexusClientHandle {
public interface NexusOperationHandle<R> extends UntypedNexusOperationHandle {

Please keep consistent naming with other Handles like https://github.com/temporalio/sdk-java/blob/master/temporal-sdk/src/main/java/io/temporal/client/ActivityHandle.java


/** Wrap an {@link UntypedNexusClientHandle} as a typed handle bound to {@code resultClass}. */
static <R> NexusClientHandle<R> fromUntyped(
UntypedNexusClientHandle handle, Class<R> resultClass) {
return fromUntyped(handle, resultClass, null);
}

/**
* Wrap an {@link UntypedNexusClientHandle} as a typed handle bound to {@code resultClass} and
* {@code resultType}. Pass a non-null {@code resultType} when the result is a generic type whose
* parameters cannot be captured by {@link Class} alone (e.g. {@code List<String>}).
*/
static <R> NexusClientHandle<R> fromUntyped(
UntypedNexusClientHandle handle, Class<R> resultClass, @Nullable Type resultType) {
return NexusClientHandleImpl.fromUntyped(handle, resultClass, resultType);
}

/** Block until the operation completes and return the typed result. */
R getResult();

/** Block up to {@code timeout} for the operation to complete and return the typed result. */
R getResult(long timeout, java.util.concurrent.TimeUnit unit)
throws java.util.concurrent.TimeoutException;

/** Returns a future that completes with the typed result when the operation finishes. */
CompletableFuture<R> getResultAsync();

/**
* Returns a future that completes with the typed result, or completes exceptionally with a {@link
* java.util.concurrent.TimeoutException} if {@code timeout} elapses first.
*/
CompletableFuture<R> getResultAsync(long timeout, java.util.concurrent.TimeUnit unit);
}
Loading
Loading