diff --git a/src/main/java/com/google/api/gax/grpc/ApiCallable.java b/src/main/java/com/google/api/gax/grpc/ApiCallable.java index b1069073d..ccbf65ab4 100644 --- a/src/main/java/com/google/api/gax/grpc/ApiCallable.java +++ b/src/main/java/com/google/api/gax/grpc/ApiCallable.java @@ -109,7 +109,7 @@ public final class ApiCallable { * @param simpleCallSettings {@link com.google.api.gax.grpc.SimpleCallSettings} to configure the * method-level settings with. * @param channel {@link ManagedChannel} to use to connect to the service. - * @param executor {@link ScheduledExecutorService} to use to when connecting to the service. + * @param executor {@link ScheduledExecutorService} to use when connecting to the service. * @return {@link com.google.api.gax.grpc.ApiCallable} callable object. */ public static ApiCallable create( diff --git a/src/main/java/com/google/api/gax/grpc/ChannelProvider.java b/src/main/java/com/google/api/gax/grpc/ChannelProvider.java index 23daa349e..3b0020e47 100644 --- a/src/main/java/com/google/api/gax/grpc/ChannelProvider.java +++ b/src/main/java/com/google/api/gax/grpc/ChannelProvider.java @@ -8,7 +8,6 @@ import java.util.concurrent.Executor; import javax.annotation.Nullable; -import javax.naming.OperationNotSupportedException; /** * Provides an interface to hold and build the channel that will be used. If the channel does not @@ -19,9 +18,9 @@ * where the same {@link ManagedChannel} instance is returned, for example by a * {@link ChannelProvider} created using the {@link ServiceApiSettings} * provideChannelWith(ManagedChannel, boolean) method, and shouldAutoClose returns true, the - * {@link #getChannel} method will throw an {@link OperationNotSupportedException} if it is called - * more than once. This is to prevent the same {@link ManagedChannel} being closed prematurely when - * it is used by multiple client objects. + * {@link #getChannel} method will throw an {@link IllegalStateException} if it is called more than + * once. This is to prevent the same {@link ManagedChannel} being closed prematurely when it is used + * by multiple client objects. */ public interface ChannelProvider { /** @@ -42,8 +41,8 @@ public interface ChannelProvider { * * If the {@link ChannelProvider} is configured to return a fixed {@link ManagedChannel} object * and to return shouldAutoClose as true, then after the first call to {@link #getChannel}, - * subsequent calls should throw an {@link OperationNotSupportedException}. See interface level - * docs for {@link ChannelProvider} for more details. + * subsequent calls should throw an {@link IllegalStateException}. See interface level docs for + * {@link ChannelProvider} for more details. */ - ManagedChannel getChannel(Executor executor) throws IOException, OperationNotSupportedException; + ManagedChannel getChannel(Executor executor) throws IOException, IllegalStateException; } diff --git a/src/main/java/com/google/api/gax/grpc/ExecutorProvider.java b/src/main/java/com/google/api/gax/grpc/ExecutorProvider.java index 5a26a5133..03d4ce054 100644 --- a/src/main/java/com/google/api/gax/grpc/ExecutorProvider.java +++ b/src/main/java/com/google/api/gax/grpc/ExecutorProvider.java @@ -2,8 +2,6 @@ import java.util.concurrent.ScheduledExecutorService; -import javax.naming.OperationNotSupportedException; - /** * Provides an interface to hold and create the Executor to be used. If the executor does not * already exist, it will be constructed when {@link #getExecutor} is called. @@ -13,9 +11,9 @@ * instance. In cases where the same {@link ScheduledExecutorService} instance is returned, for * example by an {@link ExecutorProvider} created using the {@link ServiceApiSettings} * provideExecutorWith(ScheduledExecutorService, boolean) method, and shouldAutoClose returns true, - * the {@link #getExecutor} method will throw an {@link OperationNotSupportedException} if it is - * called more than once. This is to prevent the same {@link ScheduledExecutorService} being closed - * prematurely when it is used by multiple client objects. + * the {@link #getExecutor} method will throw an {@link IllegalStateException} if it is called more + * than once. This is to prevent the same {@link ScheduledExecutorService} being closed prematurely + * when it is used by multiple client objects. */ public interface ExecutorProvider { /** @@ -29,8 +27,9 @@ public interface ExecutorProvider { * * If the {@link ExecutorProvider} is configured to return a fixed * {@link ScheduledExecutorService} object and to return shouldAutoClose as true, then after the - * first call to {@link #getExecutor}, subsequent calls should throw an {@link ExecutorProvider}. - * See interface level docs for {@link ExecutorProvider} for more details. + * first call to {@link #getExecutor}, subsequent calls should throw an + * {@link IllegalStateException}. See interface level docs for {@link ExecutorProvider} for more + * details. */ - ScheduledExecutorService getExecutor() throws OperationNotSupportedException; + ScheduledExecutorService getExecutor() throws IllegalStateException; } diff --git a/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java b/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java index 5c200ea24..a13a19ce1 100644 --- a/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java +++ b/src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java @@ -19,8 +19,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; -import javax.naming.OperationNotSupportedException; - /** * A base settings class to configure a service API class. * @@ -81,8 +79,7 @@ protected ServiceApiSettings( * Return the channel to be used to connect to the service, retrieved using the channelProvider. * If no channel was set, a default channel will be instantiated. */ - public final ManagedChannel getOrBuildChannel() - throws IOException, OperationNotSupportedException { + public final ManagedChannel getOrBuildChannel() throws IOException, IllegalStateException { return getChannelProvider().getChannel(getOrBuildExecutor()); } @@ -98,7 +95,7 @@ public final ChannelProvider getChannelProvider() { * The Executor used for channels, retries, and bundling, retrieved using the executorProvider. If * no executor was set, a default executor will be instantiated. */ - public final ScheduledExecutorService getOrBuildExecutor() throws OperationNotSupportedException { + public final ScheduledExecutorService getOrBuildExecutor() throws IllegalStateException { return getExecutorProvider().getExecutor(); } @@ -170,23 +167,23 @@ public boolean shouldAutoClose() { * Sets the executor to use for channels, retries, and bundling. * * If multiple Api objects will use this executor, shouldAutoClose must be set to false to - * prevent the ExecutorProvider from throwing an OperationNotSupportedException. See + * prevent the {@link ExecutorProvider} from throwing an {@link IllegalStateException}. See * {@link ExecutorProvider} for more details. */ public Builder provideExecutorWith( final ScheduledExecutorService executor, final boolean shouldAutoClose) { executorProvider = new ExecutorProvider() { - private boolean executorProvided = false; + private volatile boolean executorProvided = false; @Override - public ScheduledExecutorService getExecutor() throws OperationNotSupportedException { + public ScheduledExecutorService getExecutor() throws IllegalStateException { if (executorProvided) { if (shouldAutoClose) { - throw new OperationNotSupportedException( + throw new IllegalStateException( "A fixed executor cannot be re-used when shouldAutoClose is set to true. " - + "Try calling provideExecutorWith with shouldAutoClose set to false, or " - + "using a channel created from a ConnectionSettings object."); + + "Try calling provideExecutorWith with shouldAutoClose set to false " + + "or using the default executor."); } } else { executorProvided = true; @@ -209,7 +206,7 @@ public boolean shouldAutoClose() { * See class documentation for more details on channels. * * If multiple Api objects will use this channel, shouldAutoClose must be set to false to - * prevent the ChannelProvider from throwing an OperationNotSupportedException. See + * prevent the {@link ChannelProvider} from throwing an {@link IllegalStateException}. See * {@link ChannelProvider} for more details. */ public Builder provideChannelWith(final ManagedChannel channel, final boolean shouldAutoClose) { @@ -340,10 +337,10 @@ private ChannelProvider createChannelProvider(final ManagedChannel channel, private boolean channelProvided = false; @Override - public ManagedChannel getChannel(Executor executor) throws OperationNotSupportedException { + public ManagedChannel getChannel(Executor executor) throws IllegalStateException { if (channelProvided) { if (shouldAutoClose) { - throw new OperationNotSupportedException( + throw new IllegalStateException( "A fixed channel cannot be re-used when shouldAutoClose is set to true. " + "Try calling provideChannelWith with shouldAutoClose set to false, or " + "using a channel created from a ConnectionSettings object.");