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 static com.google.cloud.talent.v4beta1.CompanyServiceClient.ListCompaniesPagedResponse; 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.talent.v4beta1.Company; 29 import com.google.cloud.talent.v4beta1.CreateCompanyRequest; 30 import com.google.cloud.talent.v4beta1.DeleteCompanyRequest; 31 import com.google.cloud.talent.v4beta1.GetCompanyRequest; 32 import com.google.cloud.talent.v4beta1.ListCompaniesRequest; 33 import com.google.cloud.talent.v4beta1.ListCompaniesResponse; 34 import com.google.cloud.talent.v4beta1.UpdateCompanyRequest; 35 import com.google.common.collect.ImmutableMap; 36 import com.google.longrunning.stub.GrpcOperationsStub; 37 import com.google.protobuf.Empty; 38 import io.grpc.MethodDescriptor; 39 import io.grpc.protobuf.ProtoUtils; 40 import java.io.IOException; 41 import java.util.concurrent.TimeUnit; 42 import javax.annotation.Generated; 43 44 // AUTO-GENERATED DOCUMENTATION AND CLASS. 45 /** 46 * gRPC stub implementation for the CompanyService service API. 47 * 48 * <p>This class is for advanced usage and reflects the underlying API directly. 49 */ 50 @BetaApi 51 @Generated("by gapic-generator-java") 52 public class GrpcCompanyServiceStub extends CompanyServiceStub { 53 private static final MethodDescriptor<CreateCompanyRequest, Company> 54 createCompanyMethodDescriptor = 55 MethodDescriptor.<CreateCompanyRequest, Company>newBuilder() 56 .setType(MethodDescriptor.MethodType.UNARY) 57 .setFullMethodName("google.cloud.talent.v4beta1.CompanyService/CreateCompany") 58 .setRequestMarshaller( 59 ProtoUtils.marshaller(CreateCompanyRequest.getDefaultInstance())) 60 .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance())) 61 .build(); 62 63 private static final MethodDescriptor<GetCompanyRequest, Company> getCompanyMethodDescriptor = 64 MethodDescriptor.<GetCompanyRequest, Company>newBuilder() 65 .setType(MethodDescriptor.MethodType.UNARY) 66 .setFullMethodName("google.cloud.talent.v4beta1.CompanyService/GetCompany") 67 .setRequestMarshaller(ProtoUtils.marshaller(GetCompanyRequest.getDefaultInstance())) 68 .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance())) 69 .build(); 70 71 private static final MethodDescriptor<UpdateCompanyRequest, Company> 72 updateCompanyMethodDescriptor = 73 MethodDescriptor.<UpdateCompanyRequest, Company>newBuilder() 74 .setType(MethodDescriptor.MethodType.UNARY) 75 .setFullMethodName("google.cloud.talent.v4beta1.CompanyService/UpdateCompany") 76 .setRequestMarshaller( 77 ProtoUtils.marshaller(UpdateCompanyRequest.getDefaultInstance())) 78 .setResponseMarshaller(ProtoUtils.marshaller(Company.getDefaultInstance())) 79 .build(); 80 81 private static final MethodDescriptor<DeleteCompanyRequest, Empty> deleteCompanyMethodDescriptor = 82 MethodDescriptor.<DeleteCompanyRequest, Empty>newBuilder() 83 .setType(MethodDescriptor.MethodType.UNARY) 84 .setFullMethodName("google.cloud.talent.v4beta1.CompanyService/DeleteCompany") 85 .setRequestMarshaller(ProtoUtils.marshaller(DeleteCompanyRequest.getDefaultInstance())) 86 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 87 .build(); 88 89 private static final MethodDescriptor<ListCompaniesRequest, ListCompaniesResponse> 90 listCompaniesMethodDescriptor = 91 MethodDescriptor.<ListCompaniesRequest, ListCompaniesResponse>newBuilder() 92 .setType(MethodDescriptor.MethodType.UNARY) 93 .setFullMethodName("google.cloud.talent.v4beta1.CompanyService/ListCompanies") 94 .setRequestMarshaller( 95 ProtoUtils.marshaller(ListCompaniesRequest.getDefaultInstance())) 96 .setResponseMarshaller( 97 ProtoUtils.marshaller(ListCompaniesResponse.getDefaultInstance())) 98 .build(); 99 100 private final UnaryCallable<CreateCompanyRequest, Company> createCompanyCallable; 101 private final UnaryCallable<GetCompanyRequest, Company> getCompanyCallable; 102 private final UnaryCallable<UpdateCompanyRequest, Company> updateCompanyCallable; 103 private final UnaryCallable<DeleteCompanyRequest, Empty> deleteCompanyCallable; 104 private final UnaryCallable<ListCompaniesRequest, ListCompaniesResponse> listCompaniesCallable; 105 private final UnaryCallable<ListCompaniesRequest, ListCompaniesPagedResponse> 106 listCompaniesPagedCallable; 107 108 private final BackgroundResource backgroundResources; 109 private final GrpcOperationsStub operationsStub; 110 private final GrpcStubCallableFactory callableFactory; 111 create(CompanyServiceStubSettings settings)112 public static final GrpcCompanyServiceStub create(CompanyServiceStubSettings settings) 113 throws IOException { 114 return new GrpcCompanyServiceStub(settings, ClientContext.create(settings)); 115 } 116 create(ClientContext clientContext)117 public static final GrpcCompanyServiceStub create(ClientContext clientContext) 118 throws IOException { 119 return new GrpcCompanyServiceStub( 120 CompanyServiceStubSettings.newBuilder().build(), clientContext); 121 } 122 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)123 public static final GrpcCompanyServiceStub create( 124 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 125 return new GrpcCompanyServiceStub( 126 CompanyServiceStubSettings.newBuilder().build(), clientContext, callableFactory); 127 } 128 129 /** 130 * Constructs an instance of GrpcCompanyServiceStub, using the given settings. This is protected 131 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 132 * preferred. 133 */ GrpcCompanyServiceStub(CompanyServiceStubSettings settings, ClientContext clientContext)134 protected GrpcCompanyServiceStub(CompanyServiceStubSettings settings, ClientContext clientContext) 135 throws IOException { 136 this(settings, clientContext, new GrpcCompanyServiceCallableFactory()); 137 } 138 139 /** 140 * Constructs an instance of GrpcCompanyServiceStub, using the given settings. This is protected 141 * so that it is easy to make a subclass, but otherwise, the static factory methods should be 142 * preferred. 143 */ GrpcCompanyServiceStub( CompanyServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)144 protected GrpcCompanyServiceStub( 145 CompanyServiceStubSettings settings, 146 ClientContext clientContext, 147 GrpcStubCallableFactory callableFactory) 148 throws IOException { 149 this.callableFactory = callableFactory; 150 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 151 152 GrpcCallSettings<CreateCompanyRequest, Company> createCompanyTransportSettings = 153 GrpcCallSettings.<CreateCompanyRequest, Company>newBuilder() 154 .setMethodDescriptor(createCompanyMethodDescriptor) 155 .setParamsExtractor( 156 request -> { 157 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 158 params.put("parent", String.valueOf(request.getParent())); 159 return params.build(); 160 }) 161 .build(); 162 GrpcCallSettings<GetCompanyRequest, Company> getCompanyTransportSettings = 163 GrpcCallSettings.<GetCompanyRequest, Company>newBuilder() 164 .setMethodDescriptor(getCompanyMethodDescriptor) 165 .setParamsExtractor( 166 request -> { 167 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 168 params.put("name", String.valueOf(request.getName())); 169 return params.build(); 170 }) 171 .build(); 172 GrpcCallSettings<UpdateCompanyRequest, Company> updateCompanyTransportSettings = 173 GrpcCallSettings.<UpdateCompanyRequest, Company>newBuilder() 174 .setMethodDescriptor(updateCompanyMethodDescriptor) 175 .setParamsExtractor( 176 request -> { 177 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 178 params.put("company.name", String.valueOf(request.getCompany().getName())); 179 return params.build(); 180 }) 181 .build(); 182 GrpcCallSettings<DeleteCompanyRequest, Empty> deleteCompanyTransportSettings = 183 GrpcCallSettings.<DeleteCompanyRequest, Empty>newBuilder() 184 .setMethodDescriptor(deleteCompanyMethodDescriptor) 185 .setParamsExtractor( 186 request -> { 187 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 188 params.put("name", String.valueOf(request.getName())); 189 return params.build(); 190 }) 191 .build(); 192 GrpcCallSettings<ListCompaniesRequest, ListCompaniesResponse> listCompaniesTransportSettings = 193 GrpcCallSettings.<ListCompaniesRequest, ListCompaniesResponse>newBuilder() 194 .setMethodDescriptor(listCompaniesMethodDescriptor) 195 .setParamsExtractor( 196 request -> { 197 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 198 params.put("parent", String.valueOf(request.getParent())); 199 return params.build(); 200 }) 201 .build(); 202 203 this.createCompanyCallable = 204 callableFactory.createUnaryCallable( 205 createCompanyTransportSettings, settings.createCompanySettings(), clientContext); 206 this.getCompanyCallable = 207 callableFactory.createUnaryCallable( 208 getCompanyTransportSettings, settings.getCompanySettings(), clientContext); 209 this.updateCompanyCallable = 210 callableFactory.createUnaryCallable( 211 updateCompanyTransportSettings, settings.updateCompanySettings(), clientContext); 212 this.deleteCompanyCallable = 213 callableFactory.createUnaryCallable( 214 deleteCompanyTransportSettings, settings.deleteCompanySettings(), clientContext); 215 this.listCompaniesCallable = 216 callableFactory.createUnaryCallable( 217 listCompaniesTransportSettings, settings.listCompaniesSettings(), clientContext); 218 this.listCompaniesPagedCallable = 219 callableFactory.createPagedCallable( 220 listCompaniesTransportSettings, settings.listCompaniesSettings(), clientContext); 221 222 this.backgroundResources = 223 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 224 } 225 getOperationsStub()226 public GrpcOperationsStub getOperationsStub() { 227 return operationsStub; 228 } 229 230 @Override createCompanyCallable()231 public UnaryCallable<CreateCompanyRequest, Company> createCompanyCallable() { 232 return createCompanyCallable; 233 } 234 235 @Override getCompanyCallable()236 public UnaryCallable<GetCompanyRequest, Company> getCompanyCallable() { 237 return getCompanyCallable; 238 } 239 240 @Override updateCompanyCallable()241 public UnaryCallable<UpdateCompanyRequest, Company> updateCompanyCallable() { 242 return updateCompanyCallable; 243 } 244 245 @Override deleteCompanyCallable()246 public UnaryCallable<DeleteCompanyRequest, Empty> deleteCompanyCallable() { 247 return deleteCompanyCallable; 248 } 249 250 @Override listCompaniesCallable()251 public UnaryCallable<ListCompaniesRequest, ListCompaniesResponse> listCompaniesCallable() { 252 return listCompaniesCallable; 253 } 254 255 @Override 256 public UnaryCallable<ListCompaniesRequest, ListCompaniesPagedResponse> listCompaniesPagedCallable()257 listCompaniesPagedCallable() { 258 return listCompaniesPagedCallable; 259 } 260 261 @Override close()262 public final void close() { 263 try { 264 backgroundResources.close(); 265 } catch (RuntimeException e) { 266 throw e; 267 } catch (Exception e) { 268 throw new IllegalStateException("Failed to close resource", e); 269 } 270 } 271 272 @Override shutdown()273 public void shutdown() { 274 backgroundResources.shutdown(); 275 } 276 277 @Override isShutdown()278 public boolean isShutdown() { 279 return backgroundResources.isShutdown(); 280 } 281 282 @Override isTerminated()283 public boolean isTerminated() { 284 return backgroundResources.isTerminated(); 285 } 286 287 @Override shutdownNow()288 public void shutdownNow() { 289 backgroundResources.shutdownNow(); 290 } 291 292 @Override awaitTermination(long duration, TimeUnit unit)293 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 294 return backgroundResources.awaitTermination(duration, unit); 295 } 296 } 297