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.dialogflow.v2beta1.stub; 18 19 import static com.google.cloud.dialogflow.v2beta1.IntentsClient.ListIntentsPagedResponse; 20 import static com.google.cloud.dialogflow.v2beta1.IntentsClient.ListLocationsPagedResponse; 21 22 import com.google.api.core.BetaApi; 23 import com.google.api.gax.core.BackgroundResource; 24 import com.google.api.gax.core.BackgroundResourceAggregation; 25 import com.google.api.gax.grpc.GrpcCallSettings; 26 import com.google.api.gax.grpc.GrpcStubCallableFactory; 27 import com.google.api.gax.rpc.ClientContext; 28 import com.google.api.gax.rpc.OperationCallable; 29 import com.google.api.gax.rpc.UnaryCallable; 30 import com.google.cloud.dialogflow.v2beta1.BatchDeleteIntentsRequest; 31 import com.google.cloud.dialogflow.v2beta1.BatchUpdateIntentsRequest; 32 import com.google.cloud.dialogflow.v2beta1.BatchUpdateIntentsResponse; 33 import com.google.cloud.dialogflow.v2beta1.CreateIntentRequest; 34 import com.google.cloud.dialogflow.v2beta1.DeleteIntentRequest; 35 import com.google.cloud.dialogflow.v2beta1.GetIntentRequest; 36 import com.google.cloud.dialogflow.v2beta1.Intent; 37 import com.google.cloud.dialogflow.v2beta1.ListIntentsRequest; 38 import com.google.cloud.dialogflow.v2beta1.ListIntentsResponse; 39 import com.google.cloud.dialogflow.v2beta1.UpdateIntentRequest; 40 import com.google.cloud.location.GetLocationRequest; 41 import com.google.cloud.location.ListLocationsRequest; 42 import com.google.cloud.location.ListLocationsResponse; 43 import com.google.cloud.location.Location; 44 import com.google.common.collect.ImmutableMap; 45 import com.google.longrunning.Operation; 46 import com.google.longrunning.stub.GrpcOperationsStub; 47 import com.google.protobuf.Empty; 48 import com.google.protobuf.Struct; 49 import io.grpc.MethodDescriptor; 50 import io.grpc.protobuf.ProtoUtils; 51 import java.io.IOException; 52 import java.util.concurrent.TimeUnit; 53 import javax.annotation.Generated; 54 55 // AUTO-GENERATED DOCUMENTATION AND CLASS. 56 /** 57 * gRPC stub implementation for the Intents service API. 58 * 59 * <p>This class is for advanced usage and reflects the underlying API directly. 60 */ 61 @BetaApi 62 @Generated("by gapic-generator-java") 63 public class GrpcIntentsStub extends IntentsStub { 64 private static final MethodDescriptor<ListIntentsRequest, ListIntentsResponse> 65 listIntentsMethodDescriptor = 66 MethodDescriptor.<ListIntentsRequest, ListIntentsResponse>newBuilder() 67 .setType(MethodDescriptor.MethodType.UNARY) 68 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/ListIntents") 69 .setRequestMarshaller(ProtoUtils.marshaller(ListIntentsRequest.getDefaultInstance())) 70 .setResponseMarshaller( 71 ProtoUtils.marshaller(ListIntentsResponse.getDefaultInstance())) 72 .build(); 73 74 private static final MethodDescriptor<GetIntentRequest, Intent> getIntentMethodDescriptor = 75 MethodDescriptor.<GetIntentRequest, Intent>newBuilder() 76 .setType(MethodDescriptor.MethodType.UNARY) 77 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/GetIntent") 78 .setRequestMarshaller(ProtoUtils.marshaller(GetIntentRequest.getDefaultInstance())) 79 .setResponseMarshaller(ProtoUtils.marshaller(Intent.getDefaultInstance())) 80 .build(); 81 82 private static final MethodDescriptor<CreateIntentRequest, Intent> createIntentMethodDescriptor = 83 MethodDescriptor.<CreateIntentRequest, Intent>newBuilder() 84 .setType(MethodDescriptor.MethodType.UNARY) 85 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/CreateIntent") 86 .setRequestMarshaller(ProtoUtils.marshaller(CreateIntentRequest.getDefaultInstance())) 87 .setResponseMarshaller(ProtoUtils.marshaller(Intent.getDefaultInstance())) 88 .build(); 89 90 private static final MethodDescriptor<UpdateIntentRequest, Intent> updateIntentMethodDescriptor = 91 MethodDescriptor.<UpdateIntentRequest, Intent>newBuilder() 92 .setType(MethodDescriptor.MethodType.UNARY) 93 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/UpdateIntent") 94 .setRequestMarshaller(ProtoUtils.marshaller(UpdateIntentRequest.getDefaultInstance())) 95 .setResponseMarshaller(ProtoUtils.marshaller(Intent.getDefaultInstance())) 96 .build(); 97 98 private static final MethodDescriptor<DeleteIntentRequest, Empty> deleteIntentMethodDescriptor = 99 MethodDescriptor.<DeleteIntentRequest, Empty>newBuilder() 100 .setType(MethodDescriptor.MethodType.UNARY) 101 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/DeleteIntent") 102 .setRequestMarshaller(ProtoUtils.marshaller(DeleteIntentRequest.getDefaultInstance())) 103 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 104 .build(); 105 106 private static final MethodDescriptor<BatchUpdateIntentsRequest, Operation> 107 batchUpdateIntentsMethodDescriptor = 108 MethodDescriptor.<BatchUpdateIntentsRequest, Operation>newBuilder() 109 .setType(MethodDescriptor.MethodType.UNARY) 110 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/BatchUpdateIntents") 111 .setRequestMarshaller( 112 ProtoUtils.marshaller(BatchUpdateIntentsRequest.getDefaultInstance())) 113 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 114 .build(); 115 116 private static final MethodDescriptor<BatchDeleteIntentsRequest, Operation> 117 batchDeleteIntentsMethodDescriptor = 118 MethodDescriptor.<BatchDeleteIntentsRequest, Operation>newBuilder() 119 .setType(MethodDescriptor.MethodType.UNARY) 120 .setFullMethodName("google.cloud.dialogflow.v2beta1.Intents/BatchDeleteIntents") 121 .setRequestMarshaller( 122 ProtoUtils.marshaller(BatchDeleteIntentsRequest.getDefaultInstance())) 123 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 124 .build(); 125 126 private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse> 127 listLocationsMethodDescriptor = 128 MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder() 129 .setType(MethodDescriptor.MethodType.UNARY) 130 .setFullMethodName("google.cloud.location.Locations/ListLocations") 131 .setRequestMarshaller( 132 ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance())) 133 .setResponseMarshaller( 134 ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance())) 135 .build(); 136 137 private static final MethodDescriptor<GetLocationRequest, Location> getLocationMethodDescriptor = 138 MethodDescriptor.<GetLocationRequest, Location>newBuilder() 139 .setType(MethodDescriptor.MethodType.UNARY) 140 .setFullMethodName("google.cloud.location.Locations/GetLocation") 141 .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance())) 142 .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) 143 .build(); 144 145 private final UnaryCallable<ListIntentsRequest, ListIntentsResponse> listIntentsCallable; 146 private final UnaryCallable<ListIntentsRequest, ListIntentsPagedResponse> 147 listIntentsPagedCallable; 148 private final UnaryCallable<GetIntentRequest, Intent> getIntentCallable; 149 private final UnaryCallable<CreateIntentRequest, Intent> createIntentCallable; 150 private final UnaryCallable<UpdateIntentRequest, Intent> updateIntentCallable; 151 private final UnaryCallable<DeleteIntentRequest, Empty> deleteIntentCallable; 152 private final UnaryCallable<BatchUpdateIntentsRequest, Operation> batchUpdateIntentsCallable; 153 private final OperationCallable<BatchUpdateIntentsRequest, BatchUpdateIntentsResponse, Struct> 154 batchUpdateIntentsOperationCallable; 155 private final UnaryCallable<BatchDeleteIntentsRequest, Operation> batchDeleteIntentsCallable; 156 private final OperationCallable<BatchDeleteIntentsRequest, Empty, Struct> 157 batchDeleteIntentsOperationCallable; 158 private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable; 159 private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> 160 listLocationsPagedCallable; 161 private final UnaryCallable<GetLocationRequest, Location> getLocationCallable; 162 163 private final BackgroundResource backgroundResources; 164 private final GrpcOperationsStub operationsStub; 165 private final GrpcStubCallableFactory callableFactory; 166 create(IntentsStubSettings settings)167 public static final GrpcIntentsStub create(IntentsStubSettings settings) throws IOException { 168 return new GrpcIntentsStub(settings, ClientContext.create(settings)); 169 } 170 create(ClientContext clientContext)171 public static final GrpcIntentsStub create(ClientContext clientContext) throws IOException { 172 return new GrpcIntentsStub(IntentsStubSettings.newBuilder().build(), clientContext); 173 } 174 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)175 public static final GrpcIntentsStub create( 176 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 177 return new GrpcIntentsStub( 178 IntentsStubSettings.newBuilder().build(), clientContext, callableFactory); 179 } 180 181 /** 182 * Constructs an instance of GrpcIntentsStub, using the given settings. This is protected so that 183 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 184 */ GrpcIntentsStub(IntentsStubSettings settings, ClientContext clientContext)185 protected GrpcIntentsStub(IntentsStubSettings settings, ClientContext clientContext) 186 throws IOException { 187 this(settings, clientContext, new GrpcIntentsCallableFactory()); 188 } 189 190 /** 191 * Constructs an instance of GrpcIntentsStub, using the given settings. This is protected so that 192 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 193 */ GrpcIntentsStub( IntentsStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)194 protected GrpcIntentsStub( 195 IntentsStubSettings settings, 196 ClientContext clientContext, 197 GrpcStubCallableFactory callableFactory) 198 throws IOException { 199 this.callableFactory = callableFactory; 200 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 201 202 GrpcCallSettings<ListIntentsRequest, ListIntentsResponse> listIntentsTransportSettings = 203 GrpcCallSettings.<ListIntentsRequest, ListIntentsResponse>newBuilder() 204 .setMethodDescriptor(listIntentsMethodDescriptor) 205 .setParamsExtractor( 206 request -> { 207 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 208 params.put("parent", String.valueOf(request.getParent())); 209 return params.build(); 210 }) 211 .build(); 212 GrpcCallSettings<GetIntentRequest, Intent> getIntentTransportSettings = 213 GrpcCallSettings.<GetIntentRequest, Intent>newBuilder() 214 .setMethodDescriptor(getIntentMethodDescriptor) 215 .setParamsExtractor( 216 request -> { 217 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 218 params.put("name", String.valueOf(request.getName())); 219 return params.build(); 220 }) 221 .build(); 222 GrpcCallSettings<CreateIntentRequest, Intent> createIntentTransportSettings = 223 GrpcCallSettings.<CreateIntentRequest, Intent>newBuilder() 224 .setMethodDescriptor(createIntentMethodDescriptor) 225 .setParamsExtractor( 226 request -> { 227 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 228 params.put("parent", String.valueOf(request.getParent())); 229 return params.build(); 230 }) 231 .build(); 232 GrpcCallSettings<UpdateIntentRequest, Intent> updateIntentTransportSettings = 233 GrpcCallSettings.<UpdateIntentRequest, Intent>newBuilder() 234 .setMethodDescriptor(updateIntentMethodDescriptor) 235 .setParamsExtractor( 236 request -> { 237 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 238 params.put("intent.name", String.valueOf(request.getIntent().getName())); 239 return params.build(); 240 }) 241 .build(); 242 GrpcCallSettings<DeleteIntentRequest, Empty> deleteIntentTransportSettings = 243 GrpcCallSettings.<DeleteIntentRequest, Empty>newBuilder() 244 .setMethodDescriptor(deleteIntentMethodDescriptor) 245 .setParamsExtractor( 246 request -> { 247 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 248 params.put("name", String.valueOf(request.getName())); 249 return params.build(); 250 }) 251 .build(); 252 GrpcCallSettings<BatchUpdateIntentsRequest, Operation> batchUpdateIntentsTransportSettings = 253 GrpcCallSettings.<BatchUpdateIntentsRequest, Operation>newBuilder() 254 .setMethodDescriptor(batchUpdateIntentsMethodDescriptor) 255 .setParamsExtractor( 256 request -> { 257 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 258 params.put("parent", String.valueOf(request.getParent())); 259 return params.build(); 260 }) 261 .build(); 262 GrpcCallSettings<BatchDeleteIntentsRequest, Operation> batchDeleteIntentsTransportSettings = 263 GrpcCallSettings.<BatchDeleteIntentsRequest, Operation>newBuilder() 264 .setMethodDescriptor(batchDeleteIntentsMethodDescriptor) 265 .setParamsExtractor( 266 request -> { 267 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 268 params.put("parent", String.valueOf(request.getParent())); 269 return params.build(); 270 }) 271 .build(); 272 GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings = 273 GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder() 274 .setMethodDescriptor(listLocationsMethodDescriptor) 275 .setParamsExtractor( 276 request -> { 277 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 278 params.put("name", String.valueOf(request.getName())); 279 return params.build(); 280 }) 281 .build(); 282 GrpcCallSettings<GetLocationRequest, Location> getLocationTransportSettings = 283 GrpcCallSettings.<GetLocationRequest, Location>newBuilder() 284 .setMethodDescriptor(getLocationMethodDescriptor) 285 .setParamsExtractor( 286 request -> { 287 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 288 params.put("name", String.valueOf(request.getName())); 289 return params.build(); 290 }) 291 .build(); 292 293 this.listIntentsCallable = 294 callableFactory.createUnaryCallable( 295 listIntentsTransportSettings, settings.listIntentsSettings(), clientContext); 296 this.listIntentsPagedCallable = 297 callableFactory.createPagedCallable( 298 listIntentsTransportSettings, settings.listIntentsSettings(), clientContext); 299 this.getIntentCallable = 300 callableFactory.createUnaryCallable( 301 getIntentTransportSettings, settings.getIntentSettings(), clientContext); 302 this.createIntentCallable = 303 callableFactory.createUnaryCallable( 304 createIntentTransportSettings, settings.createIntentSettings(), clientContext); 305 this.updateIntentCallable = 306 callableFactory.createUnaryCallable( 307 updateIntentTransportSettings, settings.updateIntentSettings(), clientContext); 308 this.deleteIntentCallable = 309 callableFactory.createUnaryCallable( 310 deleteIntentTransportSettings, settings.deleteIntentSettings(), clientContext); 311 this.batchUpdateIntentsCallable = 312 callableFactory.createUnaryCallable( 313 batchUpdateIntentsTransportSettings, 314 settings.batchUpdateIntentsSettings(), 315 clientContext); 316 this.batchUpdateIntentsOperationCallable = 317 callableFactory.createOperationCallable( 318 batchUpdateIntentsTransportSettings, 319 settings.batchUpdateIntentsOperationSettings(), 320 clientContext, 321 operationsStub); 322 this.batchDeleteIntentsCallable = 323 callableFactory.createUnaryCallable( 324 batchDeleteIntentsTransportSettings, 325 settings.batchDeleteIntentsSettings(), 326 clientContext); 327 this.batchDeleteIntentsOperationCallable = 328 callableFactory.createOperationCallable( 329 batchDeleteIntentsTransportSettings, 330 settings.batchDeleteIntentsOperationSettings(), 331 clientContext, 332 operationsStub); 333 this.listLocationsCallable = 334 callableFactory.createUnaryCallable( 335 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 336 this.listLocationsPagedCallable = 337 callableFactory.createPagedCallable( 338 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 339 this.getLocationCallable = 340 callableFactory.createUnaryCallable( 341 getLocationTransportSettings, settings.getLocationSettings(), clientContext); 342 343 this.backgroundResources = 344 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 345 } 346 getOperationsStub()347 public GrpcOperationsStub getOperationsStub() { 348 return operationsStub; 349 } 350 351 @Override listIntentsCallable()352 public UnaryCallable<ListIntentsRequest, ListIntentsResponse> listIntentsCallable() { 353 return listIntentsCallable; 354 } 355 356 @Override listIntentsPagedCallable()357 public UnaryCallable<ListIntentsRequest, ListIntentsPagedResponse> listIntentsPagedCallable() { 358 return listIntentsPagedCallable; 359 } 360 361 @Override getIntentCallable()362 public UnaryCallable<GetIntentRequest, Intent> getIntentCallable() { 363 return getIntentCallable; 364 } 365 366 @Override createIntentCallable()367 public UnaryCallable<CreateIntentRequest, Intent> createIntentCallable() { 368 return createIntentCallable; 369 } 370 371 @Override updateIntentCallable()372 public UnaryCallable<UpdateIntentRequest, Intent> updateIntentCallable() { 373 return updateIntentCallable; 374 } 375 376 @Override deleteIntentCallable()377 public UnaryCallable<DeleteIntentRequest, Empty> deleteIntentCallable() { 378 return deleteIntentCallable; 379 } 380 381 @Override batchUpdateIntentsCallable()382 public UnaryCallable<BatchUpdateIntentsRequest, Operation> batchUpdateIntentsCallable() { 383 return batchUpdateIntentsCallable; 384 } 385 386 @Override 387 public OperationCallable<BatchUpdateIntentsRequest, BatchUpdateIntentsResponse, Struct> batchUpdateIntentsOperationCallable()388 batchUpdateIntentsOperationCallable() { 389 return batchUpdateIntentsOperationCallable; 390 } 391 392 @Override batchDeleteIntentsCallable()393 public UnaryCallable<BatchDeleteIntentsRequest, Operation> batchDeleteIntentsCallable() { 394 return batchDeleteIntentsCallable; 395 } 396 397 @Override 398 public OperationCallable<BatchDeleteIntentsRequest, Empty, Struct> batchDeleteIntentsOperationCallable()399 batchDeleteIntentsOperationCallable() { 400 return batchDeleteIntentsOperationCallable; 401 } 402 403 @Override listLocationsCallable()404 public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 405 return listLocationsCallable; 406 } 407 408 @Override 409 public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()410 listLocationsPagedCallable() { 411 return listLocationsPagedCallable; 412 } 413 414 @Override getLocationCallable()415 public UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 416 return getLocationCallable; 417 } 418 419 @Override close()420 public final void close() { 421 try { 422 backgroundResources.close(); 423 } catch (RuntimeException e) { 424 throw e; 425 } catch (Exception e) { 426 throw new IllegalStateException("Failed to close resource", e); 427 } 428 } 429 430 @Override shutdown()431 public void shutdown() { 432 backgroundResources.shutdown(); 433 } 434 435 @Override isShutdown()436 public boolean isShutdown() { 437 return backgroundResources.isShutdown(); 438 } 439 440 @Override isTerminated()441 public boolean isTerminated() { 442 return backgroundResources.isTerminated(); 443 } 444 445 @Override shutdownNow()446 public void shutdownNow() { 447 backgroundResources.shutdownNow(); 448 } 449 450 @Override awaitTermination(long duration, TimeUnit unit)451 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 452 return backgroundResources.awaitTermination(duration, unit); 453 } 454 } 455