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.ApiFunction; 20 import com.google.api.core.BetaApi; 21 import com.google.api.gax.core.GaxProperties; 22 import com.google.api.gax.core.GoogleCredentialsProvider; 23 import com.google.api.gax.core.InstantiatingExecutorProvider; 24 import com.google.api.gax.grpc.GaxGrpcProperties; 25 import com.google.api.gax.grpc.GrpcTransportChannel; 26 import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; 27 import com.google.api.gax.httpjson.GaxHttpJsonProperties; 28 import com.google.api.gax.httpjson.HttpJsonTransportChannel; 29 import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; 30 import com.google.api.gax.retrying.RetrySettings; 31 import com.google.api.gax.rpc.ApiClientHeaderProvider; 32 import com.google.api.gax.rpc.ClientContext; 33 import com.google.api.gax.rpc.StatusCode; 34 import com.google.api.gax.rpc.StubSettings; 35 import com.google.api.gax.rpc.TransportChannelProvider; 36 import com.google.api.gax.rpc.UnaryCallSettings; 37 import com.google.cloud.talent.v4beta1.CompleteQueryRequest; 38 import com.google.cloud.talent.v4beta1.CompleteQueryResponse; 39 import com.google.common.collect.ImmutableList; 40 import com.google.common.collect.ImmutableMap; 41 import com.google.common.collect.ImmutableSet; 42 import com.google.common.collect.Lists; 43 import java.io.IOException; 44 import java.util.List; 45 import javax.annotation.Generated; 46 import org.threeten.bp.Duration; 47 48 // AUTO-GENERATED DOCUMENTATION AND CLASS. 49 /** 50 * Settings class to configure an instance of {@link CompletionStub}. 51 * 52 * <p>The default instance has everything set to sensible defaults: 53 * 54 * <ul> 55 * <li>The default service address (jobs.googleapis.com) and default port (443) are used. 56 * <li>Credentials are acquired automatically through Application Default Credentials. 57 * <li>Retries are configured for idempotent methods but not for non-idempotent methods. 58 * </ul> 59 * 60 * <p>The builder of this class is recursive, so contained classes are themselves builders. When 61 * build() is called, the tree of builders is called to create the complete settings object. 62 * 63 * <p>For example, to set the total timeout of completeQuery to 30 seconds: 64 * 65 * <pre>{@code 66 * // This snippet has been automatically generated and should be regarded as a code template only. 67 * // It will require modifications to work: 68 * // - It may require correct/in-range values for request initialization. 69 * // - It may require specifying regional endpoints when creating the service client as shown in 70 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 71 * CompletionStubSettings.Builder completionSettingsBuilder = CompletionStubSettings.newBuilder(); 72 * completionSettingsBuilder 73 * .completeQuerySettings() 74 * .setRetrySettings( 75 * completionSettingsBuilder 76 * .completeQuerySettings() 77 * .getRetrySettings() 78 * .toBuilder() 79 * .setTotalTimeout(Duration.ofSeconds(30)) 80 * .build()); 81 * CompletionStubSettings completionSettings = completionSettingsBuilder.build(); 82 * }</pre> 83 */ 84 @BetaApi 85 @Generated("by gapic-generator-java") 86 public class CompletionStubSettings extends StubSettings<CompletionStubSettings> { 87 /** The default scopes of the service. */ 88 private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES = 89 ImmutableList.<String>builder() 90 .add("https://www.googleapis.com/auth/cloud-platform") 91 .add("https://www.googleapis.com/auth/jobs") 92 .build(); 93 94 private final UnaryCallSettings<CompleteQueryRequest, CompleteQueryResponse> 95 completeQuerySettings; 96 97 /** Returns the object with the settings used for calls to completeQuery. */ completeQuerySettings()98 public UnaryCallSettings<CompleteQueryRequest, CompleteQueryResponse> completeQuerySettings() { 99 return completeQuerySettings; 100 } 101 createStub()102 public CompletionStub createStub() throws IOException { 103 if (getTransportChannelProvider() 104 .getTransportName() 105 .equals(GrpcTransportChannel.getGrpcTransportName())) { 106 return GrpcCompletionStub.create(this); 107 } 108 if (getTransportChannelProvider() 109 .getTransportName() 110 .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { 111 return HttpJsonCompletionStub.create(this); 112 } 113 throw new UnsupportedOperationException( 114 String.format( 115 "Transport not supported: %s", getTransportChannelProvider().getTransportName())); 116 } 117 118 /** Returns a builder for the default ExecutorProvider for this service. */ defaultExecutorProviderBuilder()119 public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { 120 return InstantiatingExecutorProvider.newBuilder(); 121 } 122 123 /** Returns the default service endpoint. */ getDefaultEndpoint()124 public static String getDefaultEndpoint() { 125 return "jobs.googleapis.com:443"; 126 } 127 128 /** Returns the default mTLS service endpoint. */ getDefaultMtlsEndpoint()129 public static String getDefaultMtlsEndpoint() { 130 return "jobs.mtls.googleapis.com:443"; 131 } 132 133 /** Returns the default service scopes. */ getDefaultServiceScopes()134 public static List<String> getDefaultServiceScopes() { 135 return DEFAULT_SERVICE_SCOPES; 136 } 137 138 /** Returns a builder for the default credentials for this service. */ defaultCredentialsProviderBuilder()139 public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { 140 return GoogleCredentialsProvider.newBuilder() 141 .setScopesToApply(DEFAULT_SERVICE_SCOPES) 142 .setUseJwtAccessWithScope(true); 143 } 144 145 /** Returns a builder for the default gRPC ChannelProvider for this service. */ defaultGrpcTransportProviderBuilder()146 public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { 147 return InstantiatingGrpcChannelProvider.newBuilder() 148 .setMaxInboundMessageSize(Integer.MAX_VALUE); 149 } 150 151 /** Returns a builder for the default REST ChannelProvider for this service. */ 152 @BetaApi 153 public static InstantiatingHttpJsonChannelProvider.Builder defaultHttpJsonTransportProviderBuilder()154 defaultHttpJsonTransportProviderBuilder() { 155 return InstantiatingHttpJsonChannelProvider.newBuilder(); 156 } 157 defaultTransportChannelProvider()158 public static TransportChannelProvider defaultTransportChannelProvider() { 159 return defaultGrpcTransportProviderBuilder().build(); 160 } 161 162 @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") defaultGrpcApiClientHeaderProviderBuilder()163 public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { 164 return ApiClientHeaderProvider.newBuilder() 165 .setGeneratedLibToken( 166 "gapic", GaxProperties.getLibraryVersion(CompletionStubSettings.class)) 167 .setTransportToken( 168 GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); 169 } 170 171 @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") defaultHttpJsonApiClientHeaderProviderBuilder()172 public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { 173 return ApiClientHeaderProvider.newBuilder() 174 .setGeneratedLibToken( 175 "gapic", GaxProperties.getLibraryVersion(CompletionStubSettings.class)) 176 .setTransportToken( 177 GaxHttpJsonProperties.getHttpJsonTokenName(), 178 GaxHttpJsonProperties.getHttpJsonVersion()); 179 } 180 defaultApiClientHeaderProviderBuilder()181 public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { 182 return CompletionStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); 183 } 184 185 /** Returns a new gRPC builder for this class. */ newBuilder()186 public static Builder newBuilder() { 187 return Builder.createDefault(); 188 } 189 190 /** Returns a new REST builder for this class. */ newHttpJsonBuilder()191 public static Builder newHttpJsonBuilder() { 192 return Builder.createHttpJsonDefault(); 193 } 194 195 /** Returns a new builder for this class. */ newBuilder(ClientContext clientContext)196 public static Builder newBuilder(ClientContext clientContext) { 197 return new Builder(clientContext); 198 } 199 200 /** Returns a builder containing all the values of this settings class. */ toBuilder()201 public Builder toBuilder() { 202 return new Builder(this); 203 } 204 CompletionStubSettings(Builder settingsBuilder)205 protected CompletionStubSettings(Builder settingsBuilder) throws IOException { 206 super(settingsBuilder); 207 208 completeQuerySettings = settingsBuilder.completeQuerySettings().build(); 209 } 210 211 /** Builder for CompletionStubSettings. */ 212 public static class Builder extends StubSettings.Builder<CompletionStubSettings, Builder> { 213 private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders; 214 private final UnaryCallSettings.Builder<CompleteQueryRequest, CompleteQueryResponse> 215 completeQuerySettings; 216 private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>> 217 RETRYABLE_CODE_DEFINITIONS; 218 219 static { 220 ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions = 221 ImmutableMap.builder(); 222 definitions.put( 223 "retry_policy_11_codes", 224 ImmutableSet.copyOf( 225 Lists.<StatusCode.Code>newArrayList( 226 StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); 227 RETRYABLE_CODE_DEFINITIONS = definitions.build(); 228 } 229 230 private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS; 231 232 static { 233 ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder(); 234 RetrySettings settings = null; 235 settings = 236 RetrySettings.newBuilder() 237 .setInitialRetryDelay(Duration.ofMillis(100L)) 238 .setRetryDelayMultiplier(1.3) 239 .setMaxRetryDelay(Duration.ofMillis(60000L)) 240 .setInitialRpcTimeout(Duration.ofMillis(30000L)) 241 .setRpcTimeoutMultiplier(1.0) 242 .setMaxRpcTimeout(Duration.ofMillis(30000L)) 243 .setTotalTimeout(Duration.ofMillis(30000L)) 244 .build(); 245 definitions.put("retry_policy_11_params", settings); 246 RETRY_PARAM_DEFINITIONS = definitions.build(); 247 } 248 Builder()249 protected Builder() { 250 this(((ClientContext) null)); 251 } 252 Builder(ClientContext clientContext)253 protected Builder(ClientContext clientContext) { 254 super(clientContext); 255 256 completeQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); 257 258 unaryMethodSettingsBuilders = 259 ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(completeQuerySettings); 260 initDefaults(this); 261 } 262 Builder(CompletionStubSettings settings)263 protected Builder(CompletionStubSettings settings) { 264 super(settings); 265 266 completeQuerySettings = settings.completeQuerySettings.toBuilder(); 267 268 unaryMethodSettingsBuilders = 269 ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(completeQuerySettings); 270 } 271 createDefault()272 private static Builder createDefault() { 273 Builder builder = new Builder(((ClientContext) null)); 274 275 builder.setTransportChannelProvider(defaultTransportChannelProvider()); 276 builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); 277 builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); 278 builder.setEndpoint(getDefaultEndpoint()); 279 builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); 280 builder.setSwitchToMtlsEndpointAllowed(true); 281 282 return initDefaults(builder); 283 } 284 createHttpJsonDefault()285 private static Builder createHttpJsonDefault() { 286 Builder builder = new Builder(((ClientContext) null)); 287 288 builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); 289 builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); 290 builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); 291 builder.setEndpoint(getDefaultEndpoint()); 292 builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); 293 builder.setSwitchToMtlsEndpointAllowed(true); 294 295 return initDefaults(builder); 296 } 297 initDefaults(Builder builder)298 private static Builder initDefaults(Builder builder) { 299 builder 300 .completeQuerySettings() 301 .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_11_codes")) 302 .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_11_params")); 303 304 return builder; 305 } 306 307 /** 308 * Applies the given settings updater function to all of the unary API methods in this service. 309 * 310 * <p>Note: This method does not support applying settings to streaming methods. 311 */ applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)312 public Builder applyToAllUnaryMethods( 313 ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) { 314 super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); 315 return this; 316 } 317 unaryMethodSettingsBuilders()318 public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() { 319 return unaryMethodSettingsBuilders; 320 } 321 322 /** Returns the builder for the settings used for calls to completeQuery. */ 323 public UnaryCallSettings.Builder<CompleteQueryRequest, CompleteQueryResponse> completeQuerySettings()324 completeQuerySettings() { 325 return completeQuerySettings; 326 } 327 328 @Override build()329 public CompletionStubSettings build() throws IOException { 330 return new CompletionStubSettings(this); 331 } 332 } 333 } 334