diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/CancelOperationOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/CancelOperationOptions.java new file mode 100644 index 0000000..a56a8f2 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/CancelOperationOptions.java @@ -0,0 +1,41 @@ +package io.nexusrpc.client; + +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +/** CancelOperationOptions is used to specify options for canceling an operation. */ +public class CancelOperationOptions { + /** Create a builder for CancelOperationOptions. */ + public static CancelOperationOptions.Builder newBuilder() { + return new CancelOperationOptions.Builder(); + } + + private final SortedMap headers; + + private CancelOperationOptions(SortedMap headers) { + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public static class Builder { + private final SortedMap headers; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + public CancelOperationOptions build() { + return new CancelOperationOptions(headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/ExecuteOperationOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/ExecuteOperationOptions.java new file mode 100644 index 0000000..69706f9 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/ExecuteOperationOptions.java @@ -0,0 +1,103 @@ +package io.nexusrpc.client; + +import io.nexusrpc.Link; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class ExecuteOperationOptions { + private final Map headers; + private final String callbackURL; + private final Map callbackHeaders; + private final String requestId; + private final List inboundLinks; + private final Duration timeout; + + public ExecuteOperationOptions( + Map headers, + String callbackURL, + Map callbackHeaders, + String requestId, + List inboundLinks, + Duration timeout) { + this.headers = headers; + this.callbackURL = callbackURL; + this.callbackHeaders = callbackHeaders; + this.requestId = requestId; + this.inboundLinks = inboundLinks; + this.timeout = timeout; + } + + public Map getHeaders() { + return headers; + } + + public String getCallbackURL() { + return callbackURL; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public String getRequestId() { + return requestId; + } + + public List getInboundLinks() { + return inboundLinks; + } + + public Duration getTimeout() { + return timeout; + } + + public static class Builder { + private final SortedMap headers; + private String callbackURL; + private SortedMap callbackHeaders; + private String requestId; + private List inboundLinks; + private Duration timeout; + + public Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + callbackHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + public Map getHeaders() { + return headers; + } + + public Builder setCallbackURL(String callbackURL) { + this.callbackURL = callbackURL; + return this; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public Builder setRequestId(String requestId) { + this.requestId = requestId; + return this; + } + + public Builder setInboundLinks(List inboundLinks) { + this.inboundLinks = inboundLinks; + return this; + } + + public Builder setTimeout(Duration timeout) { + this.timeout = timeout; + return this; + } + + public ExecuteOperationOptions build() { + return new ExecuteOperationOptions( + headers, callbackURL, callbackHeaders, requestId, inboundLinks, timeout); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationInfoOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationInfoOptions.java new file mode 100644 index 0000000..d230195 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationInfoOptions.java @@ -0,0 +1,40 @@ +package io.nexusrpc.client; + +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class GetOperationInfoOptions { + /** Create a builder for CancelOperationOptions. */ + public static GetOperationInfoOptions.Builder newBuilder() { + return new GetOperationInfoOptions.Builder(); + } + + private final SortedMap headers; + + private GetOperationInfoOptions(SortedMap headers) { + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public static class Builder { + private final SortedMap headers; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + public GetOperationInfoOptions build() { + return new GetOperationInfoOptions(headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationResultOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationResultOptions.java new file mode 100644 index 0000000..30e913f --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/GetOperationResultOptions.java @@ -0,0 +1,59 @@ +package io.nexusrpc.client; + +import java.time.Duration; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class GetOperationResultOptions { + /** Create a builder for GetOperationResultOptions. */ + public static GetOperationResultOptions.Builder newBuilder() { + return new GetOperationResultOptions.Builder(); + } + + private final Duration timeout; + private final SortedMap headers; + + private GetOperationResultOptions(Duration timeout, SortedMap headers) { + this.timeout = timeout; + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public Duration getTimeout() { + return timeout; + } + + public static class Builder { + private final SortedMap headers; + private Duration timeout; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + /** + * Set the timeout for the operation. + * + * @param timeout the duration to wait for the operation result + * @return this builder instance + */ + public Builder setTimeout(Duration timeout) { + this.timeout = timeout; + return this; + } + + public GetOperationResultOptions build() { + return new GetOperationResultOptions(timeout, headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/GetResultResponse.java b/nexus-sdk/src/main/java/io/nexusrpc/client/GetResultResponse.java new file mode 100644 index 0000000..6585104 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/GetResultResponse.java @@ -0,0 +1,45 @@ +package io.nexusrpc.client; + +import io.nexusrpc.Link; +import java.util.List; + +public class GetResultResponse { + public static GetResultResponse.Builder newBuilder() { + return new GetResultResponse.Builder(); + } + + private final T result; + private final List links; + + private GetResultResponse(T result, List links) { + this.result = result; + this.links = links; + } + + public T getResult() { + return result; + } + + public List getLinks() { + return links; + } + + public static class Builder { + private T result; + private List links; + + public Builder setResult(T result) { + this.result = result; + return this; + } + + public Builder setLinks(List links) { + this.links = links; + return this; + } + + public GetResultResponse build() { + return new GetResultResponse<>(result, links); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/OperationHandle.java b/nexus-sdk/src/main/java/io/nexusrpc/client/OperationHandle.java new file mode 100644 index 0000000..d7beebd --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/OperationHandle.java @@ -0,0 +1,132 @@ +package io.nexusrpc.client; + +import io.nexusrpc.OperationInfo; +import io.nexusrpc.client.transport.GetOperationInfoResponse; +import io.nexusrpc.client.transport.GetOperationResultResponse; +import io.nexusrpc.client.transport.Transport; +import java.util.concurrent.CompletableFuture; + +/** + * OperationHandle represents a handle to an operation that can be used to interact with the + * operation. + */ +public class OperationHandle { + private final String operation; + private final String service; + private final String operationToken; + private final Transport transport; + + public OperationHandle( + String operation, String service, String operationToken, Transport transport) { + this.operation = operation; + this.service = service; + this.operationToken = operationToken; + this.transport = transport; + } + + public String getOperation() { + return operation; + } + + public String getService() { + return service; + } + + String getOperationToken() { + return operationToken; + } + + OperationInfo getInfo(GetOperationInfoOptions options) { + // TODO: translate options to transport options if necessary + return transport + .getOperationInfo( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationInfoOptions.newBuilder().build()) + .getOperationInfo(); + } + + void cancel(CancelOperationOptions options) { + // TODO: translate options to transport options if necessary + transport.cancelOperation( + operation, + service, + operationToken, + io.nexusrpc.client.transport.CancelOperationOptions.newBuilder().build()); + } + + T getResult(GetOperationResultOptions options) { + // TODO: translate options to transport options if necessary + return (T) + transport + .getOperationResult( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationResultOptions.newBuilder().build()) + .getResult(); + } + + GetResultResponse getResultWithDetails(GetOperationResultOptions options) { + // TODO: translate options to transport options if necessary + GetOperationResultResponse response = + transport.getOperationResult( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationResultOptions.newBuilder().build()); + return GetResultResponse.newBuilder() + .setResult(response) + .setLinks(response.getLinks()) + .build(); + } + + CompletableFuture getInfoAsync(GetOperationInfoOptions options) { + return transport + .getOperationInfoAsync( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationInfoOptions.newBuilder().build()) + .thenApply(GetOperationInfoResponse::getOperationInfo); + } + + CompletableFuture cancelAsync(CancelOperationOptions options) { + return transport + .cancelOperationAsync( + operation, + service, + operationToken, + io.nexusrpc.client.transport.CancelOperationOptions.newBuilder().build()) + .thenApply(response -> null); + } + + CompletableFuture getResultAsync(GetOperationResultOptions options) { + return transport + .getOperationResultAsync( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationResultOptions.newBuilder().build()) + .thenApply(response -> (T) response.getResult()); + } + + CompletableFuture> getResultWithDetailsAsync( + GetOperationResultOptions options) { + return transport + .getOperationResultAsync( + operation, + service, + operationToken, + io.nexusrpc.client.transport.GetOperationResultOptions.newBuilder().build()) + .thenApply( + response -> + GetResultResponse.newBuilder() + .setResult(response) + .setLinks(response.getLinks()) + .build()); + } + + // TODO Add no arg versions of the above methods that use default options. +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/ServiceClient.java b/nexus-sdk/src/main/java/io/nexusrpc/client/ServiceClient.java new file mode 100644 index 0000000..2a9140f --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/ServiceClient.java @@ -0,0 +1,137 @@ +package io.nexusrpc.client; + +import io.nexusrpc.client.transport.GetOperationResultResponse; +import io.nexusrpc.client.transport.StartOperationResponse; +import io.nexusrpc.client.transport.Transport; +import java.util.function.BiFunction; + +public class ServiceClient { + private final String service; + private final Transport transport; + + // TODO maybe use the builder pattern for consistency + public ServiceClient(String service, Transport transport) { + this.service = service; + this.transport = transport; + } + + /** + * Executes an operation on the Nexus service with the provided input. This method is synchronous + * and returns the result directly. + * + * @param operation The operation method to execute, represented as a BiFunction. + * @param input The input to the operation. + * @return The result of the operation. + */ + R executeOperation(BiFunction operation, U input) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + * Executes an operation on the Nexus service with the provided input. This method is synchronous + * and returns the result directly. + * + * @param operation The operation method to execute, represented as a BiFunction. + * @param input The input to the operation. + * @param options for execute operations + * @return The result of the operation. + */ + R executeOperation( + BiFunction operation, U input, ExecuteOperationOptions options) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + * Starts an operation on the Nexus service with the provided input. + * + * @param operation The operation method to start, represented as a BiFunction. + * @param input The input to the operation. + */ + StartOperationResult startOperation(BiFunction operation, U input) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + * Starts an operation on the Nexus service with the provided input. + * + * @param operation The operation method to start, represented as a BiFunction. + * @param input The input to the operation. + * @param options for start operations + */ + StartOperationResult startOperation( + BiFunction operation, U input, StartOperationOptions options) { + throw new UnsupportedOperationException("Not implemented yet"); + } + + /** + * Starts an operation on the Nexus service with the provided input. + * + * @param operation The operation name to start. + * @param input The input to the operation. + * @param options for start operations + */ + StartOperationResult startOperation( + String operation, U input, StartOperationOptions options) { + // TODO translate options to transport options + StartOperationResponse response = + transport.startOperation( + operation, + service, + io.nexusrpc.client.transport.StartOperationOptions.newBuilder().build()); + // TODO handle response and convert to StartOperationResult + return new StartOperationResult<>(); + } + + /** + * Execute an operation on the Nexus service with the provided input. + * + * @param operation The operation name to start. + * @param input The input to the operation. + * @param options for start operations + */ + StartOperationResult executeOperation( + String operation, U input, ExecuteOperationOptions options) { + // TODO translate options to transport options + StartOperationResponse response = + transport.startOperation( + operation, + service, + io.nexusrpc.client.transport.StartOperationOptions.newBuilder().build()); + if (response.getSyncResult() != null) { + // If the operation is synchronous, return the result directly + return new StartOperationResult<>(); + } + // TODO handle response and convert to GetOperationResultOptions + GetOperationResultResponse result = + transport.getOperationResult( + operation, + service, + response.getAsyncOperationToken(), + io.nexusrpc.client.transport.GetOperationResultOptions.newBuilder().build()); + return new StartOperationResult<>(); + } + + /** + * Gets a handle to an asynchronous operation. + * + *

Note: This does not perform validation that the token is valid. + * + * @param operation name of the operation. + * @param token operation token. + */ + OperationHandle newHandle(String operation, String token) { + return new OperationHandle<>(operation, service, token, transport); + } + + /** + * Gets a handle to an asynchronous operation. + * + *

Note: This does not perform validation that the token is valid. + * + * @param operation operation method. + * @param token operation token. + */ + OperationHandle newHandle(BiFunction operation, String token) { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationOptions.java new file mode 100644 index 0000000..18d0ee6 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationOptions.java @@ -0,0 +1,93 @@ +package io.nexusrpc.client; + +import io.nexusrpc.Link; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class StartOperationOptions { + public static Builder newBuilder() { + return new Builder(); + } + + private final Map headers; + private final String callbackURL; + private final Map callbackHeaders; + private final String requestId; + private final List inboundLinks; + + private StartOperationOptions( + Map headers, + String callbackURL, + Map callbackHeaders, + String requestId, + List inboundLinks) { + this.headers = headers; + this.callbackURL = callbackURL; + this.callbackHeaders = callbackHeaders; + this.requestId = requestId; + this.inboundLinks = inboundLinks; + } + + public Map getHeaders() { + return headers; + } + + public String getCallbackURL() { + return callbackURL; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public String getRequestId() { + return requestId; + } + + public List getInboundLinks() { + return inboundLinks; + } + + public static class Builder { + private final SortedMap headers; + private String callbackURL; + private SortedMap callbackHeaders; + private String requestId; + private List inboundLinks; + + public Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + callbackHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + public Map getHeaders() { + return headers; + } + + public Builder setCallbackURL(String callbackURL) { + this.callbackURL = callbackURL; + return this; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public Builder setRequestId(String requestId) { + this.requestId = requestId; + return this; + } + + public Builder setInboundLinks(List inboundLinks) { + this.inboundLinks = inboundLinks; + return this; + } + + public StartOperationOptions build() { + return new StartOperationOptions( + headers, callbackURL, callbackHeaders, requestId, inboundLinks); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationResult.java b/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationResult.java new file mode 100644 index 0000000..5a4a76e --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/StartOperationResult.java @@ -0,0 +1,21 @@ +package io.nexusrpc.client; + +import io.nexusrpc.Link; +import java.util.List; +import org.jspecify.annotations.Nullable; + +// TODO this can also be an interface with two implementations: one for synchronous and one for +// asynchronous operations. +public class StartOperationResult { + @Nullable T getResult() { + return null; + } + + @Nullable OperationHandle getPendingOperationHandle() { + return null; + } + + List getLinks() { + return null; + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationOptions.java new file mode 100644 index 0000000..cd94779 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationOptions.java @@ -0,0 +1,40 @@ +package io.nexusrpc.client.transport; + +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class CancelOperationOptions { + /** Create a builder for CancelOperationOptions. */ + public static Builder newBuilder() { + return new Builder(); + } + + private final SortedMap headers; + + private CancelOperationOptions(SortedMap headers) { + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public static class Builder { + private final SortedMap headers; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + public CancelOperationOptions build() { + return new CancelOperationOptions(headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationResponse.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationResponse.java new file mode 100644 index 0000000..c35a944 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/CancelOperationResponse.java @@ -0,0 +1,3 @@ +package io.nexusrpc.client.transport; + +public class CancelOperationResponse {} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoOptions.java new file mode 100644 index 0000000..9837b10 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoOptions.java @@ -0,0 +1,40 @@ +package io.nexusrpc.client.transport; + +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class GetOperationInfoOptions { + /** Create a builder for GetOperationInfoOptions. */ + public static Builder newBuilder() { + return new Builder(); + } + + private final SortedMap headers; + + private GetOperationInfoOptions(SortedMap headers) { + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public static class Builder { + private final SortedMap headers; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + public GetOperationInfoOptions build() { + return new GetOperationInfoOptions(headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoResponse.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoResponse.java new file mode 100644 index 0000000..717ec23 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationInfoResponse.java @@ -0,0 +1,35 @@ +package io.nexusrpc.client.transport; + +import io.nexusrpc.OperationInfo; + +public class GetOperationInfoResponse { + /** Create a builder for GetOperationInfoResponse. */ + public static Builder newBuilder() { + return new Builder(); + } + + private final OperationInfo operationInfo; + + private GetOperationInfoResponse(OperationInfo operationInfo) { + this.operationInfo = operationInfo; + } + + public OperationInfo getOperationInfo() { + return operationInfo; + } + + public static class Builder { + private OperationInfo operationInfo; + + private Builder() {} + + public Builder setOperationInfo(OperationInfo operationInfo) { + this.operationInfo = operationInfo; + return this; + } + + public GetOperationInfoResponse build() { + return new GetOperationInfoResponse(operationInfo); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultOptions.java new file mode 100644 index 0000000..46bd70d --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultOptions.java @@ -0,0 +1,59 @@ +package io.nexusrpc.client.transport; + +import java.time.Duration; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class GetOperationResultOptions { + /** Create a builder for GetOperationResultOptions. */ + public static Builder newBuilder() { + return new Builder(); + } + + private final Duration timeout; + private final SortedMap headers; + + private GetOperationResultOptions(Duration timeout, SortedMap headers) { + this.timeout = timeout; + this.headers = headers; + } + + /** Headers. The returned map operates without regard to case. */ + public Map getHeaders() { + return headers; + } + + public Duration getTimeout() { + return timeout; + } + + public static class Builder { + private final SortedMap headers; + private Duration timeout; + + private Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + /** Get headers to mutate. */ + public Map getHeaders() { + return headers; + } + + /** + * Set the timeout for the operation. + * + * @param timeout the duration to wait for the operation result + * @return this builder instance + */ + public Builder setTimeout(Duration timeout) { + this.timeout = timeout; + return this; + } + + public GetOperationResultOptions build() { + return new GetOperationResultOptions(timeout, headers); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultResponse.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultResponse.java new file mode 100644 index 0000000..77f3ce0 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/GetOperationResultResponse.java @@ -0,0 +1,45 @@ +package io.nexusrpc.client.transport; + +import io.nexusrpc.Link; +import java.util.List; + +public class GetOperationResultResponse { + public static GetOperationResultResponse.Builder newBuilder() { + return new GetOperationResultResponse.Builder(); + } + + private final Object result; + private final List links; + + private GetOperationResultResponse(Object result, List links) { + this.result = result; + this.links = links; + } + + public Object getResult() { + return result; + } + + public List getLinks() { + return links; + } + + public static class Builder { + private Object result; + private List links; + + public GetOperationResultResponse.Builder setResult(Object result) { + this.result = result; + return this; + } + + public GetOperationResultResponse.Builder setLinks(List links) { + this.links = links; + return this; + } + + public GetOperationResultResponse build() { + return new GetOperationResultResponse(result, links); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationOptions.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationOptions.java new file mode 100644 index 0000000..e177cc0 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationOptions.java @@ -0,0 +1,94 @@ +package io.nexusrpc.client.transport; + +import io.nexusrpc.Link; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class StartOperationOptions { + /** Create a builder for StartOperationOptions. */ + public static Builder newBuilder() { + return new Builder(); + } + + private final Map headers; + private final String callbackURL; + private final Map callbackHeaders; + private final String requestId; + private final List inboundLinks; + + private StartOperationOptions( + Map headers, + String callbackURL, + Map callbackHeaders, + String requestId, + List inboundLinks) { + this.headers = headers; + this.callbackURL = callbackURL; + this.callbackHeaders = callbackHeaders; + this.requestId = requestId; + this.inboundLinks = inboundLinks; + } + + public Map getHeaders() { + return headers; + } + + public String getCallbackURL() { + return callbackURL; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public String getRequestId() { + return requestId; + } + + public List getInboundLinks() { + return inboundLinks; + } + + public static class Builder { + private final SortedMap headers; + private String callbackURL; + private SortedMap callbackHeaders; + private String requestId; + private List inboundLinks; + + public Builder() { + headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + callbackHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + } + + public Map getHeaders() { + return headers; + } + + public Builder setCallbackURL(String callbackURL) { + this.callbackURL = callbackURL; + return this; + } + + public Map getCallbackHeaders() { + return callbackHeaders; + } + + public Builder setRequestId(String requestId) { + this.requestId = requestId; + return this; + } + + public Builder setInboundLinks(List inboundLinks) { + this.inboundLinks = inboundLinks; + return this; + } + + public StartOperationOptions build() { + return new StartOperationOptions( + headers, callbackURL, callbackHeaders, requestId, inboundLinks); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationResponse.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationResponse.java new file mode 100644 index 0000000..634e553 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/StartOperationResponse.java @@ -0,0 +1,57 @@ +package io.nexusrpc.client.transport; + +import io.nexusrpc.Link; +import java.util.List; + +public class StartOperationResponse { + public static Builder newBuilder() { + return new Builder(); + } + + private final Object syncResult; + private final List links; + private final String asyncOperationToken; + + private StartOperationResponse(Object syncResult, String asyncOperationToken, List links) { + this.syncResult = syncResult; + this.asyncOperationToken = asyncOperationToken; + this.links = links; + } + + public Object getSyncResult() { + return syncResult; + } + + public String getAsyncOperationToken() { + return asyncOperationToken; + } + + public List getLinks() { + return links; + } + + public static class Builder { + private Object syncResult; + private String asyncOperationToken; + private List links; + + public Builder setResult(Object syncResult) { + this.syncResult = syncResult; + return this; + } + + public Builder setAsyncOperationToken(String asyncOperationToken) { + this.asyncOperationToken = asyncOperationToken; + return this; + } + + public Builder setLinks(List links) { + this.links = links; + return this; + } + + public StartOperationResponse build() { + return new StartOperationResponse(syncResult, asyncOperationToken, links); + } + } +} diff --git a/nexus-sdk/src/main/java/io/nexusrpc/client/transport/Transport.java b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/Transport.java new file mode 100644 index 0000000..1f245a6 --- /dev/null +++ b/nexus-sdk/src/main/java/io/nexusrpc/client/transport/Transport.java @@ -0,0 +1,50 @@ +package io.nexusrpc.client.transport; + +import java.util.concurrent.CompletableFuture; + +public interface Transport { + StartOperationResponse startOperation( + String operationName, String serviceName, StartOperationOptions options); + + GetOperationResultResponse getOperationResult( + String operationName, + String serviceName, + String operationToken, + GetOperationResultOptions options); + + GetOperationInfoResponse getOperationInfo( + String operationName, + String serviceName, + String operationToken, + GetOperationInfoOptions options); + + CancelOperationResponse cancelOperation( + String operationName, + String serviceName, + String operationToken, + CancelOperationOptions options); + + CompletableFuture startOperationAsync( + String operationName, + String serviceName, + String operationToken, + StartOperationOptions options); + + CompletableFuture getOperationResultAsync( + String operationName, + String serviceName, + String operationToken, + GetOperationResultOptions options); + + CompletableFuture getOperationInfoAsync( + String operationName, + String serviceName, + String operationToken, + GetOperationInfoOptions options); + + CompletableFuture cancelOperationAsync( + String operationName, + String serviceName, + String operationToken, + CancelOperationOptions options); +}