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