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.gaming.v1.stub; 18 19 import static com.google.cloud.gaming.v1.RealmsServiceClient.ListRealmsPagedResponse; 20 21 import com.google.api.gax.core.BackgroundResource; 22 import com.google.api.gax.core.BackgroundResourceAggregation; 23 import com.google.api.gax.grpc.GrpcCallSettings; 24 import com.google.api.gax.grpc.GrpcStubCallableFactory; 25 import com.google.api.gax.rpc.ClientContext; 26 import com.google.api.gax.rpc.OperationCallable; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.gaming.v1.CreateRealmRequest; 29 import com.google.cloud.gaming.v1.DeleteRealmRequest; 30 import com.google.cloud.gaming.v1.GetRealmRequest; 31 import com.google.cloud.gaming.v1.ListRealmsRequest; 32 import com.google.cloud.gaming.v1.ListRealmsResponse; 33 import com.google.cloud.gaming.v1.OperationMetadata; 34 import com.google.cloud.gaming.v1.PreviewRealmUpdateRequest; 35 import com.google.cloud.gaming.v1.PreviewRealmUpdateResponse; 36 import com.google.cloud.gaming.v1.Realm; 37 import com.google.cloud.gaming.v1.UpdateRealmRequest; 38 import com.google.common.collect.ImmutableMap; 39 import com.google.longrunning.Operation; 40 import com.google.longrunning.stub.GrpcOperationsStub; 41 import com.google.protobuf.Empty; 42 import io.grpc.MethodDescriptor; 43 import io.grpc.protobuf.ProtoUtils; 44 import java.io.IOException; 45 import java.util.concurrent.TimeUnit; 46 import javax.annotation.Generated; 47 48 // AUTO-GENERATED DOCUMENTATION AND CLASS. 49 /** 50 * gRPC stub implementation for the RealmsService service API. 51 * 52 * <p>This class is for advanced usage and reflects the underlying API directly. 53 */ 54 @Generated("by gapic-generator-java") 55 public class GrpcRealmsServiceStub extends RealmsServiceStub { 56 private static final MethodDescriptor<ListRealmsRequest, ListRealmsResponse> 57 listRealmsMethodDescriptor = 58 MethodDescriptor.<ListRealmsRequest, ListRealmsResponse>newBuilder() 59 .setType(MethodDescriptor.MethodType.UNARY) 60 .setFullMethodName("google.cloud.gaming.v1.RealmsService/ListRealms") 61 .setRequestMarshaller(ProtoUtils.marshaller(ListRealmsRequest.getDefaultInstance())) 62 .setResponseMarshaller(ProtoUtils.marshaller(ListRealmsResponse.getDefaultInstance())) 63 .build(); 64 65 private static final MethodDescriptor<GetRealmRequest, Realm> getRealmMethodDescriptor = 66 MethodDescriptor.<GetRealmRequest, Realm>newBuilder() 67 .setType(MethodDescriptor.MethodType.UNARY) 68 .setFullMethodName("google.cloud.gaming.v1.RealmsService/GetRealm") 69 .setRequestMarshaller(ProtoUtils.marshaller(GetRealmRequest.getDefaultInstance())) 70 .setResponseMarshaller(ProtoUtils.marshaller(Realm.getDefaultInstance())) 71 .build(); 72 73 private static final MethodDescriptor<CreateRealmRequest, Operation> createRealmMethodDescriptor = 74 MethodDescriptor.<CreateRealmRequest, Operation>newBuilder() 75 .setType(MethodDescriptor.MethodType.UNARY) 76 .setFullMethodName("google.cloud.gaming.v1.RealmsService/CreateRealm") 77 .setRequestMarshaller(ProtoUtils.marshaller(CreateRealmRequest.getDefaultInstance())) 78 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 79 .build(); 80 81 private static final MethodDescriptor<DeleteRealmRequest, Operation> deleteRealmMethodDescriptor = 82 MethodDescriptor.<DeleteRealmRequest, Operation>newBuilder() 83 .setType(MethodDescriptor.MethodType.UNARY) 84 .setFullMethodName("google.cloud.gaming.v1.RealmsService/DeleteRealm") 85 .setRequestMarshaller(ProtoUtils.marshaller(DeleteRealmRequest.getDefaultInstance())) 86 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 87 .build(); 88 89 private static final MethodDescriptor<UpdateRealmRequest, Operation> updateRealmMethodDescriptor = 90 MethodDescriptor.<UpdateRealmRequest, Operation>newBuilder() 91 .setType(MethodDescriptor.MethodType.UNARY) 92 .setFullMethodName("google.cloud.gaming.v1.RealmsService/UpdateRealm") 93 .setRequestMarshaller(ProtoUtils.marshaller(UpdateRealmRequest.getDefaultInstance())) 94 .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) 95 .build(); 96 97 private static final MethodDescriptor<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse> 98 previewRealmUpdateMethodDescriptor = 99 MethodDescriptor.<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse>newBuilder() 100 .setType(MethodDescriptor.MethodType.UNARY) 101 .setFullMethodName("google.cloud.gaming.v1.RealmsService/PreviewRealmUpdate") 102 .setRequestMarshaller( 103 ProtoUtils.marshaller(PreviewRealmUpdateRequest.getDefaultInstance())) 104 .setResponseMarshaller( 105 ProtoUtils.marshaller(PreviewRealmUpdateResponse.getDefaultInstance())) 106 .build(); 107 108 private final UnaryCallable<ListRealmsRequest, ListRealmsResponse> listRealmsCallable; 109 private final UnaryCallable<ListRealmsRequest, ListRealmsPagedResponse> listRealmsPagedCallable; 110 private final UnaryCallable<GetRealmRequest, Realm> getRealmCallable; 111 private final UnaryCallable<CreateRealmRequest, Operation> createRealmCallable; 112 private final OperationCallable<CreateRealmRequest, Realm, OperationMetadata> 113 createRealmOperationCallable; 114 private final UnaryCallable<DeleteRealmRequest, Operation> deleteRealmCallable; 115 private final OperationCallable<DeleteRealmRequest, Empty, OperationMetadata> 116 deleteRealmOperationCallable; 117 private final UnaryCallable<UpdateRealmRequest, Operation> updateRealmCallable; 118 private final OperationCallable<UpdateRealmRequest, Realm, OperationMetadata> 119 updateRealmOperationCallable; 120 private final UnaryCallable<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse> 121 previewRealmUpdateCallable; 122 123 private final BackgroundResource backgroundResources; 124 private final GrpcOperationsStub operationsStub; 125 private final GrpcStubCallableFactory callableFactory; 126 create(RealmsServiceStubSettings settings)127 public static final GrpcRealmsServiceStub create(RealmsServiceStubSettings settings) 128 throws IOException { 129 return new GrpcRealmsServiceStub(settings, ClientContext.create(settings)); 130 } 131 create(ClientContext clientContext)132 public static final GrpcRealmsServiceStub create(ClientContext clientContext) throws IOException { 133 return new GrpcRealmsServiceStub(RealmsServiceStubSettings.newBuilder().build(), clientContext); 134 } 135 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)136 public static final GrpcRealmsServiceStub create( 137 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 138 return new GrpcRealmsServiceStub( 139 RealmsServiceStubSettings.newBuilder().build(), clientContext, callableFactory); 140 } 141 142 /** 143 * Constructs an instance of GrpcRealmsServiceStub, using the given settings. This is protected so 144 * that it is easy to make a subclass, but otherwise, the static factory methods should be 145 * preferred. 146 */ GrpcRealmsServiceStub(RealmsServiceStubSettings settings, ClientContext clientContext)147 protected GrpcRealmsServiceStub(RealmsServiceStubSettings settings, ClientContext clientContext) 148 throws IOException { 149 this(settings, clientContext, new GrpcRealmsServiceCallableFactory()); 150 } 151 152 /** 153 * Constructs an instance of GrpcRealmsServiceStub, using the given settings. This is protected so 154 * that it is easy to make a subclass, but otherwise, the static factory methods should be 155 * preferred. 156 */ GrpcRealmsServiceStub( RealmsServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)157 protected GrpcRealmsServiceStub( 158 RealmsServiceStubSettings settings, 159 ClientContext clientContext, 160 GrpcStubCallableFactory callableFactory) 161 throws IOException { 162 this.callableFactory = callableFactory; 163 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 164 165 GrpcCallSettings<ListRealmsRequest, ListRealmsResponse> listRealmsTransportSettings = 166 GrpcCallSettings.<ListRealmsRequest, ListRealmsResponse>newBuilder() 167 .setMethodDescriptor(listRealmsMethodDescriptor) 168 .setParamsExtractor( 169 request -> { 170 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 171 params.put("parent", String.valueOf(request.getParent())); 172 return params.build(); 173 }) 174 .build(); 175 GrpcCallSettings<GetRealmRequest, Realm> getRealmTransportSettings = 176 GrpcCallSettings.<GetRealmRequest, Realm>newBuilder() 177 .setMethodDescriptor(getRealmMethodDescriptor) 178 .setParamsExtractor( 179 request -> { 180 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 181 params.put("name", String.valueOf(request.getName())); 182 return params.build(); 183 }) 184 .build(); 185 GrpcCallSettings<CreateRealmRequest, Operation> createRealmTransportSettings = 186 GrpcCallSettings.<CreateRealmRequest, Operation>newBuilder() 187 .setMethodDescriptor(createRealmMethodDescriptor) 188 .setParamsExtractor( 189 request -> { 190 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 191 params.put("parent", String.valueOf(request.getParent())); 192 return params.build(); 193 }) 194 .build(); 195 GrpcCallSettings<DeleteRealmRequest, Operation> deleteRealmTransportSettings = 196 GrpcCallSettings.<DeleteRealmRequest, Operation>newBuilder() 197 .setMethodDescriptor(deleteRealmMethodDescriptor) 198 .setParamsExtractor( 199 request -> { 200 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 201 params.put("name", String.valueOf(request.getName())); 202 return params.build(); 203 }) 204 .build(); 205 GrpcCallSettings<UpdateRealmRequest, Operation> updateRealmTransportSettings = 206 GrpcCallSettings.<UpdateRealmRequest, Operation>newBuilder() 207 .setMethodDescriptor(updateRealmMethodDescriptor) 208 .setParamsExtractor( 209 request -> { 210 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 211 params.put("realm.name", String.valueOf(request.getRealm().getName())); 212 return params.build(); 213 }) 214 .build(); 215 GrpcCallSettings<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse> 216 previewRealmUpdateTransportSettings = 217 GrpcCallSettings.<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse>newBuilder() 218 .setMethodDescriptor(previewRealmUpdateMethodDescriptor) 219 .setParamsExtractor( 220 request -> { 221 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 222 params.put("realm.name", String.valueOf(request.getRealm().getName())); 223 return params.build(); 224 }) 225 .build(); 226 227 this.listRealmsCallable = 228 callableFactory.createUnaryCallable( 229 listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); 230 this.listRealmsPagedCallable = 231 callableFactory.createPagedCallable( 232 listRealmsTransportSettings, settings.listRealmsSettings(), clientContext); 233 this.getRealmCallable = 234 callableFactory.createUnaryCallable( 235 getRealmTransportSettings, settings.getRealmSettings(), clientContext); 236 this.createRealmCallable = 237 callableFactory.createUnaryCallable( 238 createRealmTransportSettings, settings.createRealmSettings(), clientContext); 239 this.createRealmOperationCallable = 240 callableFactory.createOperationCallable( 241 createRealmTransportSettings, 242 settings.createRealmOperationSettings(), 243 clientContext, 244 operationsStub); 245 this.deleteRealmCallable = 246 callableFactory.createUnaryCallable( 247 deleteRealmTransportSettings, settings.deleteRealmSettings(), clientContext); 248 this.deleteRealmOperationCallable = 249 callableFactory.createOperationCallable( 250 deleteRealmTransportSettings, 251 settings.deleteRealmOperationSettings(), 252 clientContext, 253 operationsStub); 254 this.updateRealmCallable = 255 callableFactory.createUnaryCallable( 256 updateRealmTransportSettings, settings.updateRealmSettings(), clientContext); 257 this.updateRealmOperationCallable = 258 callableFactory.createOperationCallable( 259 updateRealmTransportSettings, 260 settings.updateRealmOperationSettings(), 261 clientContext, 262 operationsStub); 263 this.previewRealmUpdateCallable = 264 callableFactory.createUnaryCallable( 265 previewRealmUpdateTransportSettings, 266 settings.previewRealmUpdateSettings(), 267 clientContext); 268 269 this.backgroundResources = 270 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 271 } 272 getOperationsStub()273 public GrpcOperationsStub getOperationsStub() { 274 return operationsStub; 275 } 276 277 @Override listRealmsCallable()278 public UnaryCallable<ListRealmsRequest, ListRealmsResponse> listRealmsCallable() { 279 return listRealmsCallable; 280 } 281 282 @Override listRealmsPagedCallable()283 public UnaryCallable<ListRealmsRequest, ListRealmsPagedResponse> listRealmsPagedCallable() { 284 return listRealmsPagedCallable; 285 } 286 287 @Override getRealmCallable()288 public UnaryCallable<GetRealmRequest, Realm> getRealmCallable() { 289 return getRealmCallable; 290 } 291 292 @Override createRealmCallable()293 public UnaryCallable<CreateRealmRequest, Operation> createRealmCallable() { 294 return createRealmCallable; 295 } 296 297 @Override 298 public OperationCallable<CreateRealmRequest, Realm, OperationMetadata> createRealmOperationCallable()299 createRealmOperationCallable() { 300 return createRealmOperationCallable; 301 } 302 303 @Override deleteRealmCallable()304 public UnaryCallable<DeleteRealmRequest, Operation> deleteRealmCallable() { 305 return deleteRealmCallable; 306 } 307 308 @Override 309 public OperationCallable<DeleteRealmRequest, Empty, OperationMetadata> deleteRealmOperationCallable()310 deleteRealmOperationCallable() { 311 return deleteRealmOperationCallable; 312 } 313 314 @Override updateRealmCallable()315 public UnaryCallable<UpdateRealmRequest, Operation> updateRealmCallable() { 316 return updateRealmCallable; 317 } 318 319 @Override 320 public OperationCallable<UpdateRealmRequest, Realm, OperationMetadata> updateRealmOperationCallable()321 updateRealmOperationCallable() { 322 return updateRealmOperationCallable; 323 } 324 325 @Override 326 public UnaryCallable<PreviewRealmUpdateRequest, PreviewRealmUpdateResponse> previewRealmUpdateCallable()327 previewRealmUpdateCallable() { 328 return previewRealmUpdateCallable; 329 } 330 331 @Override close()332 public final void close() { 333 try { 334 backgroundResources.close(); 335 } catch (RuntimeException e) { 336 throw e; 337 } catch (Exception e) { 338 throw new IllegalStateException("Failed to close resource", e); 339 } 340 } 341 342 @Override shutdown()343 public void shutdown() { 344 backgroundResources.shutdown(); 345 } 346 347 @Override isShutdown()348 public boolean isShutdown() { 349 return backgroundResources.isShutdown(); 350 } 351 352 @Override isTerminated()353 public boolean isTerminated() { 354 return backgroundResources.isTerminated(); 355 } 356 357 @Override shutdownNow()358 public void shutdownNow() { 359 backgroundResources.shutdownNow(); 360 } 361 362 @Override awaitTermination(long duration, TimeUnit unit)363 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 364 return backgroundResources.awaitTermination(duration, unit); 365 } 366 } 367