|
| 1 | +package com.google.api.version.test.stub; |
| 2 | + |
| 3 | +import com.google.api.core.ApiFunction; |
| 4 | +import com.google.api.gax.core.GaxProperties; |
| 5 | +import com.google.api.gax.core.GoogleCredentialsProvider; |
| 6 | +import com.google.api.gax.core.InstantiatingExecutorProvider; |
| 7 | +import com.google.api.gax.grpc.GaxGrpcProperties; |
| 8 | +import com.google.api.gax.grpc.GrpcTransportChannel; |
| 9 | +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; |
| 10 | +import com.google.api.gax.retrying.RetrySettings; |
| 11 | +import com.google.api.gax.rpc.ApiClientHeaderProvider; |
| 12 | +import com.google.api.gax.rpc.ClientContext; |
| 13 | +import com.google.api.gax.rpc.StatusCode; |
| 14 | +import com.google.api.gax.rpc.StubSettings; |
| 15 | +import com.google.api.gax.rpc.TransportChannelProvider; |
| 16 | +import com.google.api.gax.rpc.UnaryCallSettings; |
| 17 | +import com.google.api.version.test.EchoRequest; |
| 18 | +import com.google.api.version.test.EchoResponse; |
| 19 | +import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.common.collect.ImmutableMap; |
| 21 | +import com.google.common.collect.ImmutableSet; |
| 22 | +import com.google.common.collect.Lists; |
| 23 | +import java.io.IOException; |
| 24 | +import java.util.List; |
| 25 | +import javax.annotation.Generated; |
| 26 | + |
| 27 | +// AUTO-GENERATED DOCUMENTATION AND CLASS. |
| 28 | +/** |
| 29 | + * Settings class to configure an instance of {@link EchoWithVersionStub}. |
| 30 | + * |
| 31 | + * <p>The default instance has everything set to sensible defaults: |
| 32 | + * |
| 33 | + * <ul> |
| 34 | + * <li>The default service address (localhost) and default port (7469) are used. |
| 35 | + * <li>Credentials are acquired automatically through Application Default Credentials. |
| 36 | + * <li>Retries are configured for idempotent methods but not for non-idempotent methods. |
| 37 | + * </ul> |
| 38 | + * |
| 39 | + * <p>The builder of this class is recursive, so contained classes are themselves builders. When |
| 40 | + * build() is called, the tree of builders is called to create the complete settings object. |
| 41 | + * |
| 42 | + * <p>For example, to set the total timeout of echoWithVersionMethod to 30 seconds: |
| 43 | + * |
| 44 | + * <pre>{@code |
| 45 | + * // This snippet has been automatically generated and should be regarded as a code template only. |
| 46 | + * // It will require modifications to work: |
| 47 | + * // - It may require correct/in-range values for request initialization. |
| 48 | + * // - It may require specifying regional endpoints when creating the service client as shown in |
| 49 | + * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
| 50 | + * EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder = |
| 51 | + * EchoWithVersionStubSettings.newBuilder(); |
| 52 | + * echoWithVersionSettingsBuilder |
| 53 | + * .echoWithVersionMethodSettings() |
| 54 | + * .setRetrySettings( |
| 55 | + * echoWithVersionSettingsBuilder |
| 56 | + * .echoWithVersionMethodSettings() |
| 57 | + * .getRetrySettings() |
| 58 | + * .toBuilder() |
| 59 | + * .setTotalTimeout(Duration.ofSeconds(30)) |
| 60 | + * .build()); |
| 61 | + * EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build(); |
| 62 | + * }</pre> |
| 63 | + */ |
| 64 | +@Generated("by gapic-generator-java") |
| 65 | +public class EchoWithVersionStubSettings extends StubSettings<EchoWithVersionStubSettings> { |
| 66 | + /** The default scopes of the service. */ |
| 67 | + private static final ImmutableList<String> DEFAULT_SERVICE_SCOPES = |
| 68 | + ImmutableList.<String>builder().add("https://www.googleapis.com/auth/cloud-platform").build(); |
| 69 | + |
| 70 | + private final UnaryCallSettings<EchoRequest, EchoResponse> echoWithVersionMethodSettings; |
| 71 | + |
| 72 | + /** Returns the object with the settings used for calls to echoWithVersionMethod. */ |
| 73 | + public UnaryCallSettings<EchoRequest, EchoResponse> echoWithVersionMethodSettings() { |
| 74 | + return echoWithVersionMethodSettings; |
| 75 | + } |
| 76 | + |
| 77 | + public EchoWithVersionStub createStub() throws IOException { |
| 78 | + if (getTransportChannelProvider() |
| 79 | + .getTransportName() |
| 80 | + .equals(GrpcTransportChannel.getGrpcTransportName())) { |
| 81 | + return GrpcEchoWithVersionStub.create(this); |
| 82 | + } |
| 83 | + throw new UnsupportedOperationException( |
| 84 | + String.format( |
| 85 | + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); |
| 86 | + } |
| 87 | + |
| 88 | + /** Returns a builder for the default ExecutorProvider for this service. */ |
| 89 | + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { |
| 90 | + return InstantiatingExecutorProvider.newBuilder(); |
| 91 | + } |
| 92 | + |
| 93 | + /** Returns the default service endpoint. */ |
| 94 | + public static String getDefaultEndpoint() { |
| 95 | + return "localhost:7469"; |
| 96 | + } |
| 97 | + |
| 98 | + /** Returns the default mTLS service endpoint. */ |
| 99 | + public static String getDefaultMtlsEndpoint() { |
| 100 | + return "localhost:7469"; |
| 101 | + } |
| 102 | + |
| 103 | + /** Returns the default service scopes. */ |
| 104 | + public static List<String> getDefaultServiceScopes() { |
| 105 | + return DEFAULT_SERVICE_SCOPES; |
| 106 | + } |
| 107 | + |
| 108 | + /** Returns a builder for the default credentials for this service. */ |
| 109 | + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { |
| 110 | + return GoogleCredentialsProvider.newBuilder() |
| 111 | + .setScopesToApply(DEFAULT_SERVICE_SCOPES) |
| 112 | + .setUseJwtAccessWithScope(true); |
| 113 | + } |
| 114 | + |
| 115 | + /** Returns a builder for the default ChannelProvider for this service. */ |
| 116 | + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { |
| 117 | + return InstantiatingGrpcChannelProvider.newBuilder() |
| 118 | + .setMaxInboundMessageSize(Integer.MAX_VALUE); |
| 119 | + } |
| 120 | + |
| 121 | + public static TransportChannelProvider defaultTransportChannelProvider() { |
| 122 | + return defaultGrpcTransportProviderBuilder().build(); |
| 123 | + } |
| 124 | + |
| 125 | + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { |
| 126 | + return ApiClientHeaderProvider.newBuilder() |
| 127 | + .setGeneratedLibToken( |
| 128 | + "gapic", GaxProperties.getLibraryVersion(EchoWithVersionStubSettings.class)) |
| 129 | + .setTransportToken(GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()) |
| 130 | + .setApiVersionToken("fake_version"); |
| 131 | + } |
| 132 | + |
| 133 | + /** Returns a new builder for this class. */ |
| 134 | + public static Builder newBuilder() { |
| 135 | + return Builder.createDefault(); |
| 136 | + } |
| 137 | + |
| 138 | + /** Returns a new builder for this class. */ |
| 139 | + public static Builder newBuilder(ClientContext clientContext) { |
| 140 | + return new Builder(clientContext); |
| 141 | + } |
| 142 | + |
| 143 | + /** Returns a builder containing all the values of this settings class. */ |
| 144 | + public Builder toBuilder() { |
| 145 | + return new Builder(this); |
| 146 | + } |
| 147 | + |
| 148 | + protected EchoWithVersionStubSettings(Builder settingsBuilder) throws IOException { |
| 149 | + super(settingsBuilder); |
| 150 | + |
| 151 | + echoWithVersionMethodSettings = settingsBuilder.echoWithVersionMethodSettings().build(); |
| 152 | + } |
| 153 | + |
| 154 | + /** Builder for EchoWithVersionStubSettings. */ |
| 155 | + public static class Builder extends StubSettings.Builder<EchoWithVersionStubSettings, Builder> { |
| 156 | + private final ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders; |
| 157 | + private final UnaryCallSettings.Builder<EchoRequest, EchoResponse> |
| 158 | + echoWithVersionMethodSettings; |
| 159 | + private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>> |
| 160 | + RETRYABLE_CODE_DEFINITIONS; |
| 161 | + |
| 162 | + static { |
| 163 | + ImmutableMap.Builder<String, ImmutableSet<StatusCode.Code>> definitions = |
| 164 | + ImmutableMap.builder(); |
| 165 | + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList())); |
| 166 | + RETRYABLE_CODE_DEFINITIONS = definitions.build(); |
| 167 | + } |
| 168 | + |
| 169 | + private static final ImmutableMap<String, RetrySettings> RETRY_PARAM_DEFINITIONS; |
| 170 | + |
| 171 | + static { |
| 172 | + ImmutableMap.Builder<String, RetrySettings> definitions = ImmutableMap.builder(); |
| 173 | + RetrySettings settings = null; |
| 174 | + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); |
| 175 | + definitions.put("no_retry_params", settings); |
| 176 | + RETRY_PARAM_DEFINITIONS = definitions.build(); |
| 177 | + } |
| 178 | + |
| 179 | + protected Builder() { |
| 180 | + this(((ClientContext) null)); |
| 181 | + } |
| 182 | + |
| 183 | + protected Builder(ClientContext clientContext) { |
| 184 | + super(clientContext); |
| 185 | + |
| 186 | + echoWithVersionMethodSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); |
| 187 | + |
| 188 | + unaryMethodSettingsBuilders = |
| 189 | + ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(echoWithVersionMethodSettings); |
| 190 | + initDefaults(this); |
| 191 | + } |
| 192 | + |
| 193 | + protected Builder(EchoWithVersionStubSettings settings) { |
| 194 | + super(settings); |
| 195 | + |
| 196 | + echoWithVersionMethodSettings = settings.echoWithVersionMethodSettings.toBuilder(); |
| 197 | + |
| 198 | + unaryMethodSettingsBuilders = |
| 199 | + ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(echoWithVersionMethodSettings); |
| 200 | + } |
| 201 | + |
| 202 | + private static Builder createDefault() { |
| 203 | + Builder builder = new Builder(((ClientContext) null)); |
| 204 | + |
| 205 | + builder.setTransportChannelProvider(defaultTransportChannelProvider()); |
| 206 | + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); |
| 207 | + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); |
| 208 | + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); |
| 209 | + builder.setSwitchToMtlsEndpointAllowed(true); |
| 210 | + |
| 211 | + return initDefaults(builder); |
| 212 | + } |
| 213 | + |
| 214 | + private static Builder initDefaults(Builder builder) { |
| 215 | + builder |
| 216 | + .echoWithVersionMethodSettings() |
| 217 | + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) |
| 218 | + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); |
| 219 | + |
| 220 | + return builder; |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * Applies the given settings updater function to all of the unary API methods in this service. |
| 225 | + * |
| 226 | + * <p>Note: This method does not support applying settings to streaming methods. |
| 227 | + */ |
| 228 | + public Builder applyToAllUnaryMethods( |
| 229 | + ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> settingsUpdater) { |
| 230 | + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); |
| 231 | + return this; |
| 232 | + } |
| 233 | + |
| 234 | + public ImmutableList<UnaryCallSettings.Builder<?, ?>> unaryMethodSettingsBuilders() { |
| 235 | + return unaryMethodSettingsBuilders; |
| 236 | + } |
| 237 | + |
| 238 | + /** Returns the builder for the settings used for calls to echoWithVersionMethod. */ |
| 239 | + public UnaryCallSettings.Builder<EchoRequest, EchoResponse> echoWithVersionMethodSettings() { |
| 240 | + return echoWithVersionMethodSettings; |
| 241 | + } |
| 242 | + |
| 243 | + @Override |
| 244 | + public EchoWithVersionStubSettings build() throws IOException { |
| 245 | + return new EchoWithVersionStubSettings(this); |
| 246 | + } |
| 247 | + } |
| 248 | +} |
0 commit comments