• 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.billing.v1.stub;
18 
19 import static com.google.cloud.billing.v1.CloudCatalogClient.ListServicesPagedResponse;
20 import static com.google.cloud.billing.v1.CloudCatalogClient.ListSkusPagedResponse;
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.billing.v1.ListServicesRequest;
29 import com.google.cloud.billing.v1.ListServicesResponse;
30 import com.google.cloud.billing.v1.ListSkusRequest;
31 import com.google.cloud.billing.v1.ListSkusResponse;
32 import com.google.common.collect.ImmutableMap;
33 import com.google.longrunning.stub.GrpcOperationsStub;
34 import io.grpc.MethodDescriptor;
35 import io.grpc.protobuf.ProtoUtils;
36 import java.io.IOException;
37 import java.util.concurrent.TimeUnit;
38 import javax.annotation.Generated;
39 
40 // AUTO-GENERATED DOCUMENTATION AND CLASS.
41 /**
42  * gRPC stub implementation for the CloudCatalog service API.
43  *
44  * <p>This class is for advanced usage and reflects the underlying API directly.
45  */
46 @Generated("by gapic-generator-java")
47 public class GrpcCloudCatalogStub extends CloudCatalogStub {
48   private static final MethodDescriptor<ListServicesRequest, ListServicesResponse>
49       listServicesMethodDescriptor =
50           MethodDescriptor.<ListServicesRequest, ListServicesResponse>newBuilder()
51               .setType(MethodDescriptor.MethodType.UNARY)
52               .setFullMethodName("google.cloud.billing.v1.CloudCatalog/ListServices")
53               .setRequestMarshaller(ProtoUtils.marshaller(ListServicesRequest.getDefaultInstance()))
54               .setResponseMarshaller(
55                   ProtoUtils.marshaller(ListServicesResponse.getDefaultInstance()))
56               .build();
57 
58   private static final MethodDescriptor<ListSkusRequest, ListSkusResponse>
59       listSkusMethodDescriptor =
60           MethodDescriptor.<ListSkusRequest, ListSkusResponse>newBuilder()
61               .setType(MethodDescriptor.MethodType.UNARY)
62               .setFullMethodName("google.cloud.billing.v1.CloudCatalog/ListSkus")
63               .setRequestMarshaller(ProtoUtils.marshaller(ListSkusRequest.getDefaultInstance()))
64               .setResponseMarshaller(ProtoUtils.marshaller(ListSkusResponse.getDefaultInstance()))
65               .build();
66 
67   private final UnaryCallable<ListServicesRequest, ListServicesResponse> listServicesCallable;
68   private final UnaryCallable<ListServicesRequest, ListServicesPagedResponse>
69       listServicesPagedCallable;
70   private final UnaryCallable<ListSkusRequest, ListSkusResponse> listSkusCallable;
71   private final UnaryCallable<ListSkusRequest, ListSkusPagedResponse> listSkusPagedCallable;
72 
73   private final BackgroundResource backgroundResources;
74   private final GrpcOperationsStub operationsStub;
75   private final GrpcStubCallableFactory callableFactory;
76 
create(CloudCatalogStubSettings settings)77   public static final GrpcCloudCatalogStub create(CloudCatalogStubSettings settings)
78       throws IOException {
79     return new GrpcCloudCatalogStub(settings, ClientContext.create(settings));
80   }
81 
create(ClientContext clientContext)82   public static final GrpcCloudCatalogStub create(ClientContext clientContext) throws IOException {
83     return new GrpcCloudCatalogStub(CloudCatalogStubSettings.newBuilder().build(), clientContext);
84   }
85 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)86   public static final GrpcCloudCatalogStub create(
87       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
88     return new GrpcCloudCatalogStub(
89         CloudCatalogStubSettings.newBuilder().build(), clientContext, callableFactory);
90   }
91 
92   /**
93    * Constructs an instance of GrpcCloudCatalogStub, using the given settings. This is protected so
94    * that it is easy to make a subclass, but otherwise, the static factory methods should be
95    * preferred.
96    */
GrpcCloudCatalogStub(CloudCatalogStubSettings settings, ClientContext clientContext)97   protected GrpcCloudCatalogStub(CloudCatalogStubSettings settings, ClientContext clientContext)
98       throws IOException {
99     this(settings, clientContext, new GrpcCloudCatalogCallableFactory());
100   }
101 
102   /**
103    * Constructs an instance of GrpcCloudCatalogStub, using the given settings. This is protected so
104    * that it is easy to make a subclass, but otherwise, the static factory methods should be
105    * preferred.
106    */
GrpcCloudCatalogStub( CloudCatalogStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)107   protected GrpcCloudCatalogStub(
108       CloudCatalogStubSettings settings,
109       ClientContext clientContext,
110       GrpcStubCallableFactory callableFactory)
111       throws IOException {
112     this.callableFactory = callableFactory;
113     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
114 
115     GrpcCallSettings<ListServicesRequest, ListServicesResponse> listServicesTransportSettings =
116         GrpcCallSettings.<ListServicesRequest, ListServicesResponse>newBuilder()
117             .setMethodDescriptor(listServicesMethodDescriptor)
118             .build();
119     GrpcCallSettings<ListSkusRequest, ListSkusResponse> listSkusTransportSettings =
120         GrpcCallSettings.<ListSkusRequest, ListSkusResponse>newBuilder()
121             .setMethodDescriptor(listSkusMethodDescriptor)
122             .setParamsExtractor(
123                 request -> {
124                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
125                   params.put("parent", String.valueOf(request.getParent()));
126                   return params.build();
127                 })
128             .build();
129 
130     this.listServicesCallable =
131         callableFactory.createUnaryCallable(
132             listServicesTransportSettings, settings.listServicesSettings(), clientContext);
133     this.listServicesPagedCallable =
134         callableFactory.createPagedCallable(
135             listServicesTransportSettings, settings.listServicesSettings(), clientContext);
136     this.listSkusCallable =
137         callableFactory.createUnaryCallable(
138             listSkusTransportSettings, settings.listSkusSettings(), clientContext);
139     this.listSkusPagedCallable =
140         callableFactory.createPagedCallable(
141             listSkusTransportSettings, settings.listSkusSettings(), clientContext);
142 
143     this.backgroundResources =
144         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
145   }
146 
getOperationsStub()147   public GrpcOperationsStub getOperationsStub() {
148     return operationsStub;
149   }
150 
151   @Override
listServicesCallable()152   public UnaryCallable<ListServicesRequest, ListServicesResponse> listServicesCallable() {
153     return listServicesCallable;
154   }
155 
156   @Override
listServicesPagedCallable()157   public UnaryCallable<ListServicesRequest, ListServicesPagedResponse> listServicesPagedCallable() {
158     return listServicesPagedCallable;
159   }
160 
161   @Override
listSkusCallable()162   public UnaryCallable<ListSkusRequest, ListSkusResponse> listSkusCallable() {
163     return listSkusCallable;
164   }
165 
166   @Override
listSkusPagedCallable()167   public UnaryCallable<ListSkusRequest, ListSkusPagedResponse> listSkusPagedCallable() {
168     return listSkusPagedCallable;
169   }
170 
171   @Override
close()172   public final void close() {
173     try {
174       backgroundResources.close();
175     } catch (RuntimeException e) {
176       throw e;
177     } catch (Exception e) {
178       throw new IllegalStateException("Failed to close resource", e);
179     }
180   }
181 
182   @Override
shutdown()183   public void shutdown() {
184     backgroundResources.shutdown();
185   }
186 
187   @Override
isShutdown()188   public boolean isShutdown() {
189     return backgroundResources.isShutdown();
190   }
191 
192   @Override
isTerminated()193   public boolean isTerminated() {
194     return backgroundResources.isTerminated();
195   }
196 
197   @Override
shutdownNow()198   public void shutdownNow() {
199     backgroundResources.shutdownNow();
200   }
201 
202   @Override
awaitTermination(long duration, TimeUnit unit)203   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
204     return backgroundResources.awaitTermination(duration, unit);
205   }
206 }
207