• 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.v1p1beta1.stub;
18 
19 import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllIamPoliciesPagedResponse;
20 import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse;
21 
22 import com.google.api.core.BetaApi;
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.asset.v1p1beta1.SearchAllIamPoliciesRequest;
30 import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse;
31 import com.google.cloud.asset.v1p1beta1.SearchAllResourcesRequest;
32 import com.google.cloud.asset.v1p1beta1.SearchAllResourcesResponse;
33 import com.google.common.collect.ImmutableMap;
34 import com.google.longrunning.stub.GrpcOperationsStub;
35 import io.grpc.MethodDescriptor;
36 import io.grpc.protobuf.ProtoUtils;
37 import java.io.IOException;
38 import java.util.concurrent.TimeUnit;
39 import javax.annotation.Generated;
40 
41 // AUTO-GENERATED DOCUMENTATION AND CLASS.
42 /**
43  * gRPC stub implementation for the AssetService service API.
44  *
45  * <p>This class is for advanced usage and reflects the underlying API directly.
46  */
47 @BetaApi
48 @Generated("by gapic-generator-java")
49 public class GrpcAssetServiceStub extends AssetServiceStub {
50   private static final MethodDescriptor<SearchAllResourcesRequest, SearchAllResourcesResponse>
51       searchAllResourcesMethodDescriptor =
52           MethodDescriptor.<SearchAllResourcesRequest, SearchAllResourcesResponse>newBuilder()
53               .setType(MethodDescriptor.MethodType.UNARY)
54               .setFullMethodName("google.cloud.asset.v1p1beta1.AssetService/SearchAllResources")
55               .setRequestMarshaller(
56                   ProtoUtils.marshaller(SearchAllResourcesRequest.getDefaultInstance()))
57               .setResponseMarshaller(
58                   ProtoUtils.marshaller(SearchAllResourcesResponse.getDefaultInstance()))
59               .build();
60 
61   private static final MethodDescriptor<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>
62       searchAllIamPoliciesMethodDescriptor =
63           MethodDescriptor.<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>newBuilder()
64               .setType(MethodDescriptor.MethodType.UNARY)
65               .setFullMethodName("google.cloud.asset.v1p1beta1.AssetService/SearchAllIamPolicies")
66               .setRequestMarshaller(
67                   ProtoUtils.marshaller(SearchAllIamPoliciesRequest.getDefaultInstance()))
68               .setResponseMarshaller(
69                   ProtoUtils.marshaller(SearchAllIamPoliciesResponse.getDefaultInstance()))
70               .build();
71 
72   private final UnaryCallable<SearchAllResourcesRequest, SearchAllResourcesResponse>
73       searchAllResourcesCallable;
74   private final UnaryCallable<SearchAllResourcesRequest, SearchAllResourcesPagedResponse>
75       searchAllResourcesPagedCallable;
76   private final UnaryCallable<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>
77       searchAllIamPoliciesCallable;
78   private final UnaryCallable<SearchAllIamPoliciesRequest, SearchAllIamPoliciesPagedResponse>
79       searchAllIamPoliciesPagedCallable;
80 
81   private final BackgroundResource backgroundResources;
82   private final GrpcOperationsStub operationsStub;
83   private final GrpcStubCallableFactory callableFactory;
84 
create(AssetServiceStubSettings settings)85   public static final GrpcAssetServiceStub create(AssetServiceStubSettings settings)
86       throws IOException {
87     return new GrpcAssetServiceStub(settings, ClientContext.create(settings));
88   }
89 
create(ClientContext clientContext)90   public static final GrpcAssetServiceStub create(ClientContext clientContext) throws IOException {
91     return new GrpcAssetServiceStub(AssetServiceStubSettings.newBuilder().build(), clientContext);
92   }
93 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)94   public static final GrpcAssetServiceStub create(
95       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
96     return new GrpcAssetServiceStub(
97         AssetServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
98   }
99 
100   /**
101    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
102    * that it is easy to make a subclass, but otherwise, the static factory methods should be
103    * preferred.
104    */
GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)105   protected GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)
106       throws IOException {
107     this(settings, clientContext, new GrpcAssetServiceCallableFactory());
108   }
109 
110   /**
111    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
112    * that it is easy to make a subclass, but otherwise, the static factory methods should be
113    * preferred.
114    */
GrpcAssetServiceStub( AssetServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)115   protected GrpcAssetServiceStub(
116       AssetServiceStubSettings settings,
117       ClientContext clientContext,
118       GrpcStubCallableFactory callableFactory)
119       throws IOException {
120     this.callableFactory = callableFactory;
121     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
122 
123     GrpcCallSettings<SearchAllResourcesRequest, SearchAllResourcesResponse>
124         searchAllResourcesTransportSettings =
125             GrpcCallSettings.<SearchAllResourcesRequest, SearchAllResourcesResponse>newBuilder()
126                 .setMethodDescriptor(searchAllResourcesMethodDescriptor)
127                 .setParamsExtractor(
128                     request -> {
129                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
130                       params.put("scope", String.valueOf(request.getScope()));
131                       return params.build();
132                     })
133                 .build();
134     GrpcCallSettings<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>
135         searchAllIamPoliciesTransportSettings =
136             GrpcCallSettings.<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>newBuilder()
137                 .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor)
138                 .setParamsExtractor(
139                     request -> {
140                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
141                       params.put("scope", String.valueOf(request.getScope()));
142                       return params.build();
143                     })
144                 .build();
145 
146     this.searchAllResourcesCallable =
147         callableFactory.createUnaryCallable(
148             searchAllResourcesTransportSettings,
149             settings.searchAllResourcesSettings(),
150             clientContext);
151     this.searchAllResourcesPagedCallable =
152         callableFactory.createPagedCallable(
153             searchAllResourcesTransportSettings,
154             settings.searchAllResourcesSettings(),
155             clientContext);
156     this.searchAllIamPoliciesCallable =
157         callableFactory.createUnaryCallable(
158             searchAllIamPoliciesTransportSettings,
159             settings.searchAllIamPoliciesSettings(),
160             clientContext);
161     this.searchAllIamPoliciesPagedCallable =
162         callableFactory.createPagedCallable(
163             searchAllIamPoliciesTransportSettings,
164             settings.searchAllIamPoliciesSettings(),
165             clientContext);
166 
167     this.backgroundResources =
168         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
169   }
170 
getOperationsStub()171   public GrpcOperationsStub getOperationsStub() {
172     return operationsStub;
173   }
174 
175   @Override
176   public UnaryCallable<SearchAllResourcesRequest, SearchAllResourcesResponse>
searchAllResourcesCallable()177       searchAllResourcesCallable() {
178     return searchAllResourcesCallable;
179   }
180 
181   @Override
182   public UnaryCallable<SearchAllResourcesRequest, SearchAllResourcesPagedResponse>
searchAllResourcesPagedCallable()183       searchAllResourcesPagedCallable() {
184     return searchAllResourcesPagedCallable;
185   }
186 
187   @Override
188   public UnaryCallable<SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse>
searchAllIamPoliciesCallable()189       searchAllIamPoliciesCallable() {
190     return searchAllIamPoliciesCallable;
191   }
192 
193   @Override
194   public UnaryCallable<SearchAllIamPoliciesRequest, SearchAllIamPoliciesPagedResponse>
searchAllIamPoliciesPagedCallable()195       searchAllIamPoliciesPagedCallable() {
196     return searchAllIamPoliciesPagedCallable;
197   }
198 
199   @Override
close()200   public final void close() {
201     try {
202       backgroundResources.close();
203     } catch (RuntimeException e) {
204       throw e;
205     } catch (Exception e) {
206       throw new IllegalStateException("Failed to close resource", e);
207     }
208   }
209 
210   @Override
shutdown()211   public void shutdown() {
212     backgroundResources.shutdown();
213   }
214 
215   @Override
isShutdown()216   public boolean isShutdown() {
217     return backgroundResources.isShutdown();
218   }
219 
220   @Override
isTerminated()221   public boolean isTerminated() {
222     return backgroundResources.isTerminated();
223   }
224 
225   @Override
shutdownNow()226   public void shutdownNow() {
227     backgroundResources.shutdownNow();
228   }
229 
230   @Override
awaitTermination(long duration, TimeUnit unit)231   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
232     return backgroundResources.awaitTermination(duration, unit);
233   }
234 }
235