• 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.iot.v1.stub;
18 
19 import static com.google.cloud.iot.v1.DeviceManagerClient.ListDeviceRegistriesPagedResponse;
20 import static com.google.cloud.iot.v1.DeviceManagerClient.ListDevicesPagedResponse;
21 
22 import com.google.api.gax.core.BackgroundResource;
23 import com.google.api.gax.core.BackgroundResourceAggregation;
24 import com.google.api.gax.grpc.GrpcCallSettings;
25 import com.google.api.gax.grpc.GrpcStubCallableFactory;
26 import com.google.api.gax.rpc.ClientContext;
27 import com.google.api.gax.rpc.UnaryCallable;
28 import com.google.cloud.iot.v1.BindDeviceToGatewayRequest;
29 import com.google.cloud.iot.v1.BindDeviceToGatewayResponse;
30 import com.google.cloud.iot.v1.CreateDeviceRegistryRequest;
31 import com.google.cloud.iot.v1.CreateDeviceRequest;
32 import com.google.cloud.iot.v1.DeleteDeviceRegistryRequest;
33 import com.google.cloud.iot.v1.DeleteDeviceRequest;
34 import com.google.cloud.iot.v1.Device;
35 import com.google.cloud.iot.v1.DeviceConfig;
36 import com.google.cloud.iot.v1.DeviceRegistry;
37 import com.google.cloud.iot.v1.GetDeviceRegistryRequest;
38 import com.google.cloud.iot.v1.GetDeviceRequest;
39 import com.google.cloud.iot.v1.ListDeviceConfigVersionsRequest;
40 import com.google.cloud.iot.v1.ListDeviceConfigVersionsResponse;
41 import com.google.cloud.iot.v1.ListDeviceRegistriesRequest;
42 import com.google.cloud.iot.v1.ListDeviceRegistriesResponse;
43 import com.google.cloud.iot.v1.ListDeviceStatesRequest;
44 import com.google.cloud.iot.v1.ListDeviceStatesResponse;
45 import com.google.cloud.iot.v1.ListDevicesRequest;
46 import com.google.cloud.iot.v1.ListDevicesResponse;
47 import com.google.cloud.iot.v1.ModifyCloudToDeviceConfigRequest;
48 import com.google.cloud.iot.v1.SendCommandToDeviceRequest;
49 import com.google.cloud.iot.v1.SendCommandToDeviceResponse;
50 import com.google.cloud.iot.v1.UnbindDeviceFromGatewayRequest;
51 import com.google.cloud.iot.v1.UnbindDeviceFromGatewayResponse;
52 import com.google.cloud.iot.v1.UpdateDeviceRegistryRequest;
53 import com.google.cloud.iot.v1.UpdateDeviceRequest;
54 import com.google.common.collect.ImmutableMap;
55 import com.google.iam.v1.GetIamPolicyRequest;
56 import com.google.iam.v1.Policy;
57 import com.google.iam.v1.SetIamPolicyRequest;
58 import com.google.iam.v1.TestIamPermissionsRequest;
59 import com.google.iam.v1.TestIamPermissionsResponse;
60 import com.google.longrunning.stub.GrpcOperationsStub;
61 import com.google.protobuf.Empty;
62 import io.grpc.MethodDescriptor;
63 import io.grpc.protobuf.ProtoUtils;
64 import java.io.IOException;
65 import java.util.concurrent.TimeUnit;
66 import javax.annotation.Generated;
67 
68 // AUTO-GENERATED DOCUMENTATION AND CLASS.
69 /**
70  * gRPC stub implementation for the DeviceManager service API.
71  *
72  * <p>This class is for advanced usage and reflects the underlying API directly.
73  */
74 @Generated("by gapic-generator-java")
75 public class GrpcDeviceManagerStub extends DeviceManagerStub {
76   private static final MethodDescriptor<CreateDeviceRegistryRequest, DeviceRegistry>
77       createDeviceRegistryMethodDescriptor =
78           MethodDescriptor.<CreateDeviceRegistryRequest, DeviceRegistry>newBuilder()
79               .setType(MethodDescriptor.MethodType.UNARY)
80               .setFullMethodName("google.cloud.iot.v1.DeviceManager/CreateDeviceRegistry")
81               .setRequestMarshaller(
82                   ProtoUtils.marshaller(CreateDeviceRegistryRequest.getDefaultInstance()))
83               .setResponseMarshaller(ProtoUtils.marshaller(DeviceRegistry.getDefaultInstance()))
84               .build();
85 
86   private static final MethodDescriptor<GetDeviceRegistryRequest, DeviceRegistry>
87       getDeviceRegistryMethodDescriptor =
88           MethodDescriptor.<GetDeviceRegistryRequest, DeviceRegistry>newBuilder()
89               .setType(MethodDescriptor.MethodType.UNARY)
90               .setFullMethodName("google.cloud.iot.v1.DeviceManager/GetDeviceRegistry")
91               .setRequestMarshaller(
92                   ProtoUtils.marshaller(GetDeviceRegistryRequest.getDefaultInstance()))
93               .setResponseMarshaller(ProtoUtils.marshaller(DeviceRegistry.getDefaultInstance()))
94               .build();
95 
96   private static final MethodDescriptor<UpdateDeviceRegistryRequest, DeviceRegistry>
97       updateDeviceRegistryMethodDescriptor =
98           MethodDescriptor.<UpdateDeviceRegistryRequest, DeviceRegistry>newBuilder()
99               .setType(MethodDescriptor.MethodType.UNARY)
100               .setFullMethodName("google.cloud.iot.v1.DeviceManager/UpdateDeviceRegistry")
101               .setRequestMarshaller(
102                   ProtoUtils.marshaller(UpdateDeviceRegistryRequest.getDefaultInstance()))
103               .setResponseMarshaller(ProtoUtils.marshaller(DeviceRegistry.getDefaultInstance()))
104               .build();
105 
106   private static final MethodDescriptor<DeleteDeviceRegistryRequest, Empty>
107       deleteDeviceRegistryMethodDescriptor =
108           MethodDescriptor.<DeleteDeviceRegistryRequest, Empty>newBuilder()
109               .setType(MethodDescriptor.MethodType.UNARY)
110               .setFullMethodName("google.cloud.iot.v1.DeviceManager/DeleteDeviceRegistry")
111               .setRequestMarshaller(
112                   ProtoUtils.marshaller(DeleteDeviceRegistryRequest.getDefaultInstance()))
113               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
114               .build();
115 
116   private static final MethodDescriptor<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>
117       listDeviceRegistriesMethodDescriptor =
118           MethodDescriptor.<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>newBuilder()
119               .setType(MethodDescriptor.MethodType.UNARY)
120               .setFullMethodName("google.cloud.iot.v1.DeviceManager/ListDeviceRegistries")
121               .setRequestMarshaller(
122                   ProtoUtils.marshaller(ListDeviceRegistriesRequest.getDefaultInstance()))
123               .setResponseMarshaller(
124                   ProtoUtils.marshaller(ListDeviceRegistriesResponse.getDefaultInstance()))
125               .build();
126 
127   private static final MethodDescriptor<CreateDeviceRequest, Device> createDeviceMethodDescriptor =
128       MethodDescriptor.<CreateDeviceRequest, Device>newBuilder()
129           .setType(MethodDescriptor.MethodType.UNARY)
130           .setFullMethodName("google.cloud.iot.v1.DeviceManager/CreateDevice")
131           .setRequestMarshaller(ProtoUtils.marshaller(CreateDeviceRequest.getDefaultInstance()))
132           .setResponseMarshaller(ProtoUtils.marshaller(Device.getDefaultInstance()))
133           .build();
134 
135   private static final MethodDescriptor<GetDeviceRequest, Device> getDeviceMethodDescriptor =
136       MethodDescriptor.<GetDeviceRequest, Device>newBuilder()
137           .setType(MethodDescriptor.MethodType.UNARY)
138           .setFullMethodName("google.cloud.iot.v1.DeviceManager/GetDevice")
139           .setRequestMarshaller(ProtoUtils.marshaller(GetDeviceRequest.getDefaultInstance()))
140           .setResponseMarshaller(ProtoUtils.marshaller(Device.getDefaultInstance()))
141           .build();
142 
143   private static final MethodDescriptor<UpdateDeviceRequest, Device> updateDeviceMethodDescriptor =
144       MethodDescriptor.<UpdateDeviceRequest, Device>newBuilder()
145           .setType(MethodDescriptor.MethodType.UNARY)
146           .setFullMethodName("google.cloud.iot.v1.DeviceManager/UpdateDevice")
147           .setRequestMarshaller(ProtoUtils.marshaller(UpdateDeviceRequest.getDefaultInstance()))
148           .setResponseMarshaller(ProtoUtils.marshaller(Device.getDefaultInstance()))
149           .build();
150 
151   private static final MethodDescriptor<DeleteDeviceRequest, Empty> deleteDeviceMethodDescriptor =
152       MethodDescriptor.<DeleteDeviceRequest, Empty>newBuilder()
153           .setType(MethodDescriptor.MethodType.UNARY)
154           .setFullMethodName("google.cloud.iot.v1.DeviceManager/DeleteDevice")
155           .setRequestMarshaller(ProtoUtils.marshaller(DeleteDeviceRequest.getDefaultInstance()))
156           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
157           .build();
158 
159   private static final MethodDescriptor<ListDevicesRequest, ListDevicesResponse>
160       listDevicesMethodDescriptor =
161           MethodDescriptor.<ListDevicesRequest, ListDevicesResponse>newBuilder()
162               .setType(MethodDescriptor.MethodType.UNARY)
163               .setFullMethodName("google.cloud.iot.v1.DeviceManager/ListDevices")
164               .setRequestMarshaller(ProtoUtils.marshaller(ListDevicesRequest.getDefaultInstance()))
165               .setResponseMarshaller(
166                   ProtoUtils.marshaller(ListDevicesResponse.getDefaultInstance()))
167               .build();
168 
169   private static final MethodDescriptor<ModifyCloudToDeviceConfigRequest, DeviceConfig>
170       modifyCloudToDeviceConfigMethodDescriptor =
171           MethodDescriptor.<ModifyCloudToDeviceConfigRequest, DeviceConfig>newBuilder()
172               .setType(MethodDescriptor.MethodType.UNARY)
173               .setFullMethodName("google.cloud.iot.v1.DeviceManager/ModifyCloudToDeviceConfig")
174               .setRequestMarshaller(
175                   ProtoUtils.marshaller(ModifyCloudToDeviceConfigRequest.getDefaultInstance()))
176               .setResponseMarshaller(ProtoUtils.marshaller(DeviceConfig.getDefaultInstance()))
177               .build();
178 
179   private static final MethodDescriptor<
180           ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>
181       listDeviceConfigVersionsMethodDescriptor =
182           MethodDescriptor
183               .<ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>newBuilder()
184               .setType(MethodDescriptor.MethodType.UNARY)
185               .setFullMethodName("google.cloud.iot.v1.DeviceManager/ListDeviceConfigVersions")
186               .setRequestMarshaller(
187                   ProtoUtils.marshaller(ListDeviceConfigVersionsRequest.getDefaultInstance()))
188               .setResponseMarshaller(
189                   ProtoUtils.marshaller(ListDeviceConfigVersionsResponse.getDefaultInstance()))
190               .build();
191 
192   private static final MethodDescriptor<ListDeviceStatesRequest, ListDeviceStatesResponse>
193       listDeviceStatesMethodDescriptor =
194           MethodDescriptor.<ListDeviceStatesRequest, ListDeviceStatesResponse>newBuilder()
195               .setType(MethodDescriptor.MethodType.UNARY)
196               .setFullMethodName("google.cloud.iot.v1.DeviceManager/ListDeviceStates")
197               .setRequestMarshaller(
198                   ProtoUtils.marshaller(ListDeviceStatesRequest.getDefaultInstance()))
199               .setResponseMarshaller(
200                   ProtoUtils.marshaller(ListDeviceStatesResponse.getDefaultInstance()))
201               .build();
202 
203   private static final MethodDescriptor<SetIamPolicyRequest, Policy> setIamPolicyMethodDescriptor =
204       MethodDescriptor.<SetIamPolicyRequest, Policy>newBuilder()
205           .setType(MethodDescriptor.MethodType.UNARY)
206           .setFullMethodName("google.cloud.iot.v1.DeviceManager/SetIamPolicy")
207           .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance()))
208           .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance()))
209           .build();
210 
211   private static final MethodDescriptor<GetIamPolicyRequest, Policy> getIamPolicyMethodDescriptor =
212       MethodDescriptor.<GetIamPolicyRequest, Policy>newBuilder()
213           .setType(MethodDescriptor.MethodType.UNARY)
214           .setFullMethodName("google.cloud.iot.v1.DeviceManager/GetIamPolicy")
215           .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance()))
216           .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance()))
217           .build();
218 
219   private static final MethodDescriptor<TestIamPermissionsRequest, TestIamPermissionsResponse>
220       testIamPermissionsMethodDescriptor =
221           MethodDescriptor.<TestIamPermissionsRequest, TestIamPermissionsResponse>newBuilder()
222               .setType(MethodDescriptor.MethodType.UNARY)
223               .setFullMethodName("google.cloud.iot.v1.DeviceManager/TestIamPermissions")
224               .setRequestMarshaller(
225                   ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance()))
226               .setResponseMarshaller(
227                   ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance()))
228               .build();
229 
230   private static final MethodDescriptor<SendCommandToDeviceRequest, SendCommandToDeviceResponse>
231       sendCommandToDeviceMethodDescriptor =
232           MethodDescriptor.<SendCommandToDeviceRequest, SendCommandToDeviceResponse>newBuilder()
233               .setType(MethodDescriptor.MethodType.UNARY)
234               .setFullMethodName("google.cloud.iot.v1.DeviceManager/SendCommandToDevice")
235               .setRequestMarshaller(
236                   ProtoUtils.marshaller(SendCommandToDeviceRequest.getDefaultInstance()))
237               .setResponseMarshaller(
238                   ProtoUtils.marshaller(SendCommandToDeviceResponse.getDefaultInstance()))
239               .build();
240 
241   private static final MethodDescriptor<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>
242       bindDeviceToGatewayMethodDescriptor =
243           MethodDescriptor.<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>newBuilder()
244               .setType(MethodDescriptor.MethodType.UNARY)
245               .setFullMethodName("google.cloud.iot.v1.DeviceManager/BindDeviceToGateway")
246               .setRequestMarshaller(
247                   ProtoUtils.marshaller(BindDeviceToGatewayRequest.getDefaultInstance()))
248               .setResponseMarshaller(
249                   ProtoUtils.marshaller(BindDeviceToGatewayResponse.getDefaultInstance()))
250               .build();
251 
252   private static final MethodDescriptor<
253           UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>
254       unbindDeviceFromGatewayMethodDescriptor =
255           MethodDescriptor
256               .<UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>newBuilder()
257               .setType(MethodDescriptor.MethodType.UNARY)
258               .setFullMethodName("google.cloud.iot.v1.DeviceManager/UnbindDeviceFromGateway")
259               .setRequestMarshaller(
260                   ProtoUtils.marshaller(UnbindDeviceFromGatewayRequest.getDefaultInstance()))
261               .setResponseMarshaller(
262                   ProtoUtils.marshaller(UnbindDeviceFromGatewayResponse.getDefaultInstance()))
263               .build();
264 
265   private final UnaryCallable<CreateDeviceRegistryRequest, DeviceRegistry>
266       createDeviceRegistryCallable;
267   private final UnaryCallable<GetDeviceRegistryRequest, DeviceRegistry> getDeviceRegistryCallable;
268   private final UnaryCallable<UpdateDeviceRegistryRequest, DeviceRegistry>
269       updateDeviceRegistryCallable;
270   private final UnaryCallable<DeleteDeviceRegistryRequest, Empty> deleteDeviceRegistryCallable;
271   private final UnaryCallable<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>
272       listDeviceRegistriesCallable;
273   private final UnaryCallable<ListDeviceRegistriesRequest, ListDeviceRegistriesPagedResponse>
274       listDeviceRegistriesPagedCallable;
275   private final UnaryCallable<CreateDeviceRequest, Device> createDeviceCallable;
276   private final UnaryCallable<GetDeviceRequest, Device> getDeviceCallable;
277   private final UnaryCallable<UpdateDeviceRequest, Device> updateDeviceCallable;
278   private final UnaryCallable<DeleteDeviceRequest, Empty> deleteDeviceCallable;
279   private final UnaryCallable<ListDevicesRequest, ListDevicesResponse> listDevicesCallable;
280   private final UnaryCallable<ListDevicesRequest, ListDevicesPagedResponse>
281       listDevicesPagedCallable;
282   private final UnaryCallable<ModifyCloudToDeviceConfigRequest, DeviceConfig>
283       modifyCloudToDeviceConfigCallable;
284   private final UnaryCallable<ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>
285       listDeviceConfigVersionsCallable;
286   private final UnaryCallable<ListDeviceStatesRequest, ListDeviceStatesResponse>
287       listDeviceStatesCallable;
288   private final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable;
289   private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable;
290   private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
291       testIamPermissionsCallable;
292   private final UnaryCallable<SendCommandToDeviceRequest, SendCommandToDeviceResponse>
293       sendCommandToDeviceCallable;
294   private final UnaryCallable<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>
295       bindDeviceToGatewayCallable;
296   private final UnaryCallable<UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>
297       unbindDeviceFromGatewayCallable;
298 
299   private final BackgroundResource backgroundResources;
300   private final GrpcOperationsStub operationsStub;
301   private final GrpcStubCallableFactory callableFactory;
302 
create(DeviceManagerStubSettings settings)303   public static final GrpcDeviceManagerStub create(DeviceManagerStubSettings settings)
304       throws IOException {
305     return new GrpcDeviceManagerStub(settings, ClientContext.create(settings));
306   }
307 
create(ClientContext clientContext)308   public static final GrpcDeviceManagerStub create(ClientContext clientContext) throws IOException {
309     return new GrpcDeviceManagerStub(DeviceManagerStubSettings.newBuilder().build(), clientContext);
310   }
311 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)312   public static final GrpcDeviceManagerStub create(
313       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
314     return new GrpcDeviceManagerStub(
315         DeviceManagerStubSettings.newBuilder().build(), clientContext, callableFactory);
316   }
317 
318   /**
319    * Constructs an instance of GrpcDeviceManagerStub, using the given settings. This is protected so
320    * that it is easy to make a subclass, but otherwise, the static factory methods should be
321    * preferred.
322    */
GrpcDeviceManagerStub(DeviceManagerStubSettings settings, ClientContext clientContext)323   protected GrpcDeviceManagerStub(DeviceManagerStubSettings settings, ClientContext clientContext)
324       throws IOException {
325     this(settings, clientContext, new GrpcDeviceManagerCallableFactory());
326   }
327 
328   /**
329    * Constructs an instance of GrpcDeviceManagerStub, using the given settings. This is protected so
330    * that it is easy to make a subclass, but otherwise, the static factory methods should be
331    * preferred.
332    */
GrpcDeviceManagerStub( DeviceManagerStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)333   protected GrpcDeviceManagerStub(
334       DeviceManagerStubSettings settings,
335       ClientContext clientContext,
336       GrpcStubCallableFactory callableFactory)
337       throws IOException {
338     this.callableFactory = callableFactory;
339     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
340 
341     GrpcCallSettings<CreateDeviceRegistryRequest, DeviceRegistry>
342         createDeviceRegistryTransportSettings =
343             GrpcCallSettings.<CreateDeviceRegistryRequest, DeviceRegistry>newBuilder()
344                 .setMethodDescriptor(createDeviceRegistryMethodDescriptor)
345                 .setParamsExtractor(
346                     request -> {
347                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
348                       params.put("parent", String.valueOf(request.getParent()));
349                       return params.build();
350                     })
351                 .build();
352     GrpcCallSettings<GetDeviceRegistryRequest, DeviceRegistry> getDeviceRegistryTransportSettings =
353         GrpcCallSettings.<GetDeviceRegistryRequest, DeviceRegistry>newBuilder()
354             .setMethodDescriptor(getDeviceRegistryMethodDescriptor)
355             .setParamsExtractor(
356                 request -> {
357                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
358                   params.put("name", String.valueOf(request.getName()));
359                   return params.build();
360                 })
361             .build();
362     GrpcCallSettings<UpdateDeviceRegistryRequest, DeviceRegistry>
363         updateDeviceRegistryTransportSettings =
364             GrpcCallSettings.<UpdateDeviceRegistryRequest, DeviceRegistry>newBuilder()
365                 .setMethodDescriptor(updateDeviceRegistryMethodDescriptor)
366                 .setParamsExtractor(
367                     request -> {
368                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
369                       params.put(
370                           "device_registry.name",
371                           String.valueOf(request.getDeviceRegistry().getName()));
372                       return params.build();
373                     })
374                 .build();
375     GrpcCallSettings<DeleteDeviceRegistryRequest, Empty> deleteDeviceRegistryTransportSettings =
376         GrpcCallSettings.<DeleteDeviceRegistryRequest, Empty>newBuilder()
377             .setMethodDescriptor(deleteDeviceRegistryMethodDescriptor)
378             .setParamsExtractor(
379                 request -> {
380                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
381                   params.put("name", String.valueOf(request.getName()));
382                   return params.build();
383                 })
384             .build();
385     GrpcCallSettings<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>
386         listDeviceRegistriesTransportSettings =
387             GrpcCallSettings.<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>newBuilder()
388                 .setMethodDescriptor(listDeviceRegistriesMethodDescriptor)
389                 .setParamsExtractor(
390                     request -> {
391                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
392                       params.put("parent", String.valueOf(request.getParent()));
393                       return params.build();
394                     })
395                 .build();
396     GrpcCallSettings<CreateDeviceRequest, Device> createDeviceTransportSettings =
397         GrpcCallSettings.<CreateDeviceRequest, Device>newBuilder()
398             .setMethodDescriptor(createDeviceMethodDescriptor)
399             .setParamsExtractor(
400                 request -> {
401                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
402                   params.put("parent", String.valueOf(request.getParent()));
403                   return params.build();
404                 })
405             .build();
406     GrpcCallSettings<GetDeviceRequest, Device> getDeviceTransportSettings =
407         GrpcCallSettings.<GetDeviceRequest, Device>newBuilder()
408             .setMethodDescriptor(getDeviceMethodDescriptor)
409             .setParamsExtractor(
410                 request -> {
411                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
412                   params.put("name", String.valueOf(request.getName()));
413                   return params.build();
414                 })
415             .build();
416     GrpcCallSettings<UpdateDeviceRequest, Device> updateDeviceTransportSettings =
417         GrpcCallSettings.<UpdateDeviceRequest, Device>newBuilder()
418             .setMethodDescriptor(updateDeviceMethodDescriptor)
419             .setParamsExtractor(
420                 request -> {
421                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
422                   params.put("device.name", String.valueOf(request.getDevice().getName()));
423                   return params.build();
424                 })
425             .build();
426     GrpcCallSettings<DeleteDeviceRequest, Empty> deleteDeviceTransportSettings =
427         GrpcCallSettings.<DeleteDeviceRequest, Empty>newBuilder()
428             .setMethodDescriptor(deleteDeviceMethodDescriptor)
429             .setParamsExtractor(
430                 request -> {
431                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
432                   params.put("name", String.valueOf(request.getName()));
433                   return params.build();
434                 })
435             .build();
436     GrpcCallSettings<ListDevicesRequest, ListDevicesResponse> listDevicesTransportSettings =
437         GrpcCallSettings.<ListDevicesRequest, ListDevicesResponse>newBuilder()
438             .setMethodDescriptor(listDevicesMethodDescriptor)
439             .setParamsExtractor(
440                 request -> {
441                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
442                   params.put("parent", String.valueOf(request.getParent()));
443                   return params.build();
444                 })
445             .build();
446     GrpcCallSettings<ModifyCloudToDeviceConfigRequest, DeviceConfig>
447         modifyCloudToDeviceConfigTransportSettings =
448             GrpcCallSettings.<ModifyCloudToDeviceConfigRequest, DeviceConfig>newBuilder()
449                 .setMethodDescriptor(modifyCloudToDeviceConfigMethodDescriptor)
450                 .setParamsExtractor(
451                     request -> {
452                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
453                       params.put("name", String.valueOf(request.getName()));
454                       return params.build();
455                     })
456                 .build();
457     GrpcCallSettings<ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>
458         listDeviceConfigVersionsTransportSettings =
459             GrpcCallSettings
460                 .<ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>newBuilder()
461                 .setMethodDescriptor(listDeviceConfigVersionsMethodDescriptor)
462                 .setParamsExtractor(
463                     request -> {
464                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
465                       params.put("name", String.valueOf(request.getName()));
466                       return params.build();
467                     })
468                 .build();
469     GrpcCallSettings<ListDeviceStatesRequest, ListDeviceStatesResponse>
470         listDeviceStatesTransportSettings =
471             GrpcCallSettings.<ListDeviceStatesRequest, ListDeviceStatesResponse>newBuilder()
472                 .setMethodDescriptor(listDeviceStatesMethodDescriptor)
473                 .setParamsExtractor(
474                     request -> {
475                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
476                       params.put("name", String.valueOf(request.getName()));
477                       return params.build();
478                     })
479                 .build();
480     GrpcCallSettings<SetIamPolicyRequest, Policy> setIamPolicyTransportSettings =
481         GrpcCallSettings.<SetIamPolicyRequest, Policy>newBuilder()
482             .setMethodDescriptor(setIamPolicyMethodDescriptor)
483             .setParamsExtractor(
484                 request -> {
485                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
486                   params.put("resource", String.valueOf(request.getResource()));
487                   return params.build();
488                 })
489             .build();
490     GrpcCallSettings<GetIamPolicyRequest, Policy> getIamPolicyTransportSettings =
491         GrpcCallSettings.<GetIamPolicyRequest, Policy>newBuilder()
492             .setMethodDescriptor(getIamPolicyMethodDescriptor)
493             .setParamsExtractor(
494                 request -> {
495                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
496                   params.put("resource", String.valueOf(request.getResource()));
497                   return params.build();
498                 })
499             .build();
500     GrpcCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse>
501         testIamPermissionsTransportSettings =
502             GrpcCallSettings.<TestIamPermissionsRequest, TestIamPermissionsResponse>newBuilder()
503                 .setMethodDescriptor(testIamPermissionsMethodDescriptor)
504                 .setParamsExtractor(
505                     request -> {
506                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
507                       params.put("resource", String.valueOf(request.getResource()));
508                       return params.build();
509                     })
510                 .build();
511     GrpcCallSettings<SendCommandToDeviceRequest, SendCommandToDeviceResponse>
512         sendCommandToDeviceTransportSettings =
513             GrpcCallSettings.<SendCommandToDeviceRequest, SendCommandToDeviceResponse>newBuilder()
514                 .setMethodDescriptor(sendCommandToDeviceMethodDescriptor)
515                 .setParamsExtractor(
516                     request -> {
517                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
518                       params.put("name", String.valueOf(request.getName()));
519                       return params.build();
520                     })
521                 .build();
522     GrpcCallSettings<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>
523         bindDeviceToGatewayTransportSettings =
524             GrpcCallSettings.<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>newBuilder()
525                 .setMethodDescriptor(bindDeviceToGatewayMethodDescriptor)
526                 .setParamsExtractor(
527                     request -> {
528                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
529                       params.put("parent", String.valueOf(request.getParent()));
530                       return params.build();
531                     })
532                 .build();
533     GrpcCallSettings<UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>
534         unbindDeviceFromGatewayTransportSettings =
535             GrpcCallSettings
536                 .<UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>newBuilder()
537                 .setMethodDescriptor(unbindDeviceFromGatewayMethodDescriptor)
538                 .setParamsExtractor(
539                     request -> {
540                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
541                       params.put("parent", String.valueOf(request.getParent()));
542                       return params.build();
543                     })
544                 .build();
545 
546     this.createDeviceRegistryCallable =
547         callableFactory.createUnaryCallable(
548             createDeviceRegistryTransportSettings,
549             settings.createDeviceRegistrySettings(),
550             clientContext);
551     this.getDeviceRegistryCallable =
552         callableFactory.createUnaryCallable(
553             getDeviceRegistryTransportSettings,
554             settings.getDeviceRegistrySettings(),
555             clientContext);
556     this.updateDeviceRegistryCallable =
557         callableFactory.createUnaryCallable(
558             updateDeviceRegistryTransportSettings,
559             settings.updateDeviceRegistrySettings(),
560             clientContext);
561     this.deleteDeviceRegistryCallable =
562         callableFactory.createUnaryCallable(
563             deleteDeviceRegistryTransportSettings,
564             settings.deleteDeviceRegistrySettings(),
565             clientContext);
566     this.listDeviceRegistriesCallable =
567         callableFactory.createUnaryCallable(
568             listDeviceRegistriesTransportSettings,
569             settings.listDeviceRegistriesSettings(),
570             clientContext);
571     this.listDeviceRegistriesPagedCallable =
572         callableFactory.createPagedCallable(
573             listDeviceRegistriesTransportSettings,
574             settings.listDeviceRegistriesSettings(),
575             clientContext);
576     this.createDeviceCallable =
577         callableFactory.createUnaryCallable(
578             createDeviceTransportSettings, settings.createDeviceSettings(), clientContext);
579     this.getDeviceCallable =
580         callableFactory.createUnaryCallable(
581             getDeviceTransportSettings, settings.getDeviceSettings(), clientContext);
582     this.updateDeviceCallable =
583         callableFactory.createUnaryCallable(
584             updateDeviceTransportSettings, settings.updateDeviceSettings(), clientContext);
585     this.deleteDeviceCallable =
586         callableFactory.createUnaryCallable(
587             deleteDeviceTransportSettings, settings.deleteDeviceSettings(), clientContext);
588     this.listDevicesCallable =
589         callableFactory.createUnaryCallable(
590             listDevicesTransportSettings, settings.listDevicesSettings(), clientContext);
591     this.listDevicesPagedCallable =
592         callableFactory.createPagedCallable(
593             listDevicesTransportSettings, settings.listDevicesSettings(), clientContext);
594     this.modifyCloudToDeviceConfigCallable =
595         callableFactory.createUnaryCallable(
596             modifyCloudToDeviceConfigTransportSettings,
597             settings.modifyCloudToDeviceConfigSettings(),
598             clientContext);
599     this.listDeviceConfigVersionsCallable =
600         callableFactory.createUnaryCallable(
601             listDeviceConfigVersionsTransportSettings,
602             settings.listDeviceConfigVersionsSettings(),
603             clientContext);
604     this.listDeviceStatesCallable =
605         callableFactory.createUnaryCallable(
606             listDeviceStatesTransportSettings, settings.listDeviceStatesSettings(), clientContext);
607     this.setIamPolicyCallable =
608         callableFactory.createUnaryCallable(
609             setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext);
610     this.getIamPolicyCallable =
611         callableFactory.createUnaryCallable(
612             getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext);
613     this.testIamPermissionsCallable =
614         callableFactory.createUnaryCallable(
615             testIamPermissionsTransportSettings,
616             settings.testIamPermissionsSettings(),
617             clientContext);
618     this.sendCommandToDeviceCallable =
619         callableFactory.createUnaryCallable(
620             sendCommandToDeviceTransportSettings,
621             settings.sendCommandToDeviceSettings(),
622             clientContext);
623     this.bindDeviceToGatewayCallable =
624         callableFactory.createUnaryCallable(
625             bindDeviceToGatewayTransportSettings,
626             settings.bindDeviceToGatewaySettings(),
627             clientContext);
628     this.unbindDeviceFromGatewayCallable =
629         callableFactory.createUnaryCallable(
630             unbindDeviceFromGatewayTransportSettings,
631             settings.unbindDeviceFromGatewaySettings(),
632             clientContext);
633 
634     this.backgroundResources =
635         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
636   }
637 
getOperationsStub()638   public GrpcOperationsStub getOperationsStub() {
639     return operationsStub;
640   }
641 
642   @Override
createDeviceRegistryCallable()643   public UnaryCallable<CreateDeviceRegistryRequest, DeviceRegistry> createDeviceRegistryCallable() {
644     return createDeviceRegistryCallable;
645   }
646 
647   @Override
getDeviceRegistryCallable()648   public UnaryCallable<GetDeviceRegistryRequest, DeviceRegistry> getDeviceRegistryCallable() {
649     return getDeviceRegistryCallable;
650   }
651 
652   @Override
updateDeviceRegistryCallable()653   public UnaryCallable<UpdateDeviceRegistryRequest, DeviceRegistry> updateDeviceRegistryCallable() {
654     return updateDeviceRegistryCallable;
655   }
656 
657   @Override
deleteDeviceRegistryCallable()658   public UnaryCallable<DeleteDeviceRegistryRequest, Empty> deleteDeviceRegistryCallable() {
659     return deleteDeviceRegistryCallable;
660   }
661 
662   @Override
663   public UnaryCallable<ListDeviceRegistriesRequest, ListDeviceRegistriesResponse>
listDeviceRegistriesCallable()664       listDeviceRegistriesCallable() {
665     return listDeviceRegistriesCallable;
666   }
667 
668   @Override
669   public UnaryCallable<ListDeviceRegistriesRequest, ListDeviceRegistriesPagedResponse>
listDeviceRegistriesPagedCallable()670       listDeviceRegistriesPagedCallable() {
671     return listDeviceRegistriesPagedCallable;
672   }
673 
674   @Override
createDeviceCallable()675   public UnaryCallable<CreateDeviceRequest, Device> createDeviceCallable() {
676     return createDeviceCallable;
677   }
678 
679   @Override
getDeviceCallable()680   public UnaryCallable<GetDeviceRequest, Device> getDeviceCallable() {
681     return getDeviceCallable;
682   }
683 
684   @Override
updateDeviceCallable()685   public UnaryCallable<UpdateDeviceRequest, Device> updateDeviceCallable() {
686     return updateDeviceCallable;
687   }
688 
689   @Override
deleteDeviceCallable()690   public UnaryCallable<DeleteDeviceRequest, Empty> deleteDeviceCallable() {
691     return deleteDeviceCallable;
692   }
693 
694   @Override
listDevicesCallable()695   public UnaryCallable<ListDevicesRequest, ListDevicesResponse> listDevicesCallable() {
696     return listDevicesCallable;
697   }
698 
699   @Override
listDevicesPagedCallable()700   public UnaryCallable<ListDevicesRequest, ListDevicesPagedResponse> listDevicesPagedCallable() {
701     return listDevicesPagedCallable;
702   }
703 
704   @Override
705   public UnaryCallable<ModifyCloudToDeviceConfigRequest, DeviceConfig>
modifyCloudToDeviceConfigCallable()706       modifyCloudToDeviceConfigCallable() {
707     return modifyCloudToDeviceConfigCallable;
708   }
709 
710   @Override
711   public UnaryCallable<ListDeviceConfigVersionsRequest, ListDeviceConfigVersionsResponse>
listDeviceConfigVersionsCallable()712       listDeviceConfigVersionsCallable() {
713     return listDeviceConfigVersionsCallable;
714   }
715 
716   @Override
717   public UnaryCallable<ListDeviceStatesRequest, ListDeviceStatesResponse>
listDeviceStatesCallable()718       listDeviceStatesCallable() {
719     return listDeviceStatesCallable;
720   }
721 
722   @Override
setIamPolicyCallable()723   public UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
724     return setIamPolicyCallable;
725   }
726 
727   @Override
getIamPolicyCallable()728   public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
729     return getIamPolicyCallable;
730   }
731 
732   @Override
733   public UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsCallable()734       testIamPermissionsCallable() {
735     return testIamPermissionsCallable;
736   }
737 
738   @Override
739   public UnaryCallable<SendCommandToDeviceRequest, SendCommandToDeviceResponse>
sendCommandToDeviceCallable()740       sendCommandToDeviceCallable() {
741     return sendCommandToDeviceCallable;
742   }
743 
744   @Override
745   public UnaryCallable<BindDeviceToGatewayRequest, BindDeviceToGatewayResponse>
bindDeviceToGatewayCallable()746       bindDeviceToGatewayCallable() {
747     return bindDeviceToGatewayCallable;
748   }
749 
750   @Override
751   public UnaryCallable<UnbindDeviceFromGatewayRequest, UnbindDeviceFromGatewayResponse>
unbindDeviceFromGatewayCallable()752       unbindDeviceFromGatewayCallable() {
753     return unbindDeviceFromGatewayCallable;
754   }
755 
756   @Override
close()757   public final void close() {
758     try {
759       backgroundResources.close();
760     } catch (RuntimeException e) {
761       throw e;
762     } catch (Exception e) {
763       throw new IllegalStateException("Failed to close resource", e);
764     }
765   }
766 
767   @Override
shutdown()768   public void shutdown() {
769     backgroundResources.shutdown();
770   }
771 
772   @Override
isShutdown()773   public boolean isShutdown() {
774     return backgroundResources.isShutdown();
775   }
776 
777   @Override
isTerminated()778   public boolean isTerminated() {
779     return backgroundResources.isTerminated();
780   }
781 
782   @Override
shutdownNow()783   public void shutdownNow() {
784     backgroundResources.shutdownNow();
785   }
786 
787   @Override
awaitTermination(long duration, TimeUnit unit)788   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
789     return backgroundResources.awaitTermination(duration, unit);
790   }
791 }
792