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.scheduler.v1.stub; 18 19 import static com.google.cloud.scheduler.v1.CloudSchedulerClient.ListJobsPagedResponse; 20 import static com.google.cloud.scheduler.v1.CloudSchedulerClient.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.UnaryCallable; 28 import com.google.cloud.location.GetLocationRequest; 29 import com.google.cloud.location.ListLocationsRequest; 30 import com.google.cloud.location.ListLocationsResponse; 31 import com.google.cloud.location.Location; 32 import com.google.cloud.scheduler.v1.CreateJobRequest; 33 import com.google.cloud.scheduler.v1.DeleteJobRequest; 34 import com.google.cloud.scheduler.v1.GetJobRequest; 35 import com.google.cloud.scheduler.v1.Job; 36 import com.google.cloud.scheduler.v1.ListJobsRequest; 37 import com.google.cloud.scheduler.v1.ListJobsResponse; 38 import com.google.cloud.scheduler.v1.PauseJobRequest; 39 import com.google.cloud.scheduler.v1.ResumeJobRequest; 40 import com.google.cloud.scheduler.v1.RunJobRequest; 41 import com.google.cloud.scheduler.v1.UpdateJobRequest; 42 import com.google.common.collect.ImmutableMap; 43 import com.google.longrunning.stub.GrpcOperationsStub; 44 import com.google.protobuf.Empty; 45 import io.grpc.MethodDescriptor; 46 import io.grpc.protobuf.ProtoUtils; 47 import java.io.IOException; 48 import java.util.concurrent.TimeUnit; 49 import javax.annotation.Generated; 50 51 // AUTO-GENERATED DOCUMENTATION AND CLASS. 52 /** 53 * gRPC stub implementation for the CloudScheduler service API. 54 * 55 * <p>This class is for advanced usage and reflects the underlying API directly. 56 */ 57 @Generated("by gapic-generator-java") 58 public class GrpcCloudSchedulerStub extends CloudSchedulerStub { 59 private static final MethodDescriptor<ListJobsRequest, ListJobsResponse> 60 listJobsMethodDescriptor = 61 MethodDescriptor.<ListJobsRequest, ListJobsResponse>newBuilder() 62 .setType(MethodDescriptor.MethodType.UNARY) 63 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/ListJobs") 64 .setRequestMarshaller(ProtoUtils.marshaller(ListJobsRequest.getDefaultInstance())) 65 .setResponseMarshaller(ProtoUtils.marshaller(ListJobsResponse.getDefaultInstance())) 66 .build(); 67 68 private static final MethodDescriptor<GetJobRequest, Job> getJobMethodDescriptor = 69 MethodDescriptor.<GetJobRequest, Job>newBuilder() 70 .setType(MethodDescriptor.MethodType.UNARY) 71 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/GetJob") 72 .setRequestMarshaller(ProtoUtils.marshaller(GetJobRequest.getDefaultInstance())) 73 .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance())) 74 .build(); 75 76 private static final MethodDescriptor<CreateJobRequest, Job> createJobMethodDescriptor = 77 MethodDescriptor.<CreateJobRequest, Job>newBuilder() 78 .setType(MethodDescriptor.MethodType.UNARY) 79 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/CreateJob") 80 .setRequestMarshaller(ProtoUtils.marshaller(CreateJobRequest.getDefaultInstance())) 81 .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance())) 82 .build(); 83 84 private static final MethodDescriptor<UpdateJobRequest, Job> updateJobMethodDescriptor = 85 MethodDescriptor.<UpdateJobRequest, Job>newBuilder() 86 .setType(MethodDescriptor.MethodType.UNARY) 87 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/UpdateJob") 88 .setRequestMarshaller(ProtoUtils.marshaller(UpdateJobRequest.getDefaultInstance())) 89 .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance())) 90 .build(); 91 92 private static final MethodDescriptor<DeleteJobRequest, Empty> deleteJobMethodDescriptor = 93 MethodDescriptor.<DeleteJobRequest, Empty>newBuilder() 94 .setType(MethodDescriptor.MethodType.UNARY) 95 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/DeleteJob") 96 .setRequestMarshaller(ProtoUtils.marshaller(DeleteJobRequest.getDefaultInstance())) 97 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 98 .build(); 99 100 private static final MethodDescriptor<PauseJobRequest, Job> pauseJobMethodDescriptor = 101 MethodDescriptor.<PauseJobRequest, Job>newBuilder() 102 .setType(MethodDescriptor.MethodType.UNARY) 103 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/PauseJob") 104 .setRequestMarshaller(ProtoUtils.marshaller(PauseJobRequest.getDefaultInstance())) 105 .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance())) 106 .build(); 107 108 private static final MethodDescriptor<ResumeJobRequest, Job> resumeJobMethodDescriptor = 109 MethodDescriptor.<ResumeJobRequest, Job>newBuilder() 110 .setType(MethodDescriptor.MethodType.UNARY) 111 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/ResumeJob") 112 .setRequestMarshaller(ProtoUtils.marshaller(ResumeJobRequest.getDefaultInstance())) 113 .setResponseMarshaller(ProtoUtils.marshaller(Job.getDefaultInstance())) 114 .build(); 115 116 private static final MethodDescriptor<RunJobRequest, Job> runJobMethodDescriptor = 117 MethodDescriptor.<RunJobRequest, Job>newBuilder() 118 .setType(MethodDescriptor.MethodType.UNARY) 119 .setFullMethodName("google.cloud.scheduler.v1.CloudScheduler/RunJob") 120 .setRequestMarshaller(ProtoUtils.marshaller(RunJobRequest.getDefaultInstance())) 121 .setResponseMarshaller(ProtoUtils.marshaller(Job.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<ListJobsRequest, ListJobsResponse> listJobsCallable; 144 private final UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable; 145 private final UnaryCallable<GetJobRequest, Job> getJobCallable; 146 private final UnaryCallable<CreateJobRequest, Job> createJobCallable; 147 private final UnaryCallable<UpdateJobRequest, Job> updateJobCallable; 148 private final UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable; 149 private final UnaryCallable<PauseJobRequest, Job> pauseJobCallable; 150 private final UnaryCallable<ResumeJobRequest, Job> resumeJobCallable; 151 private final UnaryCallable<RunJobRequest, Job> runJobCallable; 152 private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable; 153 private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> 154 listLocationsPagedCallable; 155 private final UnaryCallable<GetLocationRequest, Location> getLocationCallable; 156 157 private final BackgroundResource backgroundResources; 158 private final GrpcOperationsStub operationsStub; 159 private final GrpcStubCallableFactory callableFactory; 160 create(CloudSchedulerStubSettings settings)161 public static final GrpcCloudSchedulerStub create(CloudSchedulerStubSettings settings) 162 throws IOException { 163 return new GrpcCloudSchedulerStub(settings, ClientContext.create(settings)); 164 } 165 create(ClientContext clientContext)166 public static final GrpcCloudSchedulerStub create(ClientContext clientContext) 167 throws IOException { 168 return new GrpcCloudSchedulerStub( 169 CloudSchedulerStubSettings.newBuilder().build(), clientContext); 170 } 171 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)172 public static final GrpcCloudSchedulerStub create( 173 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 174 return new GrpcCloudSchedulerStub( 175 CloudSchedulerStubSettings.newBuilder().build(), clientContext, callableFactory); 176 } 177 178 /** 179 * Constructs an instance of GrpcCloudSchedulerStub, using the given settings. This is protected 180 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 181 * preferred. 182 */ GrpcCloudSchedulerStub(CloudSchedulerStubSettings settings, ClientContext clientContext)183 protected GrpcCloudSchedulerStub(CloudSchedulerStubSettings settings, ClientContext clientContext) 184 throws IOException { 185 this(settings, clientContext, new GrpcCloudSchedulerCallableFactory()); 186 } 187 188 /** 189 * Constructs an instance of GrpcCloudSchedulerStub, using the given settings. This is protected 190 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 191 * preferred. 192 */ GrpcCloudSchedulerStub( CloudSchedulerStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)193 protected GrpcCloudSchedulerStub( 194 CloudSchedulerStubSettings settings, 195 ClientContext clientContext, 196 GrpcStubCallableFactory callableFactory) 197 throws IOException { 198 this.callableFactory = callableFactory; 199 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 200 201 GrpcCallSettings<ListJobsRequest, ListJobsResponse> listJobsTransportSettings = 202 GrpcCallSettings.<ListJobsRequest, ListJobsResponse>newBuilder() 203 .setMethodDescriptor(listJobsMethodDescriptor) 204 .setParamsExtractor( 205 request -> { 206 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 207 params.put("parent", String.valueOf(request.getParent())); 208 return params.build(); 209 }) 210 .build(); 211 GrpcCallSettings<GetJobRequest, Job> getJobTransportSettings = 212 GrpcCallSettings.<GetJobRequest, Job>newBuilder() 213 .setMethodDescriptor(getJobMethodDescriptor) 214 .setParamsExtractor( 215 request -> { 216 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 217 params.put("name", String.valueOf(request.getName())); 218 return params.build(); 219 }) 220 .build(); 221 GrpcCallSettings<CreateJobRequest, Job> createJobTransportSettings = 222 GrpcCallSettings.<CreateJobRequest, Job>newBuilder() 223 .setMethodDescriptor(createJobMethodDescriptor) 224 .setParamsExtractor( 225 request -> { 226 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 227 params.put("parent", String.valueOf(request.getParent())); 228 return params.build(); 229 }) 230 .build(); 231 GrpcCallSettings<UpdateJobRequest, Job> updateJobTransportSettings = 232 GrpcCallSettings.<UpdateJobRequest, Job>newBuilder() 233 .setMethodDescriptor(updateJobMethodDescriptor) 234 .setParamsExtractor( 235 request -> { 236 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 237 params.put("job.name", String.valueOf(request.getJob().getName())); 238 return params.build(); 239 }) 240 .build(); 241 GrpcCallSettings<DeleteJobRequest, Empty> deleteJobTransportSettings = 242 GrpcCallSettings.<DeleteJobRequest, Empty>newBuilder() 243 .setMethodDescriptor(deleteJobMethodDescriptor) 244 .setParamsExtractor( 245 request -> { 246 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 247 params.put("name", String.valueOf(request.getName())); 248 return params.build(); 249 }) 250 .build(); 251 GrpcCallSettings<PauseJobRequest, Job> pauseJobTransportSettings = 252 GrpcCallSettings.<PauseJobRequest, Job>newBuilder() 253 .setMethodDescriptor(pauseJobMethodDescriptor) 254 .setParamsExtractor( 255 request -> { 256 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 257 params.put("name", String.valueOf(request.getName())); 258 return params.build(); 259 }) 260 .build(); 261 GrpcCallSettings<ResumeJobRequest, Job> resumeJobTransportSettings = 262 GrpcCallSettings.<ResumeJobRequest, Job>newBuilder() 263 .setMethodDescriptor(resumeJobMethodDescriptor) 264 .setParamsExtractor( 265 request -> { 266 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 267 params.put("name", String.valueOf(request.getName())); 268 return params.build(); 269 }) 270 .build(); 271 GrpcCallSettings<RunJobRequest, Job> runJobTransportSettings = 272 GrpcCallSettings.<RunJobRequest, Job>newBuilder() 273 .setMethodDescriptor(runJobMethodDescriptor) 274 .setParamsExtractor( 275 request -> { 276 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 277 params.put("name", String.valueOf(request.getName())); 278 return params.build(); 279 }) 280 .build(); 281 GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings = 282 GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder() 283 .setMethodDescriptor(listLocationsMethodDescriptor) 284 .setParamsExtractor( 285 request -> { 286 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 287 params.put("name", String.valueOf(request.getName())); 288 return params.build(); 289 }) 290 .build(); 291 GrpcCallSettings<GetLocationRequest, Location> getLocationTransportSettings = 292 GrpcCallSettings.<GetLocationRequest, Location>newBuilder() 293 .setMethodDescriptor(getLocationMethodDescriptor) 294 .setParamsExtractor( 295 request -> { 296 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 297 params.put("name", String.valueOf(request.getName())); 298 return params.build(); 299 }) 300 .build(); 301 302 this.listJobsCallable = 303 callableFactory.createUnaryCallable( 304 listJobsTransportSettings, settings.listJobsSettings(), clientContext); 305 this.listJobsPagedCallable = 306 callableFactory.createPagedCallable( 307 listJobsTransportSettings, settings.listJobsSettings(), clientContext); 308 this.getJobCallable = 309 callableFactory.createUnaryCallable( 310 getJobTransportSettings, settings.getJobSettings(), clientContext); 311 this.createJobCallable = 312 callableFactory.createUnaryCallable( 313 createJobTransportSettings, settings.createJobSettings(), clientContext); 314 this.updateJobCallable = 315 callableFactory.createUnaryCallable( 316 updateJobTransportSettings, settings.updateJobSettings(), clientContext); 317 this.deleteJobCallable = 318 callableFactory.createUnaryCallable( 319 deleteJobTransportSettings, settings.deleteJobSettings(), clientContext); 320 this.pauseJobCallable = 321 callableFactory.createUnaryCallable( 322 pauseJobTransportSettings, settings.pauseJobSettings(), clientContext); 323 this.resumeJobCallable = 324 callableFactory.createUnaryCallable( 325 resumeJobTransportSettings, settings.resumeJobSettings(), clientContext); 326 this.runJobCallable = 327 callableFactory.createUnaryCallable( 328 runJobTransportSettings, settings.runJobSettings(), clientContext); 329 this.listLocationsCallable = 330 callableFactory.createUnaryCallable( 331 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 332 this.listLocationsPagedCallable = 333 callableFactory.createPagedCallable( 334 listLocationsTransportSettings, settings.listLocationsSettings(), clientContext); 335 this.getLocationCallable = 336 callableFactory.createUnaryCallable( 337 getLocationTransportSettings, settings.getLocationSettings(), clientContext); 338 339 this.backgroundResources = 340 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 341 } 342 getOperationsStub()343 public GrpcOperationsStub getOperationsStub() { 344 return operationsStub; 345 } 346 347 @Override listJobsCallable()348 public UnaryCallable<ListJobsRequest, ListJobsResponse> listJobsCallable() { 349 return listJobsCallable; 350 } 351 352 @Override listJobsPagedCallable()353 public UnaryCallable<ListJobsRequest, ListJobsPagedResponse> listJobsPagedCallable() { 354 return listJobsPagedCallable; 355 } 356 357 @Override getJobCallable()358 public UnaryCallable<GetJobRequest, Job> getJobCallable() { 359 return getJobCallable; 360 } 361 362 @Override createJobCallable()363 public UnaryCallable<CreateJobRequest, Job> createJobCallable() { 364 return createJobCallable; 365 } 366 367 @Override updateJobCallable()368 public UnaryCallable<UpdateJobRequest, Job> updateJobCallable() { 369 return updateJobCallable; 370 } 371 372 @Override deleteJobCallable()373 public UnaryCallable<DeleteJobRequest, Empty> deleteJobCallable() { 374 return deleteJobCallable; 375 } 376 377 @Override pauseJobCallable()378 public UnaryCallable<PauseJobRequest, Job> pauseJobCallable() { 379 return pauseJobCallable; 380 } 381 382 @Override resumeJobCallable()383 public UnaryCallable<ResumeJobRequest, Job> resumeJobCallable() { 384 return resumeJobCallable; 385 } 386 387 @Override runJobCallable()388 public UnaryCallable<RunJobRequest, Job> runJobCallable() { 389 return runJobCallable; 390 } 391 392 @Override listLocationsCallable()393 public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 394 return listLocationsCallable; 395 } 396 397 @Override 398 public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()399 listLocationsPagedCallable() { 400 return listLocationsPagedCallable; 401 } 402 403 @Override getLocationCallable()404 public UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 405 return getLocationCallable; 406 } 407 408 @Override close()409 public final void close() { 410 try { 411 backgroundResources.close(); 412 } catch (RuntimeException e) { 413 throw e; 414 } catch (Exception e) { 415 throw new IllegalStateException("Failed to close resource", e); 416 } 417 } 418 419 @Override shutdown()420 public void shutdown() { 421 backgroundResources.shutdown(); 422 } 423 424 @Override isShutdown()425 public boolean isShutdown() { 426 return backgroundResources.isShutdown(); 427 } 428 429 @Override isTerminated()430 public boolean isTerminated() { 431 return backgroundResources.isTerminated(); 432 } 433 434 @Override shutdownNow()435 public void shutdownNow() { 436 backgroundResources.shutdownNow(); 437 } 438 439 @Override awaitTermination(long duration, TimeUnit unit)440 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 441 return backgroundResources.awaitTermination(duration, unit); 442 } 443 } 444