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