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.automl.v1; 18 19 import com.google.api.core.ApiFunction; 20 import com.google.api.core.BetaApi; 21 import com.google.api.gax.core.GoogleCredentialsProvider; 22 import com.google.api.gax.core.InstantiatingExecutorProvider; 23 import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; 24 import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; 25 import com.google.api.gax.rpc.ApiClientHeaderProvider; 26 import com.google.api.gax.rpc.ClientContext; 27 import com.google.api.gax.rpc.ClientSettings; 28 import com.google.api.gax.rpc.OperationCallSettings; 29 import com.google.api.gax.rpc.TransportChannelProvider; 30 import com.google.api.gax.rpc.UnaryCallSettings; 31 import com.google.cloud.automl.v1.stub.PredictionServiceStubSettings; 32 import com.google.longrunning.Operation; 33 import java.io.IOException; 34 import java.util.List; 35 import javax.annotation.Generated; 36 37 // AUTO-GENERATED DOCUMENTATION AND CLASS. 38 /** 39 * Settings class to configure an instance of {@link PredictionServiceClient}. 40 * 41 * <p>The default instance has everything set to sensible defaults: 42 * 43 * <ul> 44 * <li>The default service address (automl.googleapis.com) and default port (443) are used. 45 * <li>Credentials are acquired automatically through Application Default Credentials. 46 * <li>Retries are configured for idempotent methods but not for non-idempotent methods. 47 * </ul> 48 * 49 * <p>The builder of this class is recursive, so contained classes are themselves builders. When 50 * build() is called, the tree of builders is called to create the complete settings object. 51 * 52 * <p>For example, to set the total timeout of predict to 30 seconds: 53 * 54 * <pre>{@code 55 * // This snippet has been automatically generated and should be regarded as a code template only. 56 * // It will require modifications to work: 57 * // - It may require correct/in-range values for request initialization. 58 * // - It may require specifying regional endpoints when creating the service client as shown in 59 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 60 * PredictionServiceSettings.Builder predictionServiceSettingsBuilder = 61 * PredictionServiceSettings.newBuilder(); 62 * predictionServiceSettingsBuilder 63 * .predictSettings() 64 * .setRetrySettings( 65 * predictionServiceSettingsBuilder 66 * .predictSettings() 67 * .getRetrySettings() 68 * .toBuilder() 69 * .setTotalTimeout(Duration.ofSeconds(30)) 70 * .build()); 71 * PredictionServiceSettings predictionServiceSettings = predictionServiceSettingsBuilder.build(); 72 * }</pre> 73 */ 74 @Generated("by gapic-generator-java") 75 public class PredictionServiceSettings extends ClientSettings<PredictionServiceSettings> { 76 77 /** Returns the object with the settings used for calls to predict. */ predictSettings()78 public UnaryCallSettings<PredictRequest, PredictResponse> predictSettings() { 79 return ((PredictionServiceStubSettings) getStubSettings()).predictSettings(); 80 } 81 82 /** Returns the object with the settings used for calls to batchPredict. */ batchPredictSettings()83 public UnaryCallSettings<BatchPredictRequest, Operation> batchPredictSettings() { 84 return ((PredictionServiceStubSettings) getStubSettings()).batchPredictSettings(); 85 } 86 87 /** Returns the object with the settings used for calls to batchPredict. */ 88 public OperationCallSettings<BatchPredictRequest, BatchPredictResult, OperationMetadata> batchPredictOperationSettings()89 batchPredictOperationSettings() { 90 return ((PredictionServiceStubSettings) getStubSettings()).batchPredictOperationSettings(); 91 } 92 create(PredictionServiceStubSettings stub)93 public static final PredictionServiceSettings create(PredictionServiceStubSettings stub) 94 throws IOException { 95 return new PredictionServiceSettings.Builder(stub.toBuilder()).build(); 96 } 97 98 /** Returns a builder for the default ExecutorProvider for this service. */ defaultExecutorProviderBuilder()99 public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { 100 return PredictionServiceStubSettings.defaultExecutorProviderBuilder(); 101 } 102 103 /** Returns the default service endpoint. */ getDefaultEndpoint()104 public static String getDefaultEndpoint() { 105 return PredictionServiceStubSettings.getDefaultEndpoint(); 106 } 107 108 /** Returns the default service scopes. */ getDefaultServiceScopes()109 public static List<String> getDefaultServiceScopes() { 110 return PredictionServiceStubSettings.getDefaultServiceScopes(); 111 } 112 113 /** Returns a builder for the default credentials for this service. */ defaultCredentialsProviderBuilder()114 public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { 115 return PredictionServiceStubSettings.defaultCredentialsProviderBuilder(); 116 } 117 118 /** Returns a builder for the default gRPC ChannelProvider for this service. */ defaultGrpcTransportProviderBuilder()119 public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { 120 return PredictionServiceStubSettings.defaultGrpcTransportProviderBuilder(); 121 } 122 123 /** Returns a builder for the default REST ChannelProvider for this service. */ 124 @BetaApi 125 public static InstantiatingHttpJsonChannelProvider.Builder defaultHttpJsonTransportProviderBuilder()126 defaultHttpJsonTransportProviderBuilder() { 127 return PredictionServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); 128 } 129 defaultTransportChannelProvider()130 public static TransportChannelProvider defaultTransportChannelProvider() { 131 return PredictionServiceStubSettings.defaultTransportChannelProvider(); 132 } 133 134 @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") defaultApiClientHeaderProviderBuilder()135 public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { 136 return PredictionServiceStubSettings.defaultApiClientHeaderProviderBuilder(); 137 } 138 139 /** Returns a new gRPC builder for this class. */ newBuilder()140 public static Builder newBuilder() { 141 return Builder.createDefault(); 142 } 143 144 /** Returns a new REST builder for this class. */ 145 @BetaApi newHttpJsonBuilder()146 public static Builder newHttpJsonBuilder() { 147 return Builder.createHttpJsonDefault(); 148 } 149 150 /** Returns a new builder for this class. */ newBuilder(ClientContext clientContext)151 public static Builder newBuilder(ClientContext clientContext) { 152 return new Builder(clientContext); 153 } 154 155 /** Returns a builder containing all the values of this settings class. */ toBuilder()156 public Builder toBuilder() { 157 return new Builder(this); 158 } 159 PredictionServiceSettings(Builder settingsBuilder)160 protected PredictionServiceSettings(Builder settingsBuilder) throws IOException { 161 super(settingsBuilder); 162 } 163 164 /** Builder for PredictionServiceSettings. */ 165 public static class Builder extends ClientSettings.Builder<PredictionServiceSettings, Builder> { 166 Builder()167 protected Builder() throws IOException { 168 this(((ClientContext) null)); 169 } 170 Builder(ClientContext clientContext)171 protected Builder(ClientContext clientContext) { 172 super(PredictionServiceStubSettings.newBuilder(clientContext)); 173 } 174 Builder(PredictionServiceSettings settings)175 protected Builder(PredictionServiceSettings settings) { 176 super(settings.getStubSettings().toBuilder()); 177 } 178 Builder(PredictionServiceStubSettings.Builder stubSettings)179 protected Builder(PredictionServiceStubSettings.Builder stubSettings) { 180 super(stubSettings); 181 } 182 createDefault()183 private static Builder createDefault() { 184 return new Builder(PredictionServiceStubSettings.newBuilder()); 185 } 186 187 @BetaApi createHttpJsonDefault()188 private static Builder createHttpJsonDefault() { 189 return new Builder(PredictionServiceStubSettings.newHttpJsonBuilder()); 190 } 191 getStubSettingsBuilder()192 public PredictionServiceStubSettings.Builder getStubSettingsBuilder() { 193 return ((PredictionServiceStubSettings.Builder) getStubSettings()); 194 } 195 196 /** 197 * Applies the given settings updater function to all of the unary API methods in this service. 198 * 199 * <p>Note: This method does not support applying settings to streaming methods. 200 */ applyToAllUnaryMethods( ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater)201 public Builder applyToAllUnaryMethods( 202 ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) { 203 super.applyToAllUnaryMethods( 204 getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); 205 return this; 206 } 207 208 /** Returns the builder for the settings used for calls to predict. */ predictSettings()209 public UnaryCallSettings.Builder<PredictRequest, PredictResponse> predictSettings() { 210 return getStubSettingsBuilder().predictSettings(); 211 } 212 213 /** Returns the builder for the settings used for calls to batchPredict. */ batchPredictSettings()214 public UnaryCallSettings.Builder<BatchPredictRequest, Operation> batchPredictSettings() { 215 return getStubSettingsBuilder().batchPredictSettings(); 216 } 217 218 /** Returns the builder for the settings used for calls to batchPredict. */ 219 public OperationCallSettings.Builder<BatchPredictRequest, BatchPredictResult, OperationMetadata> batchPredictOperationSettings()220 batchPredictOperationSettings() { 221 return getStubSettingsBuilder().batchPredictOperationSettings(); 222 } 223 224 @Override build()225 public PredictionServiceSettings build() throws IOException { 226 return new PredictionServiceSettings(this); 227 } 228 } 229 } 230