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.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.v4.CompleteQueryRequest; 38 import com.google.cloud.talent.v4.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 @Generated("by gapic-generator-java") 85 public class CompletionStubSettings extends StubSettings<CompletionStubSettings> { 86 /** The default scopes of the service. */ 87 private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES = 88 ImmutableList.<String>builder() 89 .add("https://www.googleapis.com/auth/cloud-platform") 90 .add("https://www.googleapis.com/auth/jobs") 91 .build(); 92 93 private final UnaryCallSettings<CompleteQueryRequest, CompleteQueryResponse> 94 completeQuerySettings; 95 96 /** Returns the object with the settings used for calls to completeQuery. */ completeQuerySettings()97 public UnaryCallSettings<CompleteQueryRequest, CompleteQueryResponse> completeQuerySettings() { 98 return completeQuerySettings; 99 } 100 createStub()101 public CompletionStub createStub() throws IOException { 102 if (getTransportChannelProvider() 103 .getTransportName() 104 .equals(GrpcTransportChannel.getGrpcTransportName())) { 105 return GrpcCompletionStub.create(this); 106 } 107 if (getTransportChannelProvider() 108 .getTransportName() 109 .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { 110 return HttpJsonCompletionStub.create(this); 111 } 112 throw new UnsupportedOperationException( 113 String.format( 114 "Transport not supported: %s", getTransportChannelProvider().getTransportName())); 115 } 116 117 /** Returns a builder for the default ExecutorProvider for this service. */ defaultExecutorProviderBuilder()118 public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { 119 return InstantiatingExecutorProvider.newBuilder(); 120 } 121 122 /** Returns the default service endpoint. */ getDefaultEndpoint()123 public static String getDefaultEndpoint() { 124 return "jobs.googleapis.com:443"; 125 } 126 127 /** Returns the default mTLS service endpoint. */ getDefaultMtlsEndpoint()128 public static String getDefaultMtlsEndpoint() { 129 return "jobs.mtls.googleapis.com:443"; 130 } 131 132 /** Returns the default service scopes. */ getDefaultServiceScopes()133 public static List<String> getDefaultServiceScopes() { 134 return DEFAULT_SERVICE_SCOPES; 135 } 136 137 /** Returns a builder for the default credentials for this service. */ defaultCredentialsProviderBuilder()138 public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { 139 return GoogleCredentialsProvider.newBuilder() 140 .setScopesToApply(DEFAULT_SERVICE_SCOPES) 141 .setUseJwtAccessWithScope(true); 142 } 143 144 /** Returns a builder for the default gRPC ChannelProvider for this service. */ defaultGrpcTransportProviderBuilder()145 public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { 146 return InstantiatingGrpcChannelProvider.newBuilder() 147 .setMaxInboundMessageSize(Integer.MAX_VALUE); 148 } 149 150 /** Returns a builder for the default REST ChannelProvider for this service. */ 151 @BetaApi 152 public static InstantiatingHttpJsonChannelProvider.Builder defaultHttpJsonTransportProviderBuilder()153 defaultHttpJsonTransportProviderBuilder() { 154 return InstantiatingHttpJsonChannelProvider.newBuilder(); 155 } 156 defaultTransportChannelProvider()157 public static TransportChannelProvider defaultTransportChannelProvider() { 158 return defaultGrpcTransportProviderBuilder().build(); 159 } 160 161 @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") defaultGrpcApiClientHeaderProviderBuilder()162 public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { 163 return ApiClientHeaderProvider.newBuilder() 164 .setGeneratedLibToken( 165 "gapic", GaxProperties.getLibraryVersion(CompletionStubSettings.class)) 166 .setTransportToken( 167 GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); 168 } 169 170 @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") defaultHttpJsonApiClientHeaderProviderBuilder()171 public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { 172 return ApiClientHeaderProvider.newBuilder() 173 .setGeneratedLibToken( 174 "gapic", GaxProperties.getLibraryVersion(CompletionStubSettings.class)) 175 .setTransportToken( 176 GaxHttpJsonProperties.getHttpJsonTokenName(), 177 GaxHttpJsonProperties.getHttpJsonVersion()); 178 } 179 defaultApiClientHeaderProviderBuilder()180 public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { 181 return CompletionStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); 182 } 183 184 /** Returns a new gRPC builder for this class. */ newBuilder()185 public static Builder newBuilder() { 186 return Builder.createDefault(); 187 } 188 189 /** Returns a new REST builder for this class. */ newHttpJsonBuilder()190 public static Builder newHttpJsonBuilder() { 191 return Builder.createHttpJsonDefault(); 192 } 193 194 /** Returns a new builder for this class. */ newBuilder(ClientContext clientContext)195 public static Builder newBuilder(ClientContext clientContext) { 196 return new Builder(clientContext); 197 } 198 199 /** Returns a builder containing all the values of this settings class. */ toBuilder()200 public Builder toBuilder() { 201 return new Builder(this); 202 } 203 CompletionStubSettings(Builder settingsBuilder)204 protected CompletionStubSettings(Builder settingsBuilder) throws IOException { 205 super(settingsBuilder); 206 207 completeQuerySettings = settingsBuilder.completeQuerySettings().build(); 208 } 209 210 /** Builder for CompletionStubSettings. */ 211 public static class Builder extends StubSettings.Builder<CompletionStubSettings, Builder> { 212 private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders; 213 private final UnaryCallSettings.Builder<CompleteQueryRequest, CompleteQueryResponse> 214 completeQuerySettings; 215 private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>> 216 RETRYABLE_CODE_DEFINITIONS; 217 218 static { 219 ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions = 220 ImmutableMap.builder(); 221 definitions.put( 222 "retry_policy_7_codes", 223 ImmutableSet.copyOf( 224 Lists.<StatusCode.Code>newArrayList( 225 StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); 226 RETRYABLE_CODE_DEFINITIONS = definitions.build(); 227 } 228 229 private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS; 230 231 static { 232 ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder(); 233 RetrySettings settings = null; 234 settings = 235 RetrySettings.newBuilder() 236 .setInitialRetryDelay(Duration.ofMillis(100L)) 237 .setRetryDelayMultiplier(1.3) 238 .setMaxRetryDelay(Duration.ofMillis(60000L)) 239 .setInitialRpcTimeout(Duration.ofMillis(30000L)) 240 .setRpcTimeoutMultiplier(1.0) 241 .setMaxRpcTimeout(Duration.ofMillis(30000L)) 242 .setTotalTimeout(Duration.ofMillis(30000L)) 243 .build(); 244 definitions.put("retry_policy_7_params", settings); 245 RETRY_PARAM_DEFINITIONS = definitions.build(); 246 } 247 Builder()248 protected Builder() { 249 this(((ClientContext) null)); 250 } 251 Builder(ClientContext clientContext)252 protected Builder(ClientContext clientContext) { 253 super(clientContext); 254 255 completeQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); 256 257 unaryMethodSettingsBuilders = 258 ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(completeQuerySettings); 259 initDefaults(this); 260 } 261 Builder(CompletionStubSettings settings)262 protected Builder(CompletionStubSettings settings) { 263 super(settings); 264 265 completeQuerySettings = settings.completeQuerySettings.toBuilder(); 266 267 unaryMethodSettingsBuilders = 268 ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(completeQuerySettings); 269 } 270 createDefault()271 private static Builder createDefault() { 272 Builder builder = new Builder(((ClientContext) null)); 273 274 builder.setTransportChannelProvider(defaultTransportChannelProvider()); 275 builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); 276 builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); 277 builder.setEndpoint(getDefaultEndpoint()); 278 builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); 279 builder.setSwitchToMtlsEndpointAllowed(true); 280 281 return initDefaults(builder); 282 } 283 createHttpJsonDefault()284 private static Builder createHttpJsonDefault() { 285 Builder builder = new Builder(((ClientContext) null)); 286 287 builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); 288 builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); 289 builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); 290 builder.setEndpoint(getDefaultEndpoint()); 291 builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); 292 builder.setSwitchToMtlsEndpointAllowed(true); 293 294 return initDefaults(builder); 295 } 296 initDefaults(Builder builder)297 private static Builder initDefaults(Builder builder) { 298 builder 299 .completeQuerySettings() 300 .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_7_codes")) 301 .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_7_params")); 302 303 return builder; 304 } 305 306 /** 307 * Applies the given settings updater function to all of the unary API methods in this service. 308 * 309 * <p>Note: This method does not support applying settings to streaming methods. 310 */ applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)311 public Builder applyToAllUnaryMethods( 312 ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) { 313 super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); 314 return this; 315 } 316 unaryMethodSettingsBuilders()317 public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() { 318 return unaryMethodSettingsBuilders; 319 } 320 321 /** Returns the builder for the settings used for calls to completeQuery. */ 322 public UnaryCallSettings.Builder<CompleteQueryRequest, CompleteQueryResponse> completeQuerySettings()323 completeQuerySettings() { 324 return completeQuerySettings; 325 } 326 327 @Override build()328 public CompletionStubSettings build() throws IOException { 329 return new CompletionStubSettings(this); 330 } 331 } 332 } 333