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.talent.v4beta1.stub; 18 19 import com.google.api.core.BetaApi; 20 import com.google.api.gax.core.BackgroundResource; 21 import com.google.api.gax.core.BackgroundResourceAggregation; 22 import com.google.api.gax.grpc.GrpcCallSettings; 23 import com.google.api.gax.grpc.GrpcStubCallableFactory; 24 import com.google.api.gax.rpc.ClientContext; 25 import com.google.api.gax.rpc.UnaryCallable; 26 import com.google.cloud.talent.v4beta1.CompleteQueryRequest; 27 import com.google.cloud.talent.v4beta1.CompleteQueryResponse; 28 import com.google.common.collect.ImmutableMap; 29 import com.google.longrunning.stub.GrpcOperationsStub; 30 import io.grpc.MethodDescriptor; 31 import io.grpc.protobuf.ProtoUtils; 32 import java.io.IOException; 33 import java.util.concurrent.TimeUnit; 34 import javax.annotation.Generated; 35 36 // AUTO-GENERATED DOCUMENTATION AND CLASS. 37 /** 38 * gRPC stub implementation for the Completion service API. 39 * 40 * <p>This class is for advanced usage and reflects the underlying API directly. 41 */ 42 @BetaApi 43 @Generated("by gapic-generator-java") 44 public class GrpcCompletionStub extends CompletionStub { 45 private static final MethodDescriptor<CompleteQueryRequest, CompleteQueryResponse> 46 completeQueryMethodDescriptor = 47 MethodDescriptor.<CompleteQueryRequest, CompleteQueryResponse>newBuilder() 48 .setType(MethodDescriptor.MethodType.UNARY) 49 .setFullMethodName("google.cloud.talent.v4beta1.Completion/CompleteQuery") 50 .setRequestMarshaller( 51 ProtoUtils.marshaller(CompleteQueryRequest.getDefaultInstance())) 52 .setResponseMarshaller( 53 ProtoUtils.marshaller(CompleteQueryResponse.getDefaultInstance())) 54 .build(); 55 56 private final UnaryCallable<CompleteQueryRequest, CompleteQueryResponse> completeQueryCallable; 57 58 private final BackgroundResource backgroundResources; 59 private final GrpcOperationsStub operationsStub; 60 private final GrpcStubCallableFactory callableFactory; 61 create(CompletionStubSettings settings)62 public static final GrpcCompletionStub create(CompletionStubSettings settings) 63 throws IOException { 64 return new GrpcCompletionStub(settings, ClientContext.create(settings)); 65 } 66 create(ClientContext clientContext)67 public static final GrpcCompletionStub create(ClientContext clientContext) throws IOException { 68 return new GrpcCompletionStub(CompletionStubSettings.newBuilder().build(), clientContext); 69 } 70 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)71 public static final GrpcCompletionStub create( 72 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 73 return new GrpcCompletionStub( 74 CompletionStubSettings.newBuilder().build(), clientContext, callableFactory); 75 } 76 77 /** 78 * Constructs an instance of GrpcCompletionStub, using the given settings. This is protected so 79 * that it is easy to make a subclass, but otherwise, the static factory methods should be 80 * preferred. 81 */ GrpcCompletionStub(CompletionStubSettings settings, ClientContext clientContext)82 protected GrpcCompletionStub(CompletionStubSettings settings, ClientContext clientContext) 83 throws IOException { 84 this(settings, clientContext, new GrpcCompletionCallableFactory()); 85 } 86 87 /** 88 * Constructs an instance of GrpcCompletionStub, using the given settings. This is protected so 89 * that it is easy to make a subclass, but otherwise, the static factory methods should be 90 * preferred. 91 */ GrpcCompletionStub( CompletionStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)92 protected GrpcCompletionStub( 93 CompletionStubSettings settings, 94 ClientContext clientContext, 95 GrpcStubCallableFactory callableFactory) 96 throws IOException { 97 this.callableFactory = callableFactory; 98 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 99 100 GrpcCallSettings<CompleteQueryRequest, CompleteQueryResponse> completeQueryTransportSettings = 101 GrpcCallSettings.<CompleteQueryRequest, CompleteQueryResponse>newBuilder() 102 .setMethodDescriptor(completeQueryMethodDescriptor) 103 .setParamsExtractor( 104 request -> { 105 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 106 params.put("parent", String.valueOf(request.getParent())); 107 return params.build(); 108 }) 109 .build(); 110 111 this.completeQueryCallable = 112 callableFactory.createUnaryCallable( 113 completeQueryTransportSettings, settings.completeQuerySettings(), clientContext); 114 115 this.backgroundResources = 116 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 117 } 118 getOperationsStub()119 public GrpcOperationsStub getOperationsStub() { 120 return operationsStub; 121 } 122 123 @Override completeQueryCallable()124 public UnaryCallable<CompleteQueryRequest, CompleteQueryResponse> completeQueryCallable() { 125 return completeQueryCallable; 126 } 127 128 @Override close()129 public final void close() { 130 try { 131 backgroundResources.close(); 132 } catch (RuntimeException e) { 133 throw e; 134 } catch (Exception e) { 135 throw new IllegalStateException("Failed to close resource", e); 136 } 137 } 138 139 @Override shutdown()140 public void shutdown() { 141 backgroundResources.shutdown(); 142 } 143 144 @Override isShutdown()145 public boolean isShutdown() { 146 return backgroundResources.isShutdown(); 147 } 148 149 @Override isTerminated()150 public boolean isTerminated() { 151 return backgroundResources.isTerminated(); 152 } 153 154 @Override shutdownNow()155 public void shutdownNow() { 156 backgroundResources.shutdownNow(); 157 } 158 159 @Override awaitTermination(long duration, TimeUnit unit)160 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 161 return backgroundResources.awaitTermination(duration, unit); 162 } 163 } 164