• 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.dialogflow.v2.stub;
18 
19 import static com.google.cloud.dialogflow.v2.EnvironmentsClient.GetEnvironmentHistoryPagedResponse;
20 import static com.google.cloud.dialogflow.v2.EnvironmentsClient.ListEnvironmentsPagedResponse;
21 import static com.google.cloud.dialogflow.v2.EnvironmentsClient.ListLocationsPagedResponse;
22 
23 import com.google.api.gax.core.BackgroundResource;
24 import com.google.api.gax.core.BackgroundResourceAggregation;
25 import com.google.api.gax.grpc.GrpcCallSettings;
26 import com.google.api.gax.grpc.GrpcStubCallableFactory;
27 import com.google.api.gax.rpc.ClientContext;
28 import com.google.api.gax.rpc.UnaryCallable;
29 import com.google.cloud.dialogflow.v2.CreateEnvironmentRequest;
30 import com.google.cloud.dialogflow.v2.DeleteEnvironmentRequest;
31 import com.google.cloud.dialogflow.v2.Environment;
32 import com.google.cloud.dialogflow.v2.EnvironmentHistory;
33 import com.google.cloud.dialogflow.v2.GetEnvironmentHistoryRequest;
34 import com.google.cloud.dialogflow.v2.GetEnvironmentRequest;
35 import com.google.cloud.dialogflow.v2.ListEnvironmentsRequest;
36 import com.google.cloud.dialogflow.v2.ListEnvironmentsResponse;
37 import com.google.cloud.dialogflow.v2.UpdateEnvironmentRequest;
38 import com.google.cloud.location.GetLocationRequest;
39 import com.google.cloud.location.ListLocationsRequest;
40 import com.google.cloud.location.ListLocationsResponse;
41 import com.google.cloud.location.Location;
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 Environments 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 GrpcEnvironmentsStub extends EnvironmentsStub {
59   private static final MethodDescriptor<ListEnvironmentsRequest, ListEnvironmentsResponse>
60       listEnvironmentsMethodDescriptor =
61           MethodDescriptor.<ListEnvironmentsRequest, ListEnvironmentsResponse>newBuilder()
62               .setType(MethodDescriptor.MethodType.UNARY)
63               .setFullMethodName("google.cloud.dialogflow.v2.Environments/ListEnvironments")
64               .setRequestMarshaller(
65                   ProtoUtils.marshaller(ListEnvironmentsRequest.getDefaultInstance()))
66               .setResponseMarshaller(
67                   ProtoUtils.marshaller(ListEnvironmentsResponse.getDefaultInstance()))
68               .build();
69 
70   private static final MethodDescriptor<GetEnvironmentRequest, Environment>
71       getEnvironmentMethodDescriptor =
72           MethodDescriptor.<GetEnvironmentRequest, Environment>newBuilder()
73               .setType(MethodDescriptor.MethodType.UNARY)
74               .setFullMethodName("google.cloud.dialogflow.v2.Environments/GetEnvironment")
75               .setRequestMarshaller(
76                   ProtoUtils.marshaller(GetEnvironmentRequest.getDefaultInstance()))
77               .setResponseMarshaller(ProtoUtils.marshaller(Environment.getDefaultInstance()))
78               .build();
79 
80   private static final MethodDescriptor<CreateEnvironmentRequest, Environment>
81       createEnvironmentMethodDescriptor =
82           MethodDescriptor.<CreateEnvironmentRequest, Environment>newBuilder()
83               .setType(MethodDescriptor.MethodType.UNARY)
84               .setFullMethodName("google.cloud.dialogflow.v2.Environments/CreateEnvironment")
85               .setRequestMarshaller(
86                   ProtoUtils.marshaller(CreateEnvironmentRequest.getDefaultInstance()))
87               .setResponseMarshaller(ProtoUtils.marshaller(Environment.getDefaultInstance()))
88               .build();
89 
90   private static final MethodDescriptor<UpdateEnvironmentRequest, Environment>
91       updateEnvironmentMethodDescriptor =
92           MethodDescriptor.<UpdateEnvironmentRequest, Environment>newBuilder()
93               .setType(MethodDescriptor.MethodType.UNARY)
94               .setFullMethodName("google.cloud.dialogflow.v2.Environments/UpdateEnvironment")
95               .setRequestMarshaller(
96                   ProtoUtils.marshaller(UpdateEnvironmentRequest.getDefaultInstance()))
97               .setResponseMarshaller(ProtoUtils.marshaller(Environment.getDefaultInstance()))
98               .build();
99 
100   private static final MethodDescriptor<DeleteEnvironmentRequest, Empty>
101       deleteEnvironmentMethodDescriptor =
102           MethodDescriptor.<DeleteEnvironmentRequest, Empty>newBuilder()
103               .setType(MethodDescriptor.MethodType.UNARY)
104               .setFullMethodName("google.cloud.dialogflow.v2.Environments/DeleteEnvironment")
105               .setRequestMarshaller(
106                   ProtoUtils.marshaller(DeleteEnvironmentRequest.getDefaultInstance()))
107               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
108               .build();
109 
110   private static final MethodDescriptor<GetEnvironmentHistoryRequest, EnvironmentHistory>
111       getEnvironmentHistoryMethodDescriptor =
112           MethodDescriptor.<GetEnvironmentHistoryRequest, EnvironmentHistory>newBuilder()
113               .setType(MethodDescriptor.MethodType.UNARY)
114               .setFullMethodName("google.cloud.dialogflow.v2.Environments/GetEnvironmentHistory")
115               .setRequestMarshaller(
116                   ProtoUtils.marshaller(GetEnvironmentHistoryRequest.getDefaultInstance()))
117               .setResponseMarshaller(ProtoUtils.marshaller(EnvironmentHistory.getDefaultInstance()))
118               .build();
119 
120   private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse>
121       listLocationsMethodDescriptor =
122           MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder()
123               .setType(MethodDescriptor.MethodType.UNARY)
124               .setFullMethodName("google.cloud.location.Locations/ListLocations")
125               .setRequestMarshaller(
126                   ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance()))
127               .setResponseMarshaller(
128                   ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance()))
129               .build();
130 
131   private static final MethodDescriptor<GetLocationRequest, Location> getLocationMethodDescriptor =
132       MethodDescriptor.<GetLocationRequest, Location>newBuilder()
133           .setType(MethodDescriptor.MethodType.UNARY)
134           .setFullMethodName("google.cloud.location.Locations/GetLocation")
135           .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance()))
136           .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance()))
137           .build();
138 
139   private final UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsResponse>
140       listEnvironmentsCallable;
141   private final UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
142       listEnvironmentsPagedCallable;
143   private final UnaryCallable<GetEnvironmentRequest, Environment> getEnvironmentCallable;
144   private final UnaryCallable<CreateEnvironmentRequest, Environment> createEnvironmentCallable;
145   private final UnaryCallable<UpdateEnvironmentRequest, Environment> updateEnvironmentCallable;
146   private final UnaryCallable<DeleteEnvironmentRequest, Empty> deleteEnvironmentCallable;
147   private final UnaryCallable<GetEnvironmentHistoryRequest, EnvironmentHistory>
148       getEnvironmentHistoryCallable;
149   private final UnaryCallable<GetEnvironmentHistoryRequest, GetEnvironmentHistoryPagedResponse>
150       getEnvironmentHistoryPagedCallable;
151   private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable;
152   private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
153       listLocationsPagedCallable;
154   private final UnaryCallable<GetLocationRequest, Location> getLocationCallable;
155 
156   private final BackgroundResource backgroundResources;
157   private final GrpcOperationsStub operationsStub;
158   private final GrpcStubCallableFactory callableFactory;
159 
create(EnvironmentsStubSettings settings)160   public static final GrpcEnvironmentsStub create(EnvironmentsStubSettings settings)
161       throws IOException {
162     return new GrpcEnvironmentsStub(settings, ClientContext.create(settings));
163   }
164 
create(ClientContext clientContext)165   public static final GrpcEnvironmentsStub create(ClientContext clientContext) throws IOException {
166     return new GrpcEnvironmentsStub(EnvironmentsStubSettings.newBuilder().build(), clientContext);
167   }
168 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)169   public static final GrpcEnvironmentsStub create(
170       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
171     return new GrpcEnvironmentsStub(
172         EnvironmentsStubSettings.newBuilder().build(), clientContext, callableFactory);
173   }
174 
175   /**
176    * Constructs an instance of GrpcEnvironmentsStub, using the given settings. This is protected so
177    * that it is easy to make a subclass, but otherwise, the static factory methods should be
178    * preferred.
179    */
GrpcEnvironmentsStub(EnvironmentsStubSettings settings, ClientContext clientContext)180   protected GrpcEnvironmentsStub(EnvironmentsStubSettings settings, ClientContext clientContext)
181       throws IOException {
182     this(settings, clientContext, new GrpcEnvironmentsCallableFactory());
183   }
184 
185   /**
186    * Constructs an instance of GrpcEnvironmentsStub, using the given settings. This is protected so
187    * that it is easy to make a subclass, but otherwise, the static factory methods should be
188    * preferred.
189    */
GrpcEnvironmentsStub( EnvironmentsStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)190   protected GrpcEnvironmentsStub(
191       EnvironmentsStubSettings settings,
192       ClientContext clientContext,
193       GrpcStubCallableFactory callableFactory)
194       throws IOException {
195     this.callableFactory = callableFactory;
196     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
197 
198     GrpcCallSettings<ListEnvironmentsRequest, ListEnvironmentsResponse>
199         listEnvironmentsTransportSettings =
200             GrpcCallSettings.<ListEnvironmentsRequest, ListEnvironmentsResponse>newBuilder()
201                 .setMethodDescriptor(listEnvironmentsMethodDescriptor)
202                 .setParamsExtractor(
203                     request -> {
204                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
205                       params.put("parent", String.valueOf(request.getParent()));
206                       return params.build();
207                     })
208                 .build();
209     GrpcCallSettings<GetEnvironmentRequest, Environment> getEnvironmentTransportSettings =
210         GrpcCallSettings.<GetEnvironmentRequest, Environment>newBuilder()
211             .setMethodDescriptor(getEnvironmentMethodDescriptor)
212             .setParamsExtractor(
213                 request -> {
214                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
215                   params.put("name", String.valueOf(request.getName()));
216                   return params.build();
217                 })
218             .build();
219     GrpcCallSettings<CreateEnvironmentRequest, Environment> createEnvironmentTransportSettings =
220         GrpcCallSettings.<CreateEnvironmentRequest, Environment>newBuilder()
221             .setMethodDescriptor(createEnvironmentMethodDescriptor)
222             .setParamsExtractor(
223                 request -> {
224                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
225                   params.put("parent", String.valueOf(request.getParent()));
226                   return params.build();
227                 })
228             .build();
229     GrpcCallSettings<UpdateEnvironmentRequest, Environment> updateEnvironmentTransportSettings =
230         GrpcCallSettings.<UpdateEnvironmentRequest, Environment>newBuilder()
231             .setMethodDescriptor(updateEnvironmentMethodDescriptor)
232             .setParamsExtractor(
233                 request -> {
234                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
235                   params.put(
236                       "environment.name", String.valueOf(request.getEnvironment().getName()));
237                   return params.build();
238                 })
239             .build();
240     GrpcCallSettings<DeleteEnvironmentRequest, Empty> deleteEnvironmentTransportSettings =
241         GrpcCallSettings.<DeleteEnvironmentRequest, Empty>newBuilder()
242             .setMethodDescriptor(deleteEnvironmentMethodDescriptor)
243             .setParamsExtractor(
244                 request -> {
245                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
246                   params.put("name", String.valueOf(request.getName()));
247                   return params.build();
248                 })
249             .build();
250     GrpcCallSettings<GetEnvironmentHistoryRequest, EnvironmentHistory>
251         getEnvironmentHistoryTransportSettings =
252             GrpcCallSettings.<GetEnvironmentHistoryRequest, EnvironmentHistory>newBuilder()
253                 .setMethodDescriptor(getEnvironmentHistoryMethodDescriptor)
254                 .setParamsExtractor(
255                     request -> {
256                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
257                       params.put("parent", String.valueOf(request.getParent()));
258                       return params.build();
259                     })
260                 .build();
261     GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings =
262         GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder()
263             .setMethodDescriptor(listLocationsMethodDescriptor)
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<GetLocationRequest, Location> getLocationTransportSettings =
272         GrpcCallSettings.<GetLocationRequest, Location>newBuilder()
273             .setMethodDescriptor(getLocationMethodDescriptor)
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 
282     this.listEnvironmentsCallable =
283         callableFactory.createUnaryCallable(
284             listEnvironmentsTransportSettings, settings.listEnvironmentsSettings(), clientContext);
285     this.listEnvironmentsPagedCallable =
286         callableFactory.createPagedCallable(
287             listEnvironmentsTransportSettings, settings.listEnvironmentsSettings(), clientContext);
288     this.getEnvironmentCallable =
289         callableFactory.createUnaryCallable(
290             getEnvironmentTransportSettings, settings.getEnvironmentSettings(), clientContext);
291     this.createEnvironmentCallable =
292         callableFactory.createUnaryCallable(
293             createEnvironmentTransportSettings,
294             settings.createEnvironmentSettings(),
295             clientContext);
296     this.updateEnvironmentCallable =
297         callableFactory.createUnaryCallable(
298             updateEnvironmentTransportSettings,
299             settings.updateEnvironmentSettings(),
300             clientContext);
301     this.deleteEnvironmentCallable =
302         callableFactory.createUnaryCallable(
303             deleteEnvironmentTransportSettings,
304             settings.deleteEnvironmentSettings(),
305             clientContext);
306     this.getEnvironmentHistoryCallable =
307         callableFactory.createUnaryCallable(
308             getEnvironmentHistoryTransportSettings,
309             settings.getEnvironmentHistorySettings(),
310             clientContext);
311     this.getEnvironmentHistoryPagedCallable =
312         callableFactory.createPagedCallable(
313             getEnvironmentHistoryTransportSettings,
314             settings.getEnvironmentHistorySettings(),
315             clientContext);
316     this.listLocationsCallable =
317         callableFactory.createUnaryCallable(
318             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
319     this.listLocationsPagedCallable =
320         callableFactory.createPagedCallable(
321             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
322     this.getLocationCallable =
323         callableFactory.createUnaryCallable(
324             getLocationTransportSettings, settings.getLocationSettings(), clientContext);
325 
326     this.backgroundResources =
327         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
328   }
329 
getOperationsStub()330   public GrpcOperationsStub getOperationsStub() {
331     return operationsStub;
332   }
333 
334   @Override
335   public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsResponse>
listEnvironmentsCallable()336       listEnvironmentsCallable() {
337     return listEnvironmentsCallable;
338   }
339 
340   @Override
341   public UnaryCallable<ListEnvironmentsRequest, ListEnvironmentsPagedResponse>
listEnvironmentsPagedCallable()342       listEnvironmentsPagedCallable() {
343     return listEnvironmentsPagedCallable;
344   }
345 
346   @Override
getEnvironmentCallable()347   public UnaryCallable<GetEnvironmentRequest, Environment> getEnvironmentCallable() {
348     return getEnvironmentCallable;
349   }
350 
351   @Override
createEnvironmentCallable()352   public UnaryCallable<CreateEnvironmentRequest, Environment> createEnvironmentCallable() {
353     return createEnvironmentCallable;
354   }
355 
356   @Override
updateEnvironmentCallable()357   public UnaryCallable<UpdateEnvironmentRequest, Environment> updateEnvironmentCallable() {
358     return updateEnvironmentCallable;
359   }
360 
361   @Override
deleteEnvironmentCallable()362   public UnaryCallable<DeleteEnvironmentRequest, Empty> deleteEnvironmentCallable() {
363     return deleteEnvironmentCallable;
364   }
365 
366   @Override
367   public UnaryCallable<GetEnvironmentHistoryRequest, EnvironmentHistory>
getEnvironmentHistoryCallable()368       getEnvironmentHistoryCallable() {
369     return getEnvironmentHistoryCallable;
370   }
371 
372   @Override
373   public UnaryCallable<GetEnvironmentHistoryRequest, GetEnvironmentHistoryPagedResponse>
getEnvironmentHistoryPagedCallable()374       getEnvironmentHistoryPagedCallable() {
375     return getEnvironmentHistoryPagedCallable;
376   }
377 
378   @Override
listLocationsCallable()379   public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
380     return listLocationsCallable;
381   }
382 
383   @Override
384   public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable()385       listLocationsPagedCallable() {
386     return listLocationsPagedCallable;
387   }
388 
389   @Override
getLocationCallable()390   public UnaryCallable<GetLocationRequest, Location> getLocationCallable() {
391     return getLocationCallable;
392   }
393 
394   @Override
close()395   public final void close() {
396     try {
397       backgroundResources.close();
398     } catch (RuntimeException e) {
399       throw e;
400     } catch (Exception e) {
401       throw new IllegalStateException("Failed to close resource", e);
402     }
403   }
404 
405   @Override
shutdown()406   public void shutdown() {
407     backgroundResources.shutdown();
408   }
409 
410   @Override
isShutdown()411   public boolean isShutdown() {
412     return backgroundResources.isShutdown();
413   }
414 
415   @Override
isTerminated()416   public boolean isTerminated() {
417     return backgroundResources.isTerminated();
418   }
419 
420   @Override
shutdownNow()421   public void shutdownNow() {
422     backgroundResources.shutdownNow();
423   }
424 
425   @Override
awaitTermination(long duration, TimeUnit unit)426   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
427     return backgroundResources.awaitTermination(duration, unit);
428   }
429 }
430