• 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.FulfillmentsClient.ListLocationsPagedResponse;
20 
21 import com.google.api.gax.core.BackgroundResource;
22 import com.google.api.gax.core.BackgroundResourceAggregation;
23 import com.google.api.gax.grpc.GrpcCallSettings;
24 import com.google.api.gax.grpc.GrpcStubCallableFactory;
25 import com.google.api.gax.rpc.ClientContext;
26 import com.google.api.gax.rpc.UnaryCallable;
27 import com.google.cloud.dialogflow.v2.Fulfillment;
28 import com.google.cloud.dialogflow.v2.GetFulfillmentRequest;
29 import com.google.cloud.dialogflow.v2.UpdateFulfillmentRequest;
30 import com.google.cloud.location.GetLocationRequest;
31 import com.google.cloud.location.ListLocationsRequest;
32 import com.google.cloud.location.ListLocationsResponse;
33 import com.google.cloud.location.Location;
34 import com.google.common.collect.ImmutableMap;
35 import com.google.longrunning.stub.GrpcOperationsStub;
36 import io.grpc.MethodDescriptor;
37 import io.grpc.protobuf.ProtoUtils;
38 import java.io.IOException;
39 import java.util.concurrent.TimeUnit;
40 import javax.annotation.Generated;
41 
42 // AUTO-GENERATED DOCUMENTATION AND CLASS.
43 /**
44  * gRPC stub implementation for the Fulfillments service API.
45  *
46  * <p>This class is for advanced usage and reflects the underlying API directly.
47  */
48 @Generated("by gapic-generator-java")
49 public class GrpcFulfillmentsStub extends FulfillmentsStub {
50   private static final MethodDescriptor<GetFulfillmentRequest, Fulfillment>
51       getFulfillmentMethodDescriptor =
52           MethodDescriptor.<GetFulfillmentRequest, Fulfillment>newBuilder()
53               .setType(MethodDescriptor.MethodType.UNARY)
54               .setFullMethodName("google.cloud.dialogflow.v2.Fulfillments/GetFulfillment")
55               .setRequestMarshaller(
56                   ProtoUtils.marshaller(GetFulfillmentRequest.getDefaultInstance()))
57               .setResponseMarshaller(ProtoUtils.marshaller(Fulfillment.getDefaultInstance()))
58               .build();
59 
60   private static final MethodDescriptor<UpdateFulfillmentRequest, Fulfillment>
61       updateFulfillmentMethodDescriptor =
62           MethodDescriptor.<UpdateFulfillmentRequest, Fulfillment>newBuilder()
63               .setType(MethodDescriptor.MethodType.UNARY)
64               .setFullMethodName("google.cloud.dialogflow.v2.Fulfillments/UpdateFulfillment")
65               .setRequestMarshaller(
66                   ProtoUtils.marshaller(UpdateFulfillmentRequest.getDefaultInstance()))
67               .setResponseMarshaller(ProtoUtils.marshaller(Fulfillment.getDefaultInstance()))
68               .build();
69 
70   private static final MethodDescriptor<ListLocationsRequest, ListLocationsResponse>
71       listLocationsMethodDescriptor =
72           MethodDescriptor.<ListLocationsRequest, ListLocationsResponse>newBuilder()
73               .setType(MethodDescriptor.MethodType.UNARY)
74               .setFullMethodName("google.cloud.location.Locations/ListLocations")
75               .setRequestMarshaller(
76                   ProtoUtils.marshaller(ListLocationsRequest.getDefaultInstance()))
77               .setResponseMarshaller(
78                   ProtoUtils.marshaller(ListLocationsResponse.getDefaultInstance()))
79               .build();
80 
81   private static final MethodDescriptor<GetLocationRequest, Location> getLocationMethodDescriptor =
82       MethodDescriptor.<GetLocationRequest, Location>newBuilder()
83           .setType(MethodDescriptor.MethodType.UNARY)
84           .setFullMethodName("google.cloud.location.Locations/GetLocation")
85           .setRequestMarshaller(ProtoUtils.marshaller(GetLocationRequest.getDefaultInstance()))
86           .setResponseMarshaller(ProtoUtils.marshaller(Location.getDefaultInstance()))
87           .build();
88 
89   private final UnaryCallable<GetFulfillmentRequest, Fulfillment> getFulfillmentCallable;
90   private final UnaryCallable<UpdateFulfillmentRequest, Fulfillment> updateFulfillmentCallable;
91   private final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable;
92   private final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
93       listLocationsPagedCallable;
94   private final UnaryCallable<GetLocationRequest, Location> getLocationCallable;
95 
96   private final BackgroundResource backgroundResources;
97   private final GrpcOperationsStub operationsStub;
98   private final GrpcStubCallableFactory callableFactory;
99 
create(FulfillmentsStubSettings settings)100   public static final GrpcFulfillmentsStub create(FulfillmentsStubSettings settings)
101       throws IOException {
102     return new GrpcFulfillmentsStub(settings, ClientContext.create(settings));
103   }
104 
create(ClientContext clientContext)105   public static final GrpcFulfillmentsStub create(ClientContext clientContext) throws IOException {
106     return new GrpcFulfillmentsStub(FulfillmentsStubSettings.newBuilder().build(), clientContext);
107   }
108 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)109   public static final GrpcFulfillmentsStub create(
110       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
111     return new GrpcFulfillmentsStub(
112         FulfillmentsStubSettings.newBuilder().build(), clientContext, callableFactory);
113   }
114 
115   /**
116    * Constructs an instance of GrpcFulfillmentsStub, using the given settings. This is protected so
117    * that it is easy to make a subclass, but otherwise, the static factory methods should be
118    * preferred.
119    */
GrpcFulfillmentsStub(FulfillmentsStubSettings settings, ClientContext clientContext)120   protected GrpcFulfillmentsStub(FulfillmentsStubSettings settings, ClientContext clientContext)
121       throws IOException {
122     this(settings, clientContext, new GrpcFulfillmentsCallableFactory());
123   }
124 
125   /**
126    * Constructs an instance of GrpcFulfillmentsStub, using the given settings. This is protected so
127    * that it is easy to make a subclass, but otherwise, the static factory methods should be
128    * preferred.
129    */
GrpcFulfillmentsStub( FulfillmentsStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)130   protected GrpcFulfillmentsStub(
131       FulfillmentsStubSettings settings,
132       ClientContext clientContext,
133       GrpcStubCallableFactory callableFactory)
134       throws IOException {
135     this.callableFactory = callableFactory;
136     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
137 
138     GrpcCallSettings<GetFulfillmentRequest, Fulfillment> getFulfillmentTransportSettings =
139         GrpcCallSettings.<GetFulfillmentRequest, Fulfillment>newBuilder()
140             .setMethodDescriptor(getFulfillmentMethodDescriptor)
141             .setParamsExtractor(
142                 request -> {
143                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
144                   params.put("name", String.valueOf(request.getName()));
145                   return params.build();
146                 })
147             .build();
148     GrpcCallSettings<UpdateFulfillmentRequest, Fulfillment> updateFulfillmentTransportSettings =
149         GrpcCallSettings.<UpdateFulfillmentRequest, Fulfillment>newBuilder()
150             .setMethodDescriptor(updateFulfillmentMethodDescriptor)
151             .setParamsExtractor(
152                 request -> {
153                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
154                   params.put(
155                       "fulfillment.name", String.valueOf(request.getFulfillment().getName()));
156                   return params.build();
157                 })
158             .build();
159     GrpcCallSettings<ListLocationsRequest, ListLocationsResponse> listLocationsTransportSettings =
160         GrpcCallSettings.<ListLocationsRequest, ListLocationsResponse>newBuilder()
161             .setMethodDescriptor(listLocationsMethodDescriptor)
162             .setParamsExtractor(
163                 request -> {
164                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
165                   params.put("name", String.valueOf(request.getName()));
166                   return params.build();
167                 })
168             .build();
169     GrpcCallSettings<GetLocationRequest, Location> getLocationTransportSettings =
170         GrpcCallSettings.<GetLocationRequest, Location>newBuilder()
171             .setMethodDescriptor(getLocationMethodDescriptor)
172             .setParamsExtractor(
173                 request -> {
174                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
175                   params.put("name", String.valueOf(request.getName()));
176                   return params.build();
177                 })
178             .build();
179 
180     this.getFulfillmentCallable =
181         callableFactory.createUnaryCallable(
182             getFulfillmentTransportSettings, settings.getFulfillmentSettings(), clientContext);
183     this.updateFulfillmentCallable =
184         callableFactory.createUnaryCallable(
185             updateFulfillmentTransportSettings,
186             settings.updateFulfillmentSettings(),
187             clientContext);
188     this.listLocationsCallable =
189         callableFactory.createUnaryCallable(
190             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
191     this.listLocationsPagedCallable =
192         callableFactory.createPagedCallable(
193             listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
194     this.getLocationCallable =
195         callableFactory.createUnaryCallable(
196             getLocationTransportSettings, settings.getLocationSettings(), clientContext);
197 
198     this.backgroundResources =
199         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
200   }
201 
getOperationsStub()202   public GrpcOperationsStub getOperationsStub() {
203     return operationsStub;
204   }
205 
206   @Override
getFulfillmentCallable()207   public UnaryCallable<GetFulfillmentRequest, Fulfillment> getFulfillmentCallable() {
208     return getFulfillmentCallable;
209   }
210 
211   @Override
updateFulfillmentCallable()212   public UnaryCallable<UpdateFulfillmentRequest, Fulfillment> updateFulfillmentCallable() {
213     return updateFulfillmentCallable;
214   }
215 
216   @Override
listLocationsCallable()217   public UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() {
218     return listLocationsCallable;
219   }
220 
221   @Override
222   public UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse>
listLocationsPagedCallable()223       listLocationsPagedCallable() {
224     return listLocationsPagedCallable;
225   }
226 
227   @Override
getLocationCallable()228   public UnaryCallable<GetLocationRequest, Location> getLocationCallable() {
229     return getLocationCallable;
230   }
231 
232   @Override
close()233   public final void close() {
234     try {
235       backgroundResources.close();
236     } catch (RuntimeException e) {
237       throw e;
238     } catch (Exception e) {
239       throw new IllegalStateException("Failed to close resource", e);
240     }
241   }
242 
243   @Override
shutdown()244   public void shutdown() {
245     backgroundResources.shutdown();
246   }
247 
248   @Override
isShutdown()249   public boolean isShutdown() {
250     return backgroundResources.isShutdown();
251   }
252 
253   @Override
isTerminated()254   public boolean isTerminated() {
255     return backgroundResources.isTerminated();
256   }
257 
258   @Override
shutdownNow()259   public void shutdownNow() {
260     backgroundResources.shutdownNow();
261   }
262 
263   @Override
awaitTermination(long duration, TimeUnit unit)264   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
265     return backgroundResources.awaitTermination(duration, unit);
266   }
267 }
268