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