1 /* 2 * Copyright 2022 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.vision.v1.stub; 18 19 import com.google.api.gax.core.BackgroundResource; 20 import com.google.api.gax.core.BackgroundResourceAggregation; 21 import com.google.api.gax.grpc.GrpcCallSettings; 22 import com.google.api.gax.grpc.GrpcStubCallableFactory; 23 import com.google.api.gax.rpc.ClientContext; 24 import com.google.api.gax.rpc.OperationCallable; 25 import com.google.api.gax.rpc.UnaryCallable; 26 import com.google.cloud.vision.v1.AsyncBatchAnnotateFilesRequest; 27 import com.google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse; 28 import com.google.cloud.vision.v1.AsyncBatchAnnotateImagesRequest; 29 import com.google.cloud.vision.v1.AsyncBatchAnnotateImagesResponse; 30 import com.google.cloud.vision.v1.BatchAnnotateFilesRequest; 31 import com.google.cloud.vision.v1.BatchAnnotateFilesResponse; 32 import com.google.cloud.vision.v1.BatchAnnotateImagesRequest; 33 import com.google.cloud.vision.v1.BatchAnnotateImagesResponse; 34 import com.google.cloud.vision.v1.OperationMetadata; 35 import com.google.common.collect.ImmutableMap; 36 import com.google.longrunning.Operation; 37 import com.google.longrunning.stub.GrpcOperationsStub; 38 import io.grpc.MethodDescriptor; 39 import io.grpc.protobuf.ProtoUtils; 40 import java.io.IOException; 41 import java.util.concurrent.TimeUnit; 42 import javax.annotation.Generated; 43 44 // AUTO-GENERATED DOCUMENTATION AND CLASS. 45 /** 46 * gRPC stub implementation for the ImageAnnotator service API. 47 * 48 * <p>This class is for advanced usage and reflects the underlying API directly. 49 */ 50 @Generated("by gapic-generator-java") 51 public class GrpcImageAnnotatorStub extends ImageAnnotatorStub { 52 private static final MethodDescriptor<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse> 53 batchAnnotateImagesMethodDescriptor = 54 MethodDescriptor.<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse>newBuilder() 55 .setType(MethodDescriptor.MethodType.UNARY) 56 .setFullMethodName("google.cloud.vision.v1.ImageAnnotator/BatchAnnotateImages") 57 .setRequestMarshaller( 58 ProtoUtils.marshaller(BatchAnnotateImagesRequest.getDefaultInstance())) 59 .setResponseMarshaller( 60 ProtoUtils.marshaller(BatchAnnotateImagesResponse.getDefaultInstance())) 61 .build(); 62 63 private static final MethodDescriptor<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse> 64 batchAnnotateFilesMethodDescriptor = 65 MethodDescriptor.<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse>newBuilder() 66 .setType(MethodDescriptor.MethodType.UNARY) 67 .setFullMethodName("google.cloud.vision.v1.ImageAnnotator/BatchAnnotateFiles") 68 .setRequestMarshaller( 69 ProtoUtils.marshaller(BatchAnnotateFilesRequest.getDefaultInstance())) 70 .setResponseMarshaller( 71 ProtoUtils.marshaller(BatchAnnotateFilesResponse.getDefaultInstance())) 72 .build(); 73 74 private static final MethodDescriptor<AsyncBatchAnnotateImagesRequest, Operation> 75 asyncBatchAnnotateImagesMethodDescriptor = 76 MethodDescriptor.<AsyncBatchAnnotateImagesRequest, Operation>newBuilder() 77 .setType(MethodDescriptor.MethodType.UNARY) 78 .setFullMethodName("google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateImages") 79 .setRequestMarshaller( 80 ProtoUtils.marshaller(AsyncBatchAnnotateImagesRequest.getDefaultInstance())) 81 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 82 .build(); 83 84 private static final MethodDescriptor<AsyncBatchAnnotateFilesRequest, Operation> 85 asyncBatchAnnotateFilesMethodDescriptor = 86 MethodDescriptor.<AsyncBatchAnnotateFilesRequest, Operation>newBuilder() 87 .setType(MethodDescriptor.MethodType.UNARY) 88 .setFullMethodName("google.cloud.vision.v1.ImageAnnotator/AsyncBatchAnnotateFiles") 89 .setRequestMarshaller( 90 ProtoUtils.marshaller(AsyncBatchAnnotateFilesRequest.getDefaultInstance())) 91 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 92 .build(); 93 94 private final UnaryCallable<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse> 95 batchAnnotateImagesCallable; 96 private final UnaryCallable<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse> 97 batchAnnotateFilesCallable; 98 private final UnaryCallable<AsyncBatchAnnotateImagesRequest, Operation> 99 asyncBatchAnnotateImagesCallable; 100 private final OperationCallable< 101 AsyncBatchAnnotateImagesRequest, AsyncBatchAnnotateImagesResponse, OperationMetadata> 102 asyncBatchAnnotateImagesOperationCallable; 103 private final UnaryCallable<AsyncBatchAnnotateFilesRequest, Operation> 104 asyncBatchAnnotateFilesCallable; 105 private final OperationCallable< 106 AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> 107 asyncBatchAnnotateFilesOperationCallable; 108 109 private final BackgroundResource backgroundResources; 110 private final GrpcOperationsStub operationsStub; 111 private final GrpcStubCallableFactory callableFactory; 112 create(ImageAnnotatorStubSettings settings)113 public static final GrpcImageAnnotatorStub create(ImageAnnotatorStubSettings settings) 114 throws IOException { 115 return new GrpcImageAnnotatorStub(settings, ClientContext.create(settings)); 116 } 117 create(ClientContext clientContext)118 public static final GrpcImageAnnotatorStub create(ClientContext clientContext) 119 throws IOException { 120 return new GrpcImageAnnotatorStub( 121 ImageAnnotatorStubSettings.newBuilder().build(), clientContext); 122 } 123 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)124 public static final GrpcImageAnnotatorStub create( 125 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 126 return new GrpcImageAnnotatorStub( 127 ImageAnnotatorStubSettings.newBuilder().build(), clientContext, callableFactory); 128 } 129 130 /** 131 * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected 132 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 133 * preferred. 134 */ GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext)135 protected GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext) 136 throws IOException { 137 this(settings, clientContext, new GrpcImageAnnotatorCallableFactory()); 138 } 139 140 /** 141 * Constructs an instance of GrpcImageAnnotatorStub, using the given settings. This is protected 142 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 143 * preferred. 144 */ GrpcImageAnnotatorStub( ImageAnnotatorStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)145 protected GrpcImageAnnotatorStub( 146 ImageAnnotatorStubSettings settings, 147 ClientContext clientContext, 148 GrpcStubCallableFactory callableFactory) 149 throws IOException { 150 this.callableFactory = callableFactory; 151 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 152 153 GrpcCallSettings<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse> 154 batchAnnotateImagesTransportSettings = 155 GrpcCallSettings.<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse>newBuilder() 156 .setMethodDescriptor(batchAnnotateImagesMethodDescriptor) 157 .setParamsExtractor( 158 request -> { 159 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 160 params.put("parent", String.valueOf(request.getParent())); 161 return params.build(); 162 }) 163 .build(); 164 GrpcCallSettings<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse> 165 batchAnnotateFilesTransportSettings = 166 GrpcCallSettings.<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse>newBuilder() 167 .setMethodDescriptor(batchAnnotateFilesMethodDescriptor) 168 .setParamsExtractor( 169 request -> { 170 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 171 params.put("parent", String.valueOf(request.getParent())); 172 return params.build(); 173 }) 174 .build(); 175 GrpcCallSettings<AsyncBatchAnnotateImagesRequest, Operation> 176 asyncBatchAnnotateImagesTransportSettings = 177 GrpcCallSettings.<AsyncBatchAnnotateImagesRequest, Operation>newBuilder() 178 .setMethodDescriptor(asyncBatchAnnotateImagesMethodDescriptor) 179 .setParamsExtractor( 180 request -> { 181 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 182 params.put("parent", String.valueOf(request.getParent())); 183 return params.build(); 184 }) 185 .build(); 186 GrpcCallSettings<AsyncBatchAnnotateFilesRequest, Operation> 187 asyncBatchAnnotateFilesTransportSettings = 188 GrpcCallSettings.<AsyncBatchAnnotateFilesRequest, Operation>newBuilder() 189 .setMethodDescriptor(asyncBatchAnnotateFilesMethodDescriptor) 190 .setParamsExtractor( 191 request -> { 192 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 193 params.put("parent", String.valueOf(request.getParent())); 194 return params.build(); 195 }) 196 .build(); 197 198 this.batchAnnotateImagesCallable = 199 callableFactory.createUnaryCallable( 200 batchAnnotateImagesTransportSettings, 201 settings.batchAnnotateImagesSettings(), 202 clientContext); 203 this.batchAnnotateFilesCallable = 204 callableFactory.createUnaryCallable( 205 batchAnnotateFilesTransportSettings, 206 settings.batchAnnotateFilesSettings(), 207 clientContext); 208 this.asyncBatchAnnotateImagesCallable = 209 callableFactory.createUnaryCallable( 210 asyncBatchAnnotateImagesTransportSettings, 211 settings.asyncBatchAnnotateImagesSettings(), 212 clientContext); 213 this.asyncBatchAnnotateImagesOperationCallable = 214 callableFactory.createOperationCallable( 215 asyncBatchAnnotateImagesTransportSettings, 216 settings.asyncBatchAnnotateImagesOperationSettings(), 217 clientContext, 218 operationsStub); 219 this.asyncBatchAnnotateFilesCallable = 220 callableFactory.createUnaryCallable( 221 asyncBatchAnnotateFilesTransportSettings, 222 settings.asyncBatchAnnotateFilesSettings(), 223 clientContext); 224 this.asyncBatchAnnotateFilesOperationCallable = 225 callableFactory.createOperationCallable( 226 asyncBatchAnnotateFilesTransportSettings, 227 settings.asyncBatchAnnotateFilesOperationSettings(), 228 clientContext, 229 operationsStub); 230 231 this.backgroundResources = 232 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 233 } 234 getOperationsStub()235 public GrpcOperationsStub getOperationsStub() { 236 return operationsStub; 237 } 238 239 @Override 240 public UnaryCallable<BatchAnnotateImagesRequest, BatchAnnotateImagesResponse> batchAnnotateImagesCallable()241 batchAnnotateImagesCallable() { 242 return batchAnnotateImagesCallable; 243 } 244 245 @Override 246 public UnaryCallable<BatchAnnotateFilesRequest, BatchAnnotateFilesResponse> batchAnnotateFilesCallable()247 batchAnnotateFilesCallable() { 248 return batchAnnotateFilesCallable; 249 } 250 251 @Override 252 public UnaryCallable<AsyncBatchAnnotateImagesRequest, Operation> asyncBatchAnnotateImagesCallable()253 asyncBatchAnnotateImagesCallable() { 254 return asyncBatchAnnotateImagesCallable; 255 } 256 257 @Override 258 public OperationCallable< 259 AsyncBatchAnnotateImagesRequest, AsyncBatchAnnotateImagesResponse, OperationMetadata> asyncBatchAnnotateImagesOperationCallable()260 asyncBatchAnnotateImagesOperationCallable() { 261 return asyncBatchAnnotateImagesOperationCallable; 262 } 263 264 @Override 265 public UnaryCallable<AsyncBatchAnnotateFilesRequest, Operation> asyncBatchAnnotateFilesCallable()266 asyncBatchAnnotateFilesCallable() { 267 return asyncBatchAnnotateFilesCallable; 268 } 269 270 @Override 271 public OperationCallable< 272 AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> asyncBatchAnnotateFilesOperationCallable()273 asyncBatchAnnotateFilesOperationCallable() { 274 return asyncBatchAnnotateFilesOperationCallable; 275 } 276 277 @Override close()278 public final void close() { 279 try { 280 backgroundResources.close(); 281 } catch (RuntimeException e) { 282 throw e; 283 } catch (Exception e) { 284 throw new IllegalStateException("Failed to close resource", e); 285 } 286 } 287 288 @Override shutdown()289 public void shutdown() { 290 backgroundResources.shutdown(); 291 } 292 293 @Override isShutdown()294 public boolean isShutdown() { 295 return backgroundResources.isShutdown(); 296 } 297 298 @Override isTerminated()299 public boolean isTerminated() { 300 return backgroundResources.isTerminated(); 301 } 302 303 @Override shutdownNow()304 public void shutdownNow() { 305 backgroundResources.shutdownNow(); 306 } 307 308 @Override awaitTermination(long duration, TimeUnit unit)309 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 310 return backgroundResources.awaitTermination(duration, unit); 311 } 312 } 313