Note: close() needs to be called on the DeprecatedServiceClient object to clean up resources
- * such as threads. In the example above, try-with-resources is used, which automatically calls
- * close().
- *
- *
The surface of this class includes several types of Java methods for each of the API's
- * methods:
+ *
The default instance has everything set to sensible defaults:
*
- *
- *
A "flattened" method. With this type of method, the fields of the request type have been
- * converted into function parameters. It may be the case that not all fields are available as
- * parameters, and not every API method will have a flattened method entry point.
- *
A "request object" method. This type of method only takes one parameter, a request object,
- * which must be constructed before the call. Not every API method will have a request object
- * method.
- *
A "callable" method. This type of method takes no parameters and returns an immutable API
- * callable object, which can be used to initiate calls to the service.
- *
+ *
+ *
The default service address (localhost) and default port (7469) are used.
+ *
Credentials are acquired automatically through Application Default Credentials.
+ *
Retries are configured for idempotent methods but not for non-idempotent methods.
+ *
*
- *
See the individual methods for example code.
+ *
The builder of this class is recursive, so contained classes are themselves builders. When
+ * build() is called, the tree of builders is called to create the complete settings object.
*
- *
Many parameters require resource names to be formatted in a particular way. To assist with
- * these names, this class includes a format method for each type of name, and additionally a parse
- * method to extract the individual identifiers contained within names that are returned.
- *
- *
This class can be customized by passing in a custom instance of DeprecatedServiceSettings to
- * create(). For example:
- *
- *
To customize credentials:
+ *
For example, to set the total timeout of fastFibonacci to 30 seconds:
*
*
Please refer to the GitHub repository's samples for more quickstart code snippets.
- *
* @deprecated This class is deprecated and will be removed in the next major version update.
*/
@Deprecated
@Generated("by gapic-generator-java")
-public class DeprecatedServiceClient implements BackgroundResource {
- private final DeprecatedServiceSettings settings;
- private final DeprecatedServiceStub stub;
+public class DeprecatedServiceSettings extends ClientSettings {
- /** Constructs an instance of DeprecatedServiceClient with default settings. */
- public static final DeprecatedServiceClient create() throws IOException {
- return create(DeprecatedServiceSettings.newBuilder().build());
+ /** Returns the object with the settings used for calls to fastFibonacci. */
+ public UnaryCallSettings fastFibonacciSettings() {
+ return ((DeprecatedServiceStubSettings) getStubSettings()).fastFibonacciSettings();
}
/**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. The channels are
- * created based on the settings passed in, or defaults for any settings that are not set.
+ * Returns the object with the settings used for calls to slowFibonacci.
+ *
+ * @deprecated This method is deprecated and will be removed in the next major version update.
*/
- public static final DeprecatedServiceClient create(DeprecatedServiceSettings settings)
- throws IOException {
- return new DeprecatedServiceClient(settings);
+ @Deprecated
+ public UnaryCallSettings slowFibonacciSettings() {
+ return ((DeprecatedServiceStubSettings) getStubSettings()).slowFibonacciSettings();
}
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given stub for making calls. This
- * is for advanced usage - prefer using create(DeprecatedServiceSettings).
- */
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public static final DeprecatedServiceClient create(DeprecatedServiceStub stub) {
- return new DeprecatedServiceClient(stub);
+ public static final DeprecatedServiceSettings create(DeprecatedServiceStubSettings stub)
+ throws IOException {
+ return new DeprecatedServiceSettings.Builder(stub.toBuilder()).build();
}
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. This is protected
- * so that it is easy to make a subclass, but otherwise, the static factory methods should be
- * preferred.
- */
- protected DeprecatedServiceClient(DeprecatedServiceSettings settings) throws IOException {
- this.settings = settings;
- this.stub = ((DeprecatedServiceStubSettings) settings.getStubSettings()).createStub();
+ /** Returns a builder for the default ExecutorProvider for this service. */
+ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
+ return DeprecatedServiceStubSettings.defaultExecutorProviderBuilder();
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- protected DeprecatedServiceClient(DeprecatedServiceStub stub) {
- this.settings = null;
- this.stub = stub;
+ /** Returns the default service endpoint. */
+ public static String getDefaultEndpoint() {
+ return DeprecatedServiceStubSettings.getDefaultEndpoint();
}
- public final DeprecatedServiceSettings getSettings() {
- return settings;
+ /** Returns the default service scopes. */
+ public static List getDefaultServiceScopes() {
+ return DeprecatedServiceStubSettings.getDefaultServiceScopes();
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public DeprecatedServiceStub getStub() {
- return stub;
+ /** Returns a builder for the default credentials for this service. */
+ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
+ return DeprecatedServiceStubSettings.defaultCredentialsProviderBuilder();
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- */
- public final void fastFibonacci(FibonacciRequest request) {
- fastFibonacciCallable().call(request);
+ /** Returns a builder for the default ChannelProvider for this service. */
+ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
+ return DeprecatedServiceStubSettings.defaultGrpcTransportProviderBuilder();
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final void slowFibonacci(FibonacciRequest request) {
- slowFibonacciCallable().call(request);
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return DeprecatedServiceStubSettings.defaultApiClientHeaderProviderBuilder();
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final UnaryCallable slowFibonacciCallable() {
- return stub.slowFibonacciCallable();
+ /** Returns a new builder for this class. */
+ public static Builder newBuilder() {
+ return Builder.createDefault();
}
- @Override
- public final void close() {
- stub.close();
+ /** Returns a new builder for this class. */
+ public static Builder newBuilder(ClientContext clientContext) {
+ return new Builder(clientContext);
}
- @Override
- public void shutdown() {
- stub.shutdown();
+ /** Returns a builder containing all the values of this settings class. */
+ public Builder toBuilder() {
+ return new Builder(this);
}
- @Override
- public boolean isShutdown() {
- return stub.isShutdown();
+ protected DeprecatedServiceSettings(Builder settingsBuilder) throws IOException {
+ super(settingsBuilder);
}
- @Override
- public boolean isTerminated() {
- return stub.isTerminated();
- }
+ /** Builder for DeprecatedServiceSettings. */
+ public static class Builder extends ClientSettings.Builder {
- @Override
- public void shutdownNow() {
- stub.shutdownNow();
- }
+ protected Builder() throws IOException {
+ this(((ClientContext) null));
+ }
+
+ protected Builder(ClientContext clientContext) {
+ super(DeprecatedServiceStubSettings.newBuilder(clientContext));
+ }
+
+ protected Builder(DeprecatedServiceSettings settings) {
+ super(settings.getStubSettings().toBuilder());
+ }
+
+ protected Builder(DeprecatedServiceStubSettings.Builder stubSettings) {
+ super(stubSettings);
+ }
+
+ private static Builder createDefault() {
+ return new Builder(DeprecatedServiceStubSettings.newBuilder());
+ }
+
+ public DeprecatedServiceStubSettings.Builder getStubSettingsBuilder() {
+ return ((DeprecatedServiceStubSettings.Builder) getStubSettings());
+ }
+
+ // NEXT_MAJOR_VER: remove 'throws Exception'.
+ /**
+ * Applies the given settings updater function to all of the unary API methods in this service.
+ *
+ *
Note: This method does not support applying settings to streaming methods.
+ */
+ public Builder applyToAllUnaryMethods(
+ ApiFunction, Void> settingsUpdater) throws Exception {
+ super.applyToAllUnaryMethods(
+ getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater);
+ return this;
+ }
+
+ /** Returns the builder for the settings used for calls to fastFibonacci. */
+ public UnaryCallSettings.Builder fastFibonacciSettings() {
+ return getStubSettingsBuilder().fastFibonacciSettings();
+ }
+
+ /**
+ * Returns the builder for the settings used for calls to slowFibonacci.
+ *
+ * @deprecated This method is deprecated and will be removed in the next major version update.
+ */
+ @Deprecated
+ public UnaryCallSettings.Builder slowFibonacciSettings() {
+ return getStubSettingsBuilder().slowFibonacciSettings();
+ }
- @Override
- public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
- return stub.awaitTermination(duration, unit);
+ @Override
+ public DeprecatedServiceSettings build() throws IOException {
+ return new DeprecatedServiceSettings(this);
+ }
}
}
diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/DeprecatedServiceStub.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/DeprecatedServiceStub.golden
index 9af83eb743..6a40197ba4 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/goldens/DeprecatedServiceStub.golden
+++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/DeprecatedServiceStub.golden
@@ -1,234 +1,32 @@
-package com.google.testdata.v1;
+package com.google.testdata.v1.stub;
-import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.protobuf.Empty;
-import com.google.testdata.v1.stub.DeprecatedServiceStub;
-import com.google.testdata.v1.stub.DeprecatedServiceStubSettings;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
+import com.google.testdata.v1.FibonacciRequest;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
- * This class provides the ability to make remote calls to the backing service through method calls
- * that map to API methods. Sample code to get started:
+ * Base stub class for the DeprecatedService service API.
*
- *
Note: close() needs to be called on the DeprecatedServiceClient object to clean up resources
- * such as threads. In the example above, try-with-resources is used, which automatically calls
- * close().
- *
- *
The surface of this class includes several types of Java methods for each of the API's
- * methods:
- *
- *
- *
A "flattened" method. With this type of method, the fields of the request type have been
- * converted into function parameters. It may be the case that not all fields are available as
- * parameters, and not every API method will have a flattened method entry point.
- *
A "request object" method. This type of method only takes one parameter, a request object,
- * which must be constructed before the call. Not every API method will have a request object
- * method.
- *
A "callable" method. This type of method takes no parameters and returns an immutable API
- * callable object, which can be used to initiate calls to the service.
- *
- *
- *
See the individual methods for example code.
- *
- *
Many parameters require resource names to be formatted in a particular way. To assist with
- * these names, this class includes a format method for each type of name, and additionally a parse
- * method to extract the individual identifiers contained within names that are returned.
- *
- *
This class can be customized by passing in a custom instance of DeprecatedServiceSettings to
- * create(). For example:
- *
- *
Please refer to the GitHub repository's samples for more quickstart code snippets.
+ *
This class is for advanced usage and reflects the underlying API directly.
*
* @deprecated This class is deprecated and will be removed in the next major version update.
*/
@Deprecated
@Generated("by gapic-generator-java")
-public class DeprecatedServiceClient implements BackgroundResource {
- private final DeprecatedServiceSettings settings;
- private final DeprecatedServiceStub stub;
-
- /** Constructs an instance of DeprecatedServiceClient with default settings. */
- public static final DeprecatedServiceClient create() throws IOException {
- return create(DeprecatedServiceSettings.newBuilder().build());
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. The channels are
- * created based on the settings passed in, or defaults for any settings that are not set.
- */
- public static final DeprecatedServiceClient create(DeprecatedServiceSettings settings)
- throws IOException {
- return new DeprecatedServiceClient(settings);
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given stub for making calls. This
- * is for advanced usage - prefer using create(DeprecatedServiceSettings).
- */
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public static final DeprecatedServiceClient create(DeprecatedServiceStub stub) {
- return new DeprecatedServiceClient(stub);
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. This is protected
- * so that it is easy to make a subclass, but otherwise, the static factory methods should be
- * preferred.
- */
- protected DeprecatedServiceClient(DeprecatedServiceSettings settings) throws IOException {
- this.settings = settings;
- this.stub = ((DeprecatedServiceStubSettings) settings.getStubSettings()).createStub();
- }
-
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- protected DeprecatedServiceClient(DeprecatedServiceStub stub) {
- this.settings = null;
- this.stub = stub;
- }
-
- public final DeprecatedServiceSettings getSettings() {
- return settings;
- }
+public abstract class DeprecatedServiceStub implements BackgroundResource {
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public DeprecatedServiceStub getStub() {
- return stub;
+ public UnaryCallable fastFibonacciCallable() {
+ throw new UnsupportedOperationException("Not implemented: fastFibonacciCallable()");
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- */
- public final void fastFibonacci(FibonacciRequest request) {
- fastFibonacciCallable().call(request);
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final void slowFibonacci(FibonacciRequest request) {
- slowFibonacciCallable().call(request);
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
Note: close() needs to be called on the DeprecatedServiceClient object to clean up resources
- * such as threads. In the example above, try-with-resources is used, which automatically calls
- * close().
- *
- *
The surface of this class includes several types of Java methods for each of the API's
- * methods:
- *
- *
- *
A "flattened" method. With this type of method, the fields of the request type have been
- * converted into function parameters. It may be the case that not all fields are available as
- * parameters, and not every API method will have a flattened method entry point.
- *
A "request object" method. This type of method only takes one parameter, a request object,
- * which must be constructed before the call. Not every API method will have a request object
- * method.
- *
A "callable" method. This type of method takes no parameters and returns an immutable API
- * callable object, which can be used to initiate calls to the service.
- *
- *
- *
See the individual methods for example code.
- *
- *
Many parameters require resource names to be formatted in a particular way. To assist with
- * these names, this class includes a format method for each type of name, and additionally a parse
- * method to extract the individual identifiers contained within names that are returned.
- *
- *
This class can be customized by passing in a custom instance of DeprecatedServiceSettings to
- * create(). For example:
+ *
The default instance has everything set to sensible defaults:
*
- *
To customize credentials:
+ *
+ *
The default service address (localhost) and default port (7469) are used.
+ *
Credentials are acquired automatically through Application Default Credentials.
+ *
Retries are configured for idempotent methods but not for non-idempotent methods.
+ *
The builder of this class is recursive, so contained classes are themselves builders. When
+ * build() is called, the tree of builders is called to create the complete settings object.
*
- *
To customize the endpoint:
+ *
For example, to set the total timeout of fastFibonacci to 30 seconds:
*
*
Please refer to the GitHub repository's samples for more quickstart code snippets.
- *
* @deprecated This class is deprecated and will be removed in the next major version update.
*/
@Deprecated
@Generated("by gapic-generator-java")
-public class DeprecatedServiceClient implements BackgroundResource {
- private final DeprecatedServiceSettings settings;
- private final DeprecatedServiceStub stub;
+public class DeprecatedServiceStubSettings extends StubSettings {
+ /** The default scopes of the service. */
+ private static final ImmutableList DEFAULT_SERVICE_SCOPES =
+ ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build();
+
+ private final UnaryCallSettings fastFibonacciSettings;
+ private final UnaryCallSettings slowFibonacciSettings;
- /** Constructs an instance of DeprecatedServiceClient with default settings. */
- public static final DeprecatedServiceClient create() throws IOException {
- return create(DeprecatedServiceSettings.newBuilder().build());
+ /** Returns the object with the settings used for calls to fastFibonacci. */
+ public UnaryCallSettings fastFibonacciSettings() {
+ return fastFibonacciSettings;
}
/**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. The channels are
- * created based on the settings passed in, or defaults for any settings that are not set.
+ * Returns the object with the settings used for calls to slowFibonacci.
+ *
+ * @deprecated This method is deprecated and will be removed in the next major version update.
*/
- public static final DeprecatedServiceClient create(DeprecatedServiceSettings settings)
- throws IOException {
- return new DeprecatedServiceClient(settings);
+ @Deprecated
+ public UnaryCallSettings slowFibonacciSettings() {
+ return slowFibonacciSettings;
}
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given stub for making calls. This
- * is for advanced usage - prefer using create(DeprecatedServiceSettings).
- */
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public static final DeprecatedServiceClient create(DeprecatedServiceStub stub) {
- return new DeprecatedServiceClient(stub);
+ public DeprecatedServiceStub createStub() throws IOException {
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(GrpcTransportChannel.getGrpcTransportName())) {
+ return GrpcDeprecatedServiceStub.create(this);
+ }
+ throw new UnsupportedOperationException(
+ String.format(
+ "Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. This is protected
- * so that it is easy to make a subclass, but otherwise, the static factory methods should be
- * preferred.
- */
- protected DeprecatedServiceClient(DeprecatedServiceSettings settings) throws IOException {
- this.settings = settings;
- this.stub = ((DeprecatedServiceStubSettings) settings.getStubSettings()).createStub();
+ /** Returns a builder for the default ExecutorProvider for this service. */
+ public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
+ return InstantiatingExecutorProvider.newBuilder();
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- protected DeprecatedServiceClient(DeprecatedServiceStub stub) {
- this.settings = null;
- this.stub = stub;
+ /** Returns the default service endpoint. */
+ public static String getDefaultEndpoint() {
+ return "localhost:7469";
}
- public final DeprecatedServiceSettings getSettings() {
- return settings;
+ /** Returns the default service scopes. */
+ public static List getDefaultServiceScopes() {
+ return DEFAULT_SERVICE_SCOPES;
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public DeprecatedServiceStub getStub() {
- return stub;
+ /** Returns a builder for the default credentials for this service. */
+ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
+ return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- */
- public final void fastFibonacci(FibonacciRequest request) {
- fastFibonacciCallable().call(request);
+ /** Returns a builder for the default ChannelProvider for this service. */
+ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
+ return InstantiatingGrpcChannelProvider.newBuilder()
+ .setMaxInboundMessageSize(Integer.MAX_VALUE);
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final void slowFibonacci(FibonacciRequest request) {
- slowFibonacciCallable().call(request);
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return ApiClientHeaderProvider.newBuilder()
+ .setGeneratedLibToken(
+ "gapic", GaxProperties.getLibraryVersion(DeprecatedServiceStubSettings.class))
+ .setTransportToken(
+ GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final UnaryCallable slowFibonacciCallable() {
- return stub.slowFibonacciCallable();
+ /** Returns a new builder for this class. */
+ public static Builder newBuilder() {
+ return Builder.createDefault();
}
- @Override
- public final void close() {
- stub.close();
+ /** Returns a new builder for this class. */
+ public static Builder newBuilder(ClientContext clientContext) {
+ return new Builder(clientContext);
}
- @Override
- public void shutdown() {
- stub.shutdown();
+ /** Returns a builder containing all the values of this settings class. */
+ public Builder toBuilder() {
+ return new Builder(this);
}
- @Override
- public boolean isShutdown() {
- return stub.isShutdown();
- }
+ protected DeprecatedServiceStubSettings(Builder settingsBuilder) throws IOException {
+ super(settingsBuilder);
- @Override
- public boolean isTerminated() {
- return stub.isTerminated();
+ fastFibonacciSettings = settingsBuilder.fastFibonacciSettings().build();
+ slowFibonacciSettings = settingsBuilder.slowFibonacciSettings().build();
}
- @Override
- public void shutdownNow() {
- stub.shutdownNow();
- }
+ /** Builder for DeprecatedServiceStubSettings. */
+ public static class Builder extends StubSettings.Builder {
+ private final ImmutableList> unaryMethodSettingsBuilders;
+ private final UnaryCallSettings.Builder fastFibonacciSettings;
+ private final UnaryCallSettings.Builder slowFibonacciSettings;
+ private static final ImmutableMap>
+ RETRYABLE_CODE_DEFINITIONS;
+
+ static {
+ ImmutableMap.Builder> definitions =
+ ImmutableMap.builder();
+ definitions.put(
+ "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList()));
+ RETRYABLE_CODE_DEFINITIONS = definitions.build();
+ }
+
+ private static final ImmutableMap RETRY_PARAM_DEFINITIONS;
+
+ static {
+ ImmutableMap.Builder definitions = ImmutableMap.builder();
+ RetrySettings settings = null;
+ settings =
+ RetrySettings.newBuilder()
+ .setInitialRpcTimeout(Duration.ofMillis(60000L))
+ .setRpcTimeoutMultiplier(1.0)
+ .setMaxRpcTimeout(Duration.ofMillis(60000L))
+ .setTotalTimeout(Duration.ofMillis(60000L))
+ .build();
+ definitions.put("no_retry_0_params", settings);
+ RETRY_PARAM_DEFINITIONS = definitions.build();
+ }
+
+ protected Builder() {
+ this(((ClientContext) null));
+ }
+
+ protected Builder(ClientContext clientContext) {
+ super(clientContext);
+
+ fastFibonacciSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ slowFibonacciSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+
+ unaryMethodSettingsBuilders =
+ ImmutableList.>of(
+ fastFibonacciSettings, slowFibonacciSettings);
+ initDefaults(this);
+ }
+
+ protected Builder(DeprecatedServiceStubSettings settings) {
+ super(settings);
+
+ fastFibonacciSettings = settings.fastFibonacciSettings.toBuilder();
+ slowFibonacciSettings = settings.slowFibonacciSettings.toBuilder();
+
+ unaryMethodSettingsBuilders =
+ ImmutableList.>of(
+ fastFibonacciSettings, slowFibonacciSettings);
+ }
+
+ private static Builder createDefault() {
+ Builder builder = new Builder(((ClientContext) null));
+
+ builder.setTransportChannelProvider(defaultTransportChannelProvider());
+ builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
+ builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
+ builder.setEndpoint(getDefaultEndpoint());
+
+ return initDefaults(builder);
+ }
+
+ private static Builder initDefaults(Builder builder) {
+ builder
+ .fastFibonacciSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
+
+ builder
+ .slowFibonacciSettings()
+ .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
+ .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
+
+ return builder;
+ }
+
+ // NEXT_MAJOR_VER: remove 'throws Exception'.
+ /**
+ * Applies the given settings updater function to all of the unary API methods in this service.
+ *
+ *
Note: This method does not support applying settings to streaming methods.
+ */
+ public Builder applyToAllUnaryMethods(
+ ApiFunction, Void> settingsUpdater) throws Exception {
+ super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
+ return this;
+ }
+
+ public ImmutableList> unaryMethodSettingsBuilders() {
+ return unaryMethodSettingsBuilders;
+ }
+
+ /** Returns the builder for the settings used for calls to fastFibonacci. */
+ public UnaryCallSettings.Builder fastFibonacciSettings() {
+ return fastFibonacciSettings;
+ }
+
+ /**
+ * Returns the builder for the settings used for calls to slowFibonacci.
+ *
+ * @deprecated This method is deprecated and will be removed in the next major version update.
+ */
+ @Deprecated
+ public UnaryCallSettings.Builder slowFibonacciSettings() {
+ return slowFibonacciSettings;
+ }
- @Override
- public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
- return stub.awaitTermination(duration, unit);
+ @Override
+ public DeprecatedServiceStubSettings build() throws IOException {
+ return new DeprecatedServiceStubSettings(this);
+ }
}
}
diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/MockDeprecatedService.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/MockDeprecatedService.golden
index 9af83eb743..f189549919 100644
--- a/src/test/java/com/google/api/generator/gapic/composer/goldens/MockDeprecatedService.golden
+++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/MockDeprecatedService.golden
@@ -1,234 +1,43 @@
package com.google.testdata.v1;
import com.google.api.core.BetaApi;
-import com.google.api.gax.core.BackgroundResource;
-import com.google.api.gax.rpc.UnaryCallable;
-import com.google.protobuf.Empty;
-import com.google.testdata.v1.stub.DeprecatedServiceStub;
-import com.google.testdata.v1.stub.DeprecatedServiceStubSettings;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
+import com.google.api.gax.grpc.testing.MockGrpcService;
+import com.google.protobuf.AbstractMessage;
+import io.grpc.ServerServiceDefinition;
+import java.util.List;
import javax.annotation.Generated;
-// AUTO-GENERATED DOCUMENTATION AND CLASS.
-/**
- * This class provides the ability to make remote calls to the backing service through method calls
- * that map to API methods. Sample code to get started:
- *
- *
Note: close() needs to be called on the DeprecatedServiceClient object to clean up resources
- * such as threads. In the example above, try-with-resources is used, which automatically calls
- * close().
- *
- *
The surface of this class includes several types of Java methods for each of the API's
- * methods:
- *
- *
- *
A "flattened" method. With this type of method, the fields of the request type have been
- * converted into function parameters. It may be the case that not all fields are available as
- * parameters, and not every API method will have a flattened method entry point.
- *
A "request object" method. This type of method only takes one parameter, a request object,
- * which must be constructed before the call. Not every API method will have a request object
- * method.
- *
A "callable" method. This type of method takes no parameters and returns an immutable API
- * callable object, which can be used to initiate calls to the service.
- *
- *
- *
See the individual methods for example code.
- *
- *
Many parameters require resource names to be formatted in a particular way. To assist with
- * these names, this class includes a format method for each type of name, and additionally a parse
- * method to extract the individual identifiers contained within names that are returned.
- *
- *
This class can be customized by passing in a custom instance of DeprecatedServiceSettings to
- * create(). For example:
- *
- *
Please refer to the GitHub repository's samples for more quickstart code snippets.
- *
- * @deprecated This class is deprecated and will be removed in the next major version update.
- */
-@Deprecated
+@BetaApi
@Generated("by gapic-generator-java")
-public class DeprecatedServiceClient implements BackgroundResource {
- private final DeprecatedServiceSettings settings;
- private final DeprecatedServiceStub stub;
+public class MockDeprecatedService implements MockGrpcService {
+ private final MockDeprecatedServiceImpl serviceImpl;
- /** Constructs an instance of DeprecatedServiceClient with default settings. */
- public static final DeprecatedServiceClient create() throws IOException {
- return create(DeprecatedServiceSettings.newBuilder().build());
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. The channels are
- * created based on the settings passed in, or defaults for any settings that are not set.
- */
- public static final DeprecatedServiceClient create(DeprecatedServiceSettings settings)
- throws IOException {
- return new DeprecatedServiceClient(settings);
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given stub for making calls. This
- * is for advanced usage - prefer using create(DeprecatedServiceSettings).
- */
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public static final DeprecatedServiceClient create(DeprecatedServiceStub stub) {
- return new DeprecatedServiceClient(stub);
- }
-
- /**
- * Constructs an instance of DeprecatedServiceClient, using the given settings. This is protected
- * so that it is easy to make a subclass, but otherwise, the static factory methods should be
- * preferred.
- */
- protected DeprecatedServiceClient(DeprecatedServiceSettings settings) throws IOException {
- this.settings = settings;
- this.stub = ((DeprecatedServiceStubSettings) settings.getStubSettings()).createStub();
- }
-
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- protected DeprecatedServiceClient(DeprecatedServiceStub stub) {
- this.settings = null;
- this.stub = stub;
- }
-
- public final DeprecatedServiceSettings getSettings() {
- return settings;
- }
-
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
- public DeprecatedServiceStub getStub() {
- return stub;
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- */
- public final void fastFibonacci(FibonacciRequest request) {
- fastFibonacciCallable().call(request);
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
- *
- * @param request The request object containing all of the parameters for the API call.
- * @throws com.google.api.gax.rpc.ApiException if the remote call fails
- * @deprecated This method is deprecated and will be removed in the next major version update.
- */
- @Deprecated
- public final void slowFibonacci(FibonacciRequest request) {
- slowFibonacciCallable().call(request);
- }
-
- // AUTO-GENERATED DOCUMENTATION AND METHOD.
- /**
- * Sample code:
- *
- *
Note: close() needs to be called on the DeprecatedServiceClient object to clean up resources
- * such as threads. In the example above, try-with-resources is used, which automatically calls
- * close().
- *
- *
The surface of this class includes several types of Java methods for each of the API's
- * methods:
- *
- *
- *
A "flattened" method. With this type of method, the fields of the request type have been
- * converted into function parameters. It may be the case that not all fields are available as
- * parameters, and not every API method will have a flattened method entry point.
- *
A "request object" method. This type of method only takes one parameter, a request object,
- * which must be constructed before the call. Not every API method will have a request object
- * method.
- *
A "callable" method. This type of method takes no parameters and returns an immutable API
- * callable object, which can be used to initiate calls to the service.
- *
- *
- *
See the individual methods for example code.
- *
- *
Many parameters require resource names to be formatted in a particular way. To assist with
- * these names, this class includes a format method for each type of name, and additionally a parse
- * method to extract the individual identifiers contained within names that are returned.
- *
- *
This class can be customized by passing in a custom instance of DeprecatedServiceSettings to
- * create(). For example:
- *
- *
Please refer to the GitHub repository's samples for more quickstart code snippets.
- *
- * @deprecated This class is deprecated and will be removed in the next major version update.
- */
-@Deprecated
+@BetaApi
@Generated("by gapic-generator-java")
-public class DeprecatedServiceClient implements BackgroundResource {
- private final DeprecatedServiceSettings settings;
- private final DeprecatedServiceStub stub;
+public class MockDeprecatedServiceImpl extends DeprecatedServiceImplBase {
+ private List requests;
+ private Queue