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