• 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.v1p5beta1.stub;
18 
19 import static com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse;
20 
21 import com.google.api.core.BetaApi;
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.asset.v1p5beta1.ListAssetsRequest;
29 import com.google.cloud.asset.v1p5beta1.ListAssetsResponse;
30 import com.google.common.collect.ImmutableMap;
31 import com.google.longrunning.stub.GrpcOperationsStub;
32 import io.grpc.MethodDescriptor;
33 import io.grpc.protobuf.ProtoUtils;
34 import java.io.IOException;
35 import java.util.concurrent.TimeUnit;
36 import javax.annotation.Generated;
37 
38 // AUTO-GENERATED DOCUMENTATION AND CLASS.
39 /**
40  * gRPC stub implementation for the AssetService service API.
41  *
42  * <p>This class is for advanced usage and reflects the underlying API directly.
43  */
44 @BetaApi
45 @Generated("by gapic-generator-java")
46 public class GrpcAssetServiceStub extends AssetServiceStub {
47   private static final MethodDescriptor<ListAssetsRequest, ListAssetsResponse>
48       listAssetsMethodDescriptor =
49           MethodDescriptor.<ListAssetsRequest, ListAssetsResponse>newBuilder()
50               .setType(MethodDescriptor.MethodType.UNARY)
51               .setFullMethodName("google.cloud.asset.v1p5beta1.AssetService/ListAssets")
52               .setRequestMarshaller(ProtoUtils.marshaller(ListAssetsRequest.getDefaultInstance()))
53               .setResponseMarshaller(ProtoUtils.marshaller(ListAssetsResponse.getDefaultInstance()))
54               .build();
55 
56   private final UnaryCallable<ListAssetsRequest, ListAssetsResponse> listAssetsCallable;
57   private final UnaryCallable<ListAssetsRequest, ListAssetsPagedResponse> listAssetsPagedCallable;
58 
59   private final BackgroundResource backgroundResources;
60   private final GrpcOperationsStub operationsStub;
61   private final GrpcStubCallableFactory callableFactory;
62 
create(AssetServiceStubSettings settings)63   public static final GrpcAssetServiceStub create(AssetServiceStubSettings settings)
64       throws IOException {
65     return new GrpcAssetServiceStub(settings, ClientContext.create(settings));
66   }
67 
create(ClientContext clientContext)68   public static final GrpcAssetServiceStub create(ClientContext clientContext) throws IOException {
69     return new GrpcAssetServiceStub(AssetServiceStubSettings.newBuilder().build(), clientContext);
70   }
71 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)72   public static final GrpcAssetServiceStub create(
73       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
74     return new GrpcAssetServiceStub(
75         AssetServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
76   }
77 
78   /**
79    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
80    * that it is easy to make a subclass, but otherwise, the static factory methods should be
81    * preferred.
82    */
GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)83   protected GrpcAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext)
84       throws IOException {
85     this(settings, clientContext, new GrpcAssetServiceCallableFactory());
86   }
87 
88   /**
89    * Constructs an instance of GrpcAssetServiceStub, using the given settings. This is protected so
90    * that it is easy to make a subclass, but otherwise, the static factory methods should be
91    * preferred.
92    */
GrpcAssetServiceStub( AssetServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)93   protected GrpcAssetServiceStub(
94       AssetServiceStubSettings settings,
95       ClientContext clientContext,
96       GrpcStubCallableFactory callableFactory)
97       throws IOException {
98     this.callableFactory = callableFactory;
99     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
100 
101     GrpcCallSettings<ListAssetsRequest, ListAssetsResponse> listAssetsTransportSettings =
102         GrpcCallSettings.<ListAssetsRequest, ListAssetsResponse>newBuilder()
103             .setMethodDescriptor(listAssetsMethodDescriptor)
104             .setParamsExtractor(
105                 request -> {
106                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
107                   params.put("parent", String.valueOf(request.getParent()));
108                   return params.build();
109                 })
110             .build();
111 
112     this.listAssetsCallable =
113         callableFactory.createUnaryCallable(
114             listAssetsTransportSettings, settings.listAssetsSettings(), clientContext);
115     this.listAssetsPagedCallable =
116         callableFactory.createPagedCallable(
117             listAssetsTransportSettings, settings.listAssetsSettings(), clientContext);
118 
119     this.backgroundResources =
120         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
121   }
122 
getOperationsStub()123   public GrpcOperationsStub getOperationsStub() {
124     return operationsStub;
125   }
126 
127   @Override
listAssetsCallable()128   public UnaryCallable<ListAssetsRequest, ListAssetsResponse> listAssetsCallable() {
129     return listAssetsCallable;
130   }
131 
132   @Override
listAssetsPagedCallable()133   public UnaryCallable<ListAssetsRequest, ListAssetsPagedResponse> listAssetsPagedCallable() {
134     return listAssetsPagedCallable;
135   }
136 
137   @Override
close()138   public final void close() {
139     try {
140       backgroundResources.close();
141     } catch (RuntimeException e) {
142       throw e;
143     } catch (Exception e) {
144       throw new IllegalStateException("Failed to close resource", e);
145     }
146   }
147 
148   @Override
shutdown()149   public void shutdown() {
150     backgroundResources.shutdown();
151   }
152 
153   @Override
isShutdown()154   public boolean isShutdown() {
155     return backgroundResources.isShutdown();
156   }
157 
158   @Override
isTerminated()159   public boolean isTerminated() {
160     return backgroundResources.isTerminated();
161   }
162 
163   @Override
shutdownNow()164   public void shutdownNow() {
165     backgroundResources.shutdownNow();
166   }
167 
168   @Override
awaitTermination(long duration, TimeUnit unit)169   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
170     return backgroundResources.awaitTermination(duration, unit);
171   }
172 }
173