• 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.asset.v1p2beta1.stub;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.core.BackgroundResourceAggregation;
22 import com.google.api.gax.grpc.GrpcCallSettings;
23 import com.google.api.gax.grpc.GrpcStubCallableFactory;
24 import com.google.api.gax.rpc.ClientContext;
25 import com.google.api.gax.rpc.UnaryCallable;
26 import com.google.cloud.asset.v1p2beta1.CreateFeedRequest;
27 import com.google.cloud.asset.v1p2beta1.DeleteFeedRequest;
28 import com.google.cloud.asset.v1p2beta1.Feed;
29 import com.google.cloud.asset.v1p2beta1.GetFeedRequest;
30 import com.google.cloud.asset.v1p2beta1.ListFeedsRequest;
31 import com.google.cloud.asset.v1p2beta1.ListFeedsResponse;
32 import com.google.cloud.asset.v1p2beta1.UpdateFeedRequest;
33 import com.google.common.collect.ImmutableMap;
34 import com.google.longrunning.stub.GrpcOperationsStub;
35 import com.google.protobuf.Empty;
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 AssetService service API.
45  *
46  * <p>This class is for advanced usage and reflects the underlying API directly.
47  */
48 @BetaApi
49 @Generated("by gapic-generator-java")
50 public class GrpcAssetServiceStub extends AssetServiceStub {
51   private static final MethodDescriptor<CreateFeedRequest, Feed> createFeedMethodDescriptor =
52       MethodDescriptor.<CreateFeedRequest, Feed>newBuilder()
53           .setType(MethodDescriptor.MethodType.UNARY)
54           .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/CreateFeed")
55           .setRequestMarshaller(ProtoUtils.marshaller(CreateFeedRequest.getDefaultInstance()))
56           .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance()))
57           .build();
58 
59   private static final MethodDescriptor<GetFeedRequest, Feed> getFeedMethodDescriptor =
60       MethodDescriptor.<GetFeedRequest, Feed>newBuilder()
61           .setType(MethodDescriptor.MethodType.UNARY)
62           .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/GetFeed")
63           .setRequestMarshaller(ProtoUtils.marshaller(GetFeedRequest.getDefaultInstance()))
64           .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance()))
65           .build();
66 
67   private static final MethodDescriptor<ListFeedsRequest, ListFeedsResponse>
68       listFeedsMethodDescriptor =
69           MethodDescriptor.<ListFeedsRequest, ListFeedsResponse>newBuilder()
70               .setType(MethodDescriptor.MethodType.UNARY)
71               .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/ListFeeds")
72               .setRequestMarshaller(ProtoUtils.marshaller(ListFeedsRequest.getDefaultInstance()))
73               .setResponseMarshaller(ProtoUtils.marshaller(ListFeedsResponse.getDefaultInstance()))
74               .build();
75 
76   private static final MethodDescriptor<UpdateFeedRequest, Feed> updateFeedMethodDescriptor =
77       MethodDescriptor.<UpdateFeedRequest, Feed>newBuilder()
78           .setType(MethodDescriptor.MethodType.UNARY)
79           .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/UpdateFeed")
80           .setRequestMarshaller(ProtoUtils.marshaller(UpdateFeedRequest.getDefaultInstance()))
81           .setResponseMarshaller(ProtoUtils.marshaller(Feed.getDefaultInstance()))
82           .build();
83 
84   private static final MethodDescriptor<DeleteFeedRequest, Empty> deleteFeedMethodDescriptor =
85       MethodDescriptor.<DeleteFeedRequest, Empty>newBuilder()
86           .setType(MethodDescriptor.MethodType.UNARY)
87           .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/DeleteFeed")
88           .setRequestMarshaller(ProtoUtils.marshaller(DeleteFeedRequest.getDefaultInstance()))
89           .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
90           .build();
91 
92   private final UnaryCallable<CreateFeedRequest, Feed> createFeedCallable;
93   private final UnaryCallable<GetFeedRequest, Feed> getFeedCallable;
94   private final UnaryCallable<ListFeedsRequest, ListFeedsResponse> listFeedsCallable;
95   private final UnaryCallable<UpdateFeedRequest, Feed> updateFeedCallable;
96   private final UnaryCallable<DeleteFeedRequest, Empty> deleteFeedCallable;
97 
98   private final BackgroundResource backgroundResources;
99   private final GrpcOperationsStub operationsStub;
100   private final GrpcStubCallableFactory callableFactory;
101 
create(AssetServiceStubSettings settings)102   public static final GrpcAssetServiceStub create(AssetServiceStubSettings settings)
103       throws IOException {
104     return new GrpcAssetServiceStub(settings, ClientContext.create(settings));
105   }
106 
create(ClientContext clientContext)107   public static final GrpcAssetServiceStub create(ClientContext clientContext) throws IOException {
108     return new GrpcAssetServiceStub(AssetServiceStubSettings.newBuilder().build(), clientContext);
109   }
110 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)111   public static final GrpcAssetServiceStub create(
112       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
113     return new GrpcAssetServiceStub(
114         AssetServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
115   }
116 
117   /**
118    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
119    * that it is easy to make a subclass, but otherwise, the static factory methods should be
120    * preferred.
121    */
GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)122   protected GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)
123       throws IOException {
124     this(settings, clientContext, new GrpcAssetServiceCallableFactory());
125   }
126 
127   /**
128    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
129    * that it is easy to make a subclass, but otherwise, the static factory methods should be
130    * preferred.
131    */
GrpcAssetServiceStub( AssetServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)132   protected GrpcAssetServiceStub(
133       AssetServiceStubSettings settings,
134       ClientContext clientContext,
135       GrpcStubCallableFactory callableFactory)
136       throws IOException {
137     this.callableFactory = callableFactory;
138     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
139 
140     GrpcCallSettings<CreateFeedRequest, Feed> createFeedTransportSettings =
141         GrpcCallSettings.<CreateFeedRequest, Feed>newBuilder()
142             .setMethodDescriptor(createFeedMethodDescriptor)
143             .setParamsExtractor(
144                 request -> {
145                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
146                   params.put("parent", String.valueOf(request.getParent()));
147                   return params.build();
148                 })
149             .build();
150     GrpcCallSettings<GetFeedRequest, Feed> getFeedTransportSettings =
151         GrpcCallSettings.<GetFeedRequest, Feed>newBuilder()
152             .setMethodDescriptor(getFeedMethodDescriptor)
153             .setParamsExtractor(
154                 request -> {
155                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
156                   params.put("name", String.valueOf(request.getName()));
157                   return params.build();
158                 })
159             .build();
160     GrpcCallSettings<ListFeedsRequest, ListFeedsResponse> listFeedsTransportSettings =
161         GrpcCallSettings.<ListFeedsRequest, ListFeedsResponse>newBuilder()
162             .setMethodDescriptor(listFeedsMethodDescriptor)
163             .setParamsExtractor(
164                 request -> {
165                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
166                   params.put("parent", String.valueOf(request.getParent()));
167                   return params.build();
168                 })
169             .build();
170     GrpcCallSettings<UpdateFeedRequest, Feed> updateFeedTransportSettings =
171         GrpcCallSettings.<UpdateFeedRequest, Feed>newBuilder()
172             .setMethodDescriptor(updateFeedMethodDescriptor)
173             .setParamsExtractor(
174                 request -> {
175                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
176                   params.put("feed.name", String.valueOf(request.getFeed().getName()));
177                   return params.build();
178                 })
179             .build();
180     GrpcCallSettings<DeleteFeedRequest, Empty> deleteFeedTransportSettings =
181         GrpcCallSettings.<DeleteFeedRequest, Empty>newBuilder()
182             .setMethodDescriptor(deleteFeedMethodDescriptor)
183             .setParamsExtractor(
184                 request -> {
185                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
186                   params.put("name", String.valueOf(request.getName()));
187                   return params.build();
188                 })
189             .build();
190 
191     this.createFeedCallable =
192         callableFactory.createUnaryCallable(
193             createFeedTransportSettings, settings.createFeedSettings(), clientContext);
194     this.getFeedCallable =
195         callableFactory.createUnaryCallable(
196             getFeedTransportSettings, settings.getFeedSettings(), clientContext);
197     this.listFeedsCallable =
198         callableFactory.createUnaryCallable(
199             listFeedsTransportSettings, settings.listFeedsSettings(), clientContext);
200     this.updateFeedCallable =
201         callableFactory.createUnaryCallable(
202             updateFeedTransportSettings, settings.updateFeedSettings(), clientContext);
203     this.deleteFeedCallable =
204         callableFactory.createUnaryCallable(
205             deleteFeedTransportSettings, settings.deleteFeedSettings(), clientContext);
206 
207     this.backgroundResources =
208         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
209   }
210 
getOperationsStub()211   public GrpcOperationsStub getOperationsStub() {
212     return operationsStub;
213   }
214 
215   @Override
createFeedCallable()216   public UnaryCallable<CreateFeedRequest, Feed> createFeedCallable() {
217     return createFeedCallable;
218   }
219 
220   @Override
getFeedCallable()221   public UnaryCallable<GetFeedRequest, Feed> getFeedCallable() {
222     return getFeedCallable;
223   }
224 
225   @Override
listFeedsCallable()226   public UnaryCallable<ListFeedsRequest, ListFeedsResponse> listFeedsCallable() {
227     return listFeedsCallable;
228   }
229 
230   @Override
updateFeedCallable()231   public UnaryCallable<UpdateFeedRequest, Feed> updateFeedCallable() {
232     return updateFeedCallable;
233   }
234 
235   @Override
deleteFeedCallable()236   public UnaryCallable<DeleteFeedRequest, Empty> deleteFeedCallable() {
237     return deleteFeedCallable;
238   }
239 
240   @Override
close()241   public final void close() {
242     try {
243       backgroundResources.close();
244     } catch (RuntimeException e) {
245       throw e;
246     } catch (Exception e) {
247       throw new IllegalStateException("Failed to close resource", e);
248     }
249   }
250 
251   @Override
shutdown()252   public void shutdown() {
253     backgroundResources.shutdown();
254   }
255 
256   @Override
isShutdown()257   public boolean isShutdown() {
258     return backgroundResources.isShutdown();
259   }
260 
261   @Override
isTerminated()262   public boolean isTerminated() {
263     return backgroundResources.isTerminated();
264   }
265 
266   @Override
shutdownNow()267   public void shutdownNow() {
268     backgroundResources.shutdownNow();
269   }
270 
271   @Override
awaitTermination(long duration, TimeUnit unit)272   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
273     return backgroundResources.awaitTermination(duration, unit);
274   }
275 }
276