|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.spanner.executor.v1; |
| 18 | + |
| 19 | +import com.google.api.gax.core.BackgroundResource; |
| 20 | +import com.google.api.gax.rpc.BidiStreamingCallable; |
| 21 | +import com.google.cloud.spanner.executor.v1.stub.SpannerExecutorProxyStub; |
| 22 | +import com.google.cloud.spanner.executor.v1.stub.SpannerExecutorProxyStubSettings; |
| 23 | +import com.google.spanner.executor.v1.SpannerAsyncActionRequest; |
| 24 | +import com.google.spanner.executor.v1.SpannerAsyncActionResponse; |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.concurrent.TimeUnit; |
| 27 | +import javax.annotation.Generated; |
| 28 | + |
| 29 | +// AUTO-GENERATED DOCUMENTATION AND CLASS. |
| 30 | +/** |
| 31 | + * Service Description: Service that executes SpannerActions asynchronously. |
| 32 | + * |
| 33 | + * <p>This class provides the ability to make remote calls to the backing service through method |
| 34 | + * calls that map to API methods. Sample code to get started: |
| 35 | + * |
| 36 | + * <pre>{@code |
| 37 | + * // This snippet has been automatically generated and should be regarded as a code template only. |
| 38 | + * // It will require modifications to work: |
| 39 | + * // - It may require correct/in-range values for request initialization. |
| 40 | + * // - It may require specifying regional endpoints when creating the service client as shown in |
| 41 | + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
| 42 | + * try (SpannerExecutorProxyClient spannerExecutorProxyClient = |
| 43 | + * SpannerExecutorProxyClient.create()) { |
| 44 | + * BidiStream<SpannerAsyncActionRequest, SpannerAsyncActionResponse> bidiStream = |
| 45 | + * spannerExecutorProxyClient.executeActionAsyncCallable().call(); |
| 46 | + * SpannerAsyncActionRequest request = |
| 47 | + * SpannerAsyncActionRequest.newBuilder() |
| 48 | + * .setActionId(198295492) |
| 49 | + * .setAction(SpannerAction.newBuilder().build()) |
| 50 | + * .build(); |
| 51 | + * bidiStream.send(request); |
| 52 | + * for (SpannerAsyncActionResponse response : bidiStream) { |
| 53 | + * // Do something when a response is received. |
| 54 | + * } |
| 55 | + * } |
| 56 | + * }</pre> |
| 57 | + * |
| 58 | + * <p>Note: close() needs to be called on the SpannerExecutorProxyClient object to clean up |
| 59 | + * resources such as threads. In the example above, try-with-resources is used, which automatically |
| 60 | + * calls close(). |
| 61 | + * |
| 62 | + * <p>The surface of this class includes several types of Java methods for each of the API's |
| 63 | + * methods: |
| 64 | + * |
| 65 | + * <ol> |
| 66 | + * <li>A "flattened" method. With this type of method, the fields of the request type have been |
| 67 | + * converted into function parameters. It may be the case that not all fields are available as |
| 68 | + * parameters, and not every API method will have a flattened method entry point. |
| 69 | + * <li>A "request object" method. This type of method only takes one parameter, a request object, |
| 70 | + * which must be constructed before the call. Not every API method will have a request object |
| 71 | + * method. |
| 72 | + * <li>A "callable" method. This type of method takes no parameters and returns an immutable API |
| 73 | + * callable object, which can be used to initiate calls to the service. |
| 74 | + * </ol> |
| 75 | + * |
| 76 | + * <p>See the individual methods for example code. |
| 77 | + * |
| 78 | + * <p>Many parameters require resource names to be formatted in a particular way. To assist with |
| 79 | + * these names, this class includes a format method for each type of name, and additionally a parse |
| 80 | + * method to extract the individual identifiers contained within names that are returned. |
| 81 | + * |
| 82 | + * <p>This class can be customized by passing in a custom instance of SpannerExecutorProxySettings |
| 83 | + * to create(). For example: |
| 84 | + * |
| 85 | + * <p>To customize credentials: |
| 86 | + * |
| 87 | + * <pre>{@code |
| 88 | + * // This snippet has been automatically generated and should be regarded as a code template only. |
| 89 | + * // It will require modifications to work: |
| 90 | + * // - It may require correct/in-range values for request initialization. |
| 91 | + * // - It may require specifying regional endpoints when creating the service client as shown in |
| 92 | + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
| 93 | + * SpannerExecutorProxySettings spannerExecutorProxySettings = |
| 94 | + * SpannerExecutorProxySettings.newBuilder() |
| 95 | + * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) |
| 96 | + * .build(); |
| 97 | + * SpannerExecutorProxyClient spannerExecutorProxyClient = |
| 98 | + * SpannerExecutorProxyClient.create(spannerExecutorProxySettings); |
| 99 | + * }</pre> |
| 100 | + * |
| 101 | + * <p>To customize the endpoint: |
| 102 | + * |
| 103 | + * <pre>{@code |
| 104 | + * // This snippet has been automatically generated and should be regarded as a code template only. |
| 105 | + * // It will require modifications to work: |
| 106 | + * // - It may require correct/in-range values for request initialization. |
| 107 | + * // - It may require specifying regional endpoints when creating the service client as shown in |
| 108 | + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
| 109 | + * SpannerExecutorProxySettings spannerExecutorProxySettings = |
| 110 | + * SpannerExecutorProxySettings.newBuilder().setEndpoint(myEndpoint).build(); |
| 111 | + * SpannerExecutorProxyClient spannerExecutorProxyClient = |
| 112 | + * SpannerExecutorProxyClient.create(spannerExecutorProxySettings); |
| 113 | + * }</pre> |
| 114 | + * |
| 115 | + * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. |
| 116 | + */ |
| 117 | +@Generated("by gapic-generator-java") |
| 118 | +public class SpannerExecutorProxyClient implements BackgroundResource { |
| 119 | + private final SpannerExecutorProxySettings settings; |
| 120 | + private final SpannerExecutorProxyStub stub; |
| 121 | + |
| 122 | + /** Constructs an instance of SpannerExecutorProxyClient with default settings. */ |
| 123 | + public static final SpannerExecutorProxyClient create() throws IOException { |
| 124 | + return create(SpannerExecutorProxySettings.newBuilder().build()); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Constructs an instance of SpannerExecutorProxyClient, using the given settings. The channels |
| 129 | + * are created based on the settings passed in, or defaults for any settings that are not set. |
| 130 | + */ |
| 131 | + public static final SpannerExecutorProxyClient create(SpannerExecutorProxySettings settings) |
| 132 | + throws IOException { |
| 133 | + return new SpannerExecutorProxyClient(settings); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Constructs an instance of SpannerExecutorProxyClient, using the given stub for making calls. |
| 138 | + * This is for advanced usage - prefer using create(SpannerExecutorProxySettings). |
| 139 | + */ |
| 140 | + public static final SpannerExecutorProxyClient create(SpannerExecutorProxyStub stub) { |
| 141 | + return new SpannerExecutorProxyClient(stub); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Constructs an instance of SpannerExecutorProxyClient, using the given settings. This is |
| 146 | + * protected so that it is easy to make a subclass, but otherwise, the static factory methods |
| 147 | + * should be preferred. |
| 148 | + */ |
| 149 | + protected SpannerExecutorProxyClient(SpannerExecutorProxySettings settings) throws IOException { |
| 150 | + this.settings = settings; |
| 151 | + this.stub = ((SpannerExecutorProxyStubSettings) settings.getStubSettings()).createStub(); |
| 152 | + } |
| 153 | + |
| 154 | + protected SpannerExecutorProxyClient(SpannerExecutorProxyStub stub) { |
| 155 | + this.settings = null; |
| 156 | + this.stub = stub; |
| 157 | + } |
| 158 | + |
| 159 | + public final SpannerExecutorProxySettings getSettings() { |
| 160 | + return settings; |
| 161 | + } |
| 162 | + |
| 163 | + public SpannerExecutorProxyStub getStub() { |
| 164 | + return stub; |
| 165 | + } |
| 166 | + |
| 167 | + // AUTO-GENERATED DOCUMENTATION AND METHOD. |
| 168 | + /** |
| 169 | + * ExecuteActionAsync is a streaming call that starts executing a new Spanner action. |
| 170 | + * |
| 171 | + * <p>For each request, the server will reply with one or more responses, but only the last |
| 172 | + * response will contain status in the outcome. |
| 173 | + * |
| 174 | + * <p>Responses can be matched to requests by action_id. It is allowed to have multiple actions in |
| 175 | + * flight--in that case, actions are be executed in parallel. |
| 176 | + * |
| 177 | + * <p>Sample code: |
| 178 | + * |
| 179 | + * <pre>{@code |
| 180 | + * // This snippet has been automatically generated and should be regarded as a code template only. |
| 181 | + * // It will require modifications to work: |
| 182 | + * // - It may require correct/in-range values for request initialization. |
| 183 | + * // - It may require specifying regional endpoints when creating the service client as shown in |
| 184 | + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
| 185 | + * try (SpannerExecutorProxyClient spannerExecutorProxyClient = |
| 186 | + * SpannerExecutorProxyClient.create()) { |
| 187 | + * BidiStream<SpannerAsyncActionRequest, SpannerAsyncActionResponse> bidiStream = |
| 188 | + * spannerExecutorProxyClient.executeActionAsyncCallable().call(); |
| 189 | + * SpannerAsyncActionRequest request = |
| 190 | + * SpannerAsyncActionRequest.newBuilder() |
| 191 | + * .setActionId(198295492) |
| 192 | + * .setAction(SpannerAction.newBuilder().build()) |
| 193 | + * .build(); |
| 194 | + * bidiStream.send(request); |
| 195 | + * for (SpannerAsyncActionResponse response : bidiStream) { |
| 196 | + * // Do something when a response is received. |
| 197 | + * } |
| 198 | + * } |
| 199 | + * }</pre> |
| 200 | + */ |
| 201 | + public final BidiStreamingCallable<SpannerAsyncActionRequest, SpannerAsyncActionResponse> |
| 202 | + executeActionAsyncCallable() { |
| 203 | + return stub.executeActionAsyncCallable(); |
| 204 | + } |
| 205 | + |
| 206 | + @Override |
| 207 | + public final void close() { |
| 208 | + stub.close(); |
| 209 | + } |
| 210 | + |
| 211 | + @Override |
| 212 | + public void shutdown() { |
| 213 | + stub.shutdown(); |
| 214 | + } |
| 215 | + |
| 216 | + @Override |
| 217 | + public boolean isShutdown() { |
| 218 | + return stub.isShutdown(); |
| 219 | + } |
| 220 | + |
| 221 | + @Override |
| 222 | + public boolean isTerminated() { |
| 223 | + return stub.isTerminated(); |
| 224 | + } |
| 225 | + |
| 226 | + @Override |
| 227 | + public void shutdownNow() { |
| 228 | + stub.shutdownNow(); |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { |
| 233 | + return stub.awaitTermination(duration, unit); |
| 234 | + } |
| 235 | +} |
0 commit comments