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