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.VersionsClient.ListLocationsPagedResponse; 20 import static com.google.cloud.dialogflow.v2.VersionsClient.ListVersionsPagedResponse; 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.UnaryCallable; 28 import com.google.cloud.dialogflow.v2.CreateVersionRequest; 29 import com.google.cloud.dialogflow.v2.DeleteVersionRequest; 30 import com.google.cloud.dialogflow.v2.GetVersionRequest; 31 import com.google.cloud.dialogflow.v2.ListVersionsRequest; 32 import com.google.cloud.dialogflow.v2.ListVersionsResponse; 33 import com.google.cloud.dialogflow.v2.UpdateVersionRequest; 34 import com.google.cloud.dialogflow.v2.Version; 35 import com.google.cloud.location.GetLocationRequest; 36 import com.google.cloud.location.ListLocationsRequest; 37 import com.google.cloud.location.ListLocationsResponse; 38 import com.google.cloud.location.Location; 39 import com.google.common.collect.ImmutableMap; 40 import com.google.longrunning.stub.GrpcOperationsStub; 41 import com.google.protobuf.Empty; 42 import io.grpc.MethodDescriptor; 43 import io.grpc.protobuf.ProtoUtils; 44 import java.io.IOException; 45 import java.util.concurrent.TimeUnit; 46 import javax.annotation.Generated; 47 48 // AUTO-GENERATED DOCUMENTATION AND CLASS. 49 /** 50 * gRPC stub implementation for the Versions service API. 51 * 52 * <p>This class is for advanced usage and reflects the underlying API directly. 53 */ 54 @Generated("by gapic-generator-java") 55 public class GrpcVersionsStub extends VersionsStub { 56 private static final MethodDescriptor<ListVersionsRequest, ListVersionsResponse> 57 listVersionsMethodDescriptor = 58 MethodDescriptor.<ListVersionsRequest, ListVersionsResponse>newBuilder() 59 .setType(MethodDescriptor.MethodType.UNARY) 60 .setFullMethodName("google.cloud.dialogflow.v2.Versions/ListVersions") 61 .setRequestMarshaller(ProtoUtils.marshaller(ListVersionsRequest.getDefaultInstance())) 62 .setResponseMarshaller( 63 ProtoUtils.marshaller(ListVersionsResponse.getDefaultInstance())) 64 .build(); 65 66 private static final MethodDescriptor<GetVersionRequest, Version> getVersionMethodDescriptor = 67 MethodDescriptor.<GetVersionRequest, Version>newBuilder() 68 .setType(MethodDescriptor.MethodType.UNARY) 69 .setFullMethodName("google.cloud.dialogflow.v2.Versions/GetVersion") 70 .setRequestMarshaller(ProtoUtils.marshaller(GetVersionRequest.getDefaultInstance())) 71 .setResponseMarshaller(ProtoUtils.marshaller(Version.getDefaultInstance())) 72 .build(); 73 74 private static final MethodDescriptor<CreateVersionRequest, Version> 75 createVersionMethodDescriptor = 76 MethodDescriptor.<CreateVersionRequest, Version>newBuilder() 77 .setType(MethodDescriptor.MethodType.UNARY) 78 .setFullMethodName("google.cloud.dialogflow.v2.Versions/CreateVersion") 79 .setRequestMarshaller( 80 ProtoUtils.marshaller(CreateVersionRequest.getDefaultInstance())) 81 .setResponseMarshaller(ProtoUtils.marshaller(Version.getDefaultInstance())) 82 .build(); 83 84 private static final MethodDescriptor<UpdateVersionRequest, Version> 85 updateVersionMethodDescriptor = 86 MethodDescriptor.<UpdateVersionRequest, Version>newBuilder() 87 .setType(MethodDescriptor.MethodType.UNARY) 88 .setFullMethodName("google.cloud.dialogflow.v2.Versions/UpdateVersion") 89 .setRequestMarshaller( 90 ProtoUtils.marshaller(UpdateVersionRequest.getDefaultInstance())) 91 .setResponseMarshaller(ProtoUtils.marshaller(Version.getDefaultInstance())) 92 .build(); 93 94 private static final MethodDescriptor<DeleteVersionRequest, Empty> deleteVersionMethodDescriptor = 95 MethodDescriptor.<DeleteVersionRequest, Empty>newBuilder() 96 .setType(MethodDescriptor.MethodType.UNARY) 97 .setFullMethodName("google.cloud.dialogflow.v2.Versions/DeleteVersion") 98 .setRequestMarshaller(ProtoUtils.marshaller(DeleteVersionRequest.getDefaultInstance())) 99 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 100 .build(); 101 102 private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse> 103 listLocationsMethodDescriptor = 104 MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder() 105 .setType(MethodDescriptor.MethodType.UNARY) 106 .setFullMethodName("google.cloud.location.Locations/ListLocations") 107 .setRequestMarshaller( 108 ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance())) 109 .setResponseMarshaller( 110 ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance())) 111 .build(); 112 113 private static final MethodDescriptor<GetLocationRequest, Location> getLocationMethodDescriptor = 114 MethodDescriptor.<GetLocationRequest, Location>newBuilder() 115 .setType(MethodDescriptor.MethodType.UNARY) 116 .setFullMethodName("google.cloud.location.Locations/GetLocation") 117 .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance())) 118 .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance())) 119 .build(); 120 121 private final UnaryCallable<ListVersionsRequest, ListVersionsResponse> listVersionsCallable; 122 private final UnaryCallable<ListVersionsRequest, ListVersionsPagedResponse> 123 listVersionsPagedCallable; 124 private final UnaryCallable<GetVersionRequest, Version> getVersionCallable; 125 private final UnaryCallable<CreateVersionRequest, Version> createVersionCallable; 126 private final UnaryCallable<UpdateVersionRequest, Version> updateVersionCallable; 127 private final UnaryCallable<DeleteVersionRequest, Empty> deleteVersionCallable; 128 private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable; 129 private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> 130 listLocationsPagedCallable; 131 private final UnaryCallable<GetLocationRequest, Location> getLocationCallable; 132 133 private final BackgroundResource backgroundResources; 134 private final GrpcOperationsStub operationsStub; 135 private final GrpcStubCallableFactory callableFactory; 136 create(VersionsStubSettings settings)137 public static final GrpcVersionsStub create(VersionsStubSettings settings) throws IOException { 138 return new GrpcVersionsStub(settings, ClientContext.create(settings)); 139 } 140 create(ClientContext clientContext)141 public static final GrpcVersionsStub create(ClientContext clientContext) throws IOException { 142 return new GrpcVersionsStub(VersionsStubSettings.newBuilder().build(), clientContext); 143 } 144 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)145 public static final GrpcVersionsStub create( 146 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 147 return new GrpcVersionsStub( 148 VersionsStubSettings.newBuilder().build(), clientContext, callableFactory); 149 } 150 151 /** 152 * Constructs an instance of GrpcVersionsStub, using the given settings. This is protected so that 153 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 154 */ GrpcVersionsStub(VersionsStubSettings settings, ClientContext clientContext)155 protected GrpcVersionsStub(VersionsStubSettings settings, ClientContext clientContext) 156 throws IOException { 157 this(settings, clientContext, new GrpcVersionsCallableFactory()); 158 } 159 160 /** 161 * Constructs an instance of GrpcVersionsStub, using the given settings. This is protected so that 162 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 163 */ GrpcVersionsStub( VersionsStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)164 protected GrpcVersionsStub( 165 VersionsStubSettings settings, 166 ClientContext clientContext, 167 GrpcStubCallableFactory callableFactory) 168 throws IOException { 169 this.callableFactory = callableFactory; 170 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 171 172 GrpcCallSettings<ListVersionsRequest, ListVersionsResponse> listVersionsTransportSettings = 173 GrpcCallSettings.<ListVersionsRequest, ListVersionsResponse>newBuilder() 174 .setMethodDescriptor(listVersionsMethodDescriptor) 175 .setParamsExtractor( 176 request -> { 177 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 178 params.put("parent", String.valueOf(request.getParent())); 179 return params.build(); 180 }) 181 .build(); 182 GrpcCallSettings<GetVersionRequest, Version> getVersionTransportSettings = 183 GrpcCallSettings.<GetVersionRequest, Version>newBuilder() 184 .setMethodDescriptor(getVersionMethodDescriptor) 185 .setParamsExtractor( 186 request -> { 187 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 188 params.put("name", String.valueOf(request.getName())); 189 return params.build(); 190 }) 191 .build(); 192 GrpcCallSettings<CreateVersionRequest, Version> createVersionTransportSettings = 193 GrpcCallSettings.<CreateVersionRequest, Version>newBuilder() 194 .setMethodDescriptor(createVersionMethodDescriptor) 195 .setParamsExtractor( 196 request -> { 197 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 198 params.put("parent", String.valueOf(request.getParent())); 199 return params.build(); 200 }) 201 .build(); 202 GrpcCallSettings<UpdateVersionRequest, Version> updateVersionTransportSettings = 203 GrpcCallSettings.<UpdateVersionRequest, Version>newBuilder() 204 .setMethodDescriptor(updateVersionMethodDescriptor) 205 .setParamsExtractor( 206 request -> { 207 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 208 params.put("version.name", String.valueOf(request.getVersion().getName())); 209 return params.build(); 210 }) 211 .build(); 212 GrpcCallSettings<DeleteVersionRequest, Empty> deleteVersionTransportSettings = 213 GrpcCallSettings.<DeleteVersionRequest, Empty>newBuilder() 214 .setMethodDescriptor(deleteVersionMethodDescriptor) 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<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings = 223 GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder() 224 .setMethodDescriptor(listLocationsMethodDescriptor) 225 .setParamsExtractor( 226 request -> { 227 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 228 params.put("name", String.valueOf(request.getName())); 229 return params.build(); 230 }) 231 .build(); 232 GrpcCallSettings<GetLocationRequest, Location> getLocationTransportSettings = 233 GrpcCallSettings.<GetLocationRequest, Location>newBuilder() 234 .setMethodDescriptor(getLocationMethodDescriptor) 235 .setParamsExtractor( 236 request -> { 237 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 238 params.put("name", String.valueOf(request.getName())); 239 return params.build(); 240 }) 241 .build(); 242 243 this.listVersionsCallable = 244 callableFactory.createUnaryCallable( 245 listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); 246 this.listVersionsPagedCallable = 247 callableFactory.createPagedCallable( 248 listVersionsTransportSettings, settings.listVersionsSettings(), clientContext); 249 this.getVersionCallable = 250 callableFactory.createUnaryCallable( 251 getVersionTransportSettings, settings.getVersionSettings(), clientContext); 252 this.createVersionCallable = 253 callableFactory.createUnaryCallable( 254 createVersionTransportSettings, settings.createVersionSettings(), clientContext); 255 this.updateVersionCallable = 256 callableFactory.createUnaryCallable( 257 updateVersionTransportSettings, settings.updateVersionSettings(), clientContext); 258 this.deleteVersionCallable = 259 callableFactory.createUnaryCallable( 260 deleteVersionTransportSettings, settings.deleteVersionSettings(), clientContext); 261 this.listLocationsCallable = 262 callableFactory.createUnaryCallable( 263 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 264 this.listLocationsPagedCallable = 265 callableFactory.createPagedCallable( 266 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 267 this.getLocationCallable = 268 callableFactory.createUnaryCallable( 269 getLocationTransportSettings, settings.getLocationSettings(), clientContext); 270 271 this.backgroundResources = 272 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 273 } 274 getOperationsStub()275 public GrpcOperationsStub getOperationsStub() { 276 return operationsStub; 277 } 278 279 @Override listVersionsCallable()280 public UnaryCallable<ListVersionsRequest, ListVersionsResponse> listVersionsCallable() { 281 return listVersionsCallable; 282 } 283 284 @Override listVersionsPagedCallable()285 public UnaryCallable<ListVersionsRequest, ListVersionsPagedResponse> listVersionsPagedCallable() { 286 return listVersionsPagedCallable; 287 } 288 289 @Override getVersionCallable()290 public UnaryCallable<GetVersionRequest, Version> getVersionCallable() { 291 return getVersionCallable; 292 } 293 294 @Override createVersionCallable()295 public UnaryCallable<CreateVersionRequest, Version> createVersionCallable() { 296 return createVersionCallable; 297 } 298 299 @Override updateVersionCallable()300 public UnaryCallable<UpdateVersionRequest, Version> updateVersionCallable() { 301 return updateVersionCallable; 302 } 303 304 @Override deleteVersionCallable()305 public UnaryCallable<DeleteVersionRequest, Empty> deleteVersionCallable() { 306 return deleteVersionCallable; 307 } 308 309 @Override listLocationsCallable()310 public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 311 return listLocationsCallable; 312 } 313 314 @Override 315 public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()316 listLocationsPagedCallable() { 317 return listLocationsPagedCallable; 318 } 319 320 @Override getLocationCallable()321 public UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 322 return getLocationCallable; 323 } 324 325 @Override close()326 public final void close() { 327 try { 328 backgroundResources.close(); 329 } catch (RuntimeException e) { 330 throw e; 331 } catch (Exception e) { 332 throw new IllegalStateException("Failed to close resource", e); 333 } 334 } 335 336 @Override shutdown()337 public void shutdown() { 338 backgroundResources.shutdown(); 339 } 340 341 @Override isShutdown()342 public boolean isShutdown() { 343 return backgroundResources.isShutdown(); 344 } 345 346 @Override isTerminated()347 public boolean isTerminated() { 348 return backgroundResources.isTerminated(); 349 } 350 351 @Override shutdownNow()352 public void shutdownNow() { 353 backgroundResources.shutdownNow(); 354 } 355 356 @Override awaitTermination(long duration, TimeUnit unit)357 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 358 return backgroundResources.awaitTermination(duration, unit); 359 } 360 } 361