• 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.language.v1.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.language.v1.AnalyzeEntitiesRequest;
26 import com.google.cloud.language.v1.AnalyzeEntitiesResponse;
27 import com.google.cloud.language.v1.AnalyzeEntitySentimentRequest;
28 import com.google.cloud.language.v1.AnalyzeEntitySentimentResponse;
29 import com.google.cloud.language.v1.AnalyzeSentimentRequest;
30 import com.google.cloud.language.v1.AnalyzeSentimentResponse;
31 import com.google.cloud.language.v1.AnalyzeSyntaxRequest;
32 import com.google.cloud.language.v1.AnalyzeSyntaxResponse;
33 import com.google.cloud.language.v1.AnnotateTextRequest;
34 import com.google.cloud.language.v1.AnnotateTextResponse;
35 import com.google.cloud.language.v1.ClassifyTextRequest;
36 import com.google.cloud.language.v1.ClassifyTextResponse;
37 import com.google.longrunning.stub.GrpcOperationsStub;
38 import io.grpc.MethodDescriptor;
39 import io.grpc.protobuf.ProtoUtils;
40 import java.io.IOException;
41 import java.util.concurrent.TimeUnit;
42 import javax.annotation.Generated;
43 
44 // AUTO-GENERATED DOCUMENTATION AND CLASS.
45 /**
46  * gRPC stub implementation for the LanguageService service API.
47  *
48  * <p>This class is for advanced usage and reflects the underlying API directly.
49  */
50 @Generated("by gapic-generator-java")
51 public class GrpcLanguageServiceStub extends LanguageServiceStub {
52   private static final MethodDescriptor<AnalyzeSentimentRequest, AnalyzeSentimentResponse>
53       analyzeSentimentMethodDescriptor =
54           MethodDescriptor.<AnalyzeSentimentRequest, AnalyzeSentimentResponse>newBuilder()
55               .setType(MethodDescriptor.MethodType.UNARY)
56               .setFullMethodName("google.cloud.language.v1.LanguageService/AnalyzeSentiment")
57               .setRequestMarshaller(
58                   ProtoUtils.marshaller(AnalyzeSentimentRequest.getDefaultInstance()))
59               .setResponseMarshaller(
60                   ProtoUtils.marshaller(AnalyzeSentimentResponse.getDefaultInstance()))
61               .build();
62 
63   private static final MethodDescriptor<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>
64       analyzeEntitiesMethodDescriptor =
65           MethodDescriptor.<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>newBuilder()
66               .setType(MethodDescriptor.MethodType.UNARY)
67               .setFullMethodName("google.cloud.language.v1.LanguageService/AnalyzeEntities")
68               .setRequestMarshaller(
69                   ProtoUtils.marshaller(AnalyzeEntitiesRequest.getDefaultInstance()))
70               .setResponseMarshaller(
71                   ProtoUtils.marshaller(AnalyzeEntitiesResponse.getDefaultInstance()))
72               .build();
73 
74   private static final MethodDescriptor<
75           AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>
76       analyzeEntitySentimentMethodDescriptor =
77           MethodDescriptor
78               .<AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>newBuilder()
79               .setType(MethodDescriptor.MethodType.UNARY)
80               .setFullMethodName("google.cloud.language.v1.LanguageService/AnalyzeEntitySentiment")
81               .setRequestMarshaller(
82                   ProtoUtils.marshaller(AnalyzeEntitySentimentRequest.getDefaultInstance()))
83               .setResponseMarshaller(
84                   ProtoUtils.marshaller(AnalyzeEntitySentimentResponse.getDefaultInstance()))
85               .build();
86 
87   private static final MethodDescriptor<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse>
88       analyzeSyntaxMethodDescriptor =
89           MethodDescriptor.<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse>newBuilder()
90               .setType(MethodDescriptor.MethodType.UNARY)
91               .setFullMethodName("google.cloud.language.v1.LanguageService/AnalyzeSyntax")
92               .setRequestMarshaller(
93                   ProtoUtils.marshaller(AnalyzeSyntaxRequest.getDefaultInstance()))
94               .setResponseMarshaller(
95                   ProtoUtils.marshaller(AnalyzeSyntaxResponse.getDefaultInstance()))
96               .build();
97 
98   private static final MethodDescriptor<ClassifyTextRequest, ClassifyTextResponse>
99       classifyTextMethodDescriptor =
100           MethodDescriptor.<ClassifyTextRequest, ClassifyTextResponse>newBuilder()
101               .setType(MethodDescriptor.MethodType.UNARY)
102               .setFullMethodName("google.cloud.language.v1.LanguageService/ClassifyText")
103               .setRequestMarshaller(ProtoUtils.marshaller(ClassifyTextRequest.getDefaultInstance()))
104               .setResponseMarshaller(
105                   ProtoUtils.marshaller(ClassifyTextResponse.getDefaultInstance()))
106               .build();
107 
108   private static final MethodDescriptor<AnnotateTextRequest, AnnotateTextResponse>
109       annotateTextMethodDescriptor =
110           MethodDescriptor.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
111               .setType(MethodDescriptor.MethodType.UNARY)
112               .setFullMethodName("google.cloud.language.v1.LanguageService/AnnotateText")
113               .setRequestMarshaller(ProtoUtils.marshaller(AnnotateTextRequest.getDefaultInstance()))
114               .setResponseMarshaller(
115                   ProtoUtils.marshaller(AnnotateTextResponse.getDefaultInstance()))
116               .build();
117 
118   private final UnaryCallable<AnalyzeSentimentRequest, AnalyzeSentimentResponse>
119       analyzeSentimentCallable;
120   private final UnaryCallable<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>
121       analyzeEntitiesCallable;
122   private final UnaryCallable<AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>
123       analyzeEntitySentimentCallable;
124   private final UnaryCallable<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse> analyzeSyntaxCallable;
125   private final UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCallable;
126   private final UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable;
127 
128   private final BackgroundResource backgroundResources;
129   private final GrpcOperationsStub operationsStub;
130   private final GrpcStubCallableFactory callableFactory;
131 
create(LanguageServiceStubSettings settings)132   public static final GrpcLanguageServiceStub create(LanguageServiceStubSettings settings)
133       throws IOException {
134     return new GrpcLanguageServiceStub(settings, ClientContext.create(settings));
135   }
136 
create(ClientContext clientContext)137   public static final GrpcLanguageServiceStub create(ClientContext clientContext)
138       throws IOException {
139     return new GrpcLanguageServiceStub(
140         LanguageServiceStubSettings.newBuilder().build(), clientContext);
141   }
142 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)143   public static final GrpcLanguageServiceStub create(
144       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
145     return new GrpcLanguageServiceStub(
146         LanguageServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
147   }
148 
149   /**
150    * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected
151    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
152    * preferred.
153    */
GrpcLanguageServiceStub( LanguageServiceStubSettings settings, ClientContext clientContext)154   protected GrpcLanguageServiceStub(
155       LanguageServiceStubSettings settings, ClientContext clientContext) throws IOException {
156     this(settings, clientContext, new GrpcLanguageServiceCallableFactory());
157   }
158 
159   /**
160    * Constructs an instance of GrpcLanguageServiceStub, using the given settings. This is protected
161    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
162    * preferred.
163    */
GrpcLanguageServiceStub( LanguageServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)164   protected GrpcLanguageServiceStub(
165       LanguageServiceStubSettings settings,
166       ClientContext clientContext,
167       GrpcStubCallableFactory callableFactory)
168       throws IOException {
169     this.callableFactory = callableFactory;
170     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
171 
172     GrpcCallSettings<AnalyzeSentimentRequest, AnalyzeSentimentResponse>
173         analyzeSentimentTransportSettings =
174             GrpcCallSettings.<AnalyzeSentimentRequest, AnalyzeSentimentResponse>newBuilder()
175                 .setMethodDescriptor(analyzeSentimentMethodDescriptor)
176                 .build();
177     GrpcCallSettings<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>
178         analyzeEntitiesTransportSettings =
179             GrpcCallSettings.<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse>newBuilder()
180                 .setMethodDescriptor(analyzeEntitiesMethodDescriptor)
181                 .build();
182     GrpcCallSettings<AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>
183         analyzeEntitySentimentTransportSettings =
184             GrpcCallSettings
185                 .<AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>newBuilder()
186                 .setMethodDescriptor(analyzeEntitySentimentMethodDescriptor)
187                 .build();
188     GrpcCallSettings<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse> analyzeSyntaxTransportSettings =
189         GrpcCallSettings.<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse>newBuilder()
190             .setMethodDescriptor(analyzeSyntaxMethodDescriptor)
191             .build();
192     GrpcCallSettings<ClassifyTextRequest, ClassifyTextResponse> classifyTextTransportSettings =
193         GrpcCallSettings.<ClassifyTextRequest, ClassifyTextResponse>newBuilder()
194             .setMethodDescriptor(classifyTextMethodDescriptor)
195             .build();
196     GrpcCallSettings<AnnotateTextRequest, AnnotateTextResponse> annotateTextTransportSettings =
197         GrpcCallSettings.<AnnotateTextRequest, AnnotateTextResponse>newBuilder()
198             .setMethodDescriptor(annotateTextMethodDescriptor)
199             .build();
200 
201     this.analyzeSentimentCallable =
202         callableFactory.createUnaryCallable(
203             analyzeSentimentTransportSettings, settings.analyzeSentimentSettings(), clientContext);
204     this.analyzeEntitiesCallable =
205         callableFactory.createUnaryCallable(
206             analyzeEntitiesTransportSettings, settings.analyzeEntitiesSettings(), clientContext);
207     this.analyzeEntitySentimentCallable =
208         callableFactory.createUnaryCallable(
209             analyzeEntitySentimentTransportSettings,
210             settings.analyzeEntitySentimentSettings(),
211             clientContext);
212     this.analyzeSyntaxCallable =
213         callableFactory.createUnaryCallable(
214             analyzeSyntaxTransportSettings, settings.analyzeSyntaxSettings(), clientContext);
215     this.classifyTextCallable =
216         callableFactory.createUnaryCallable(
217             classifyTextTransportSettings, settings.classifyTextSettings(), clientContext);
218     this.annotateTextCallable =
219         callableFactory.createUnaryCallable(
220             annotateTextTransportSettings, settings.annotateTextSettings(), clientContext);
221 
222     this.backgroundResources =
223         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
224   }
225 
getOperationsStub()226   public GrpcOperationsStub getOperationsStub() {
227     return operationsStub;
228   }
229 
230   @Override
231   public UnaryCallable<AnalyzeSentimentRequest, AnalyzeSentimentResponse>
analyzeSentimentCallable()232       analyzeSentimentCallable() {
233     return analyzeSentimentCallable;
234   }
235 
236   @Override
analyzeEntitiesCallable()237   public UnaryCallable<AnalyzeEntitiesRequest, AnalyzeEntitiesResponse> analyzeEntitiesCallable() {
238     return analyzeEntitiesCallable;
239   }
240 
241   @Override
242   public UnaryCallable<AnalyzeEntitySentimentRequest, AnalyzeEntitySentimentResponse>
analyzeEntitySentimentCallable()243       analyzeEntitySentimentCallable() {
244     return analyzeEntitySentimentCallable;
245   }
246 
247   @Override
analyzeSyntaxCallable()248   public UnaryCallable<AnalyzeSyntaxRequest, AnalyzeSyntaxResponse> analyzeSyntaxCallable() {
249     return analyzeSyntaxCallable;
250   }
251 
252   @Override
classifyTextCallable()253   public UnaryCallable<ClassifyTextRequest, ClassifyTextResponse> classifyTextCallable() {
254     return classifyTextCallable;
255   }
256 
257   @Override
annotateTextCallable()258   public UnaryCallable<AnnotateTextRequest, AnnotateTextResponse> annotateTextCallable() {
259     return annotateTextCallable;
260   }
261 
262   @Override
close()263   public final void close() {
264     try {
265       backgroundResources.close();
266     } catch (RuntimeException e) {
267       throw e;
268     } catch (Exception e) {
269       throw new IllegalStateException("Failed to close resource", e);
270     }
271   }
272 
273   @Override
shutdown()274   public void shutdown() {
275     backgroundResources.shutdown();
276   }
277 
278   @Override
isShutdown()279   public boolean isShutdown() {
280     return backgroundResources.isShutdown();
281   }
282 
283   @Override
isTerminated()284   public boolean isTerminated() {
285     return backgroundResources.isTerminated();
286   }
287 
288   @Override
shutdownNow()289   public void shutdownNow() {
290     backgroundResources.shutdownNow();
291   }
292 
293   @Override
awaitTermination(long duration, TimeUnit unit)294   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
295     return backgroundResources.awaitTermination(duration, unit);
296   }
297 }
298