Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Changed exception type
Browse files Browse the repository at this point in the history
Changed OperationNotSupportedException to IllegalStateException
Fixed doc errors

Pre-push hook installed.

Change-Id: I33529e918b1e22ce643c03dd46f207a16adfe8ad
  • Loading branch information
michaelbausor committed Apr 26, 2016
1 parent 82ab4a2 commit 0d24ef5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/google/api/gax/grpc/ApiCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final class ApiCallable<RequestT, ResponseT> {
* @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 <RequestT, ResponseT> ApiCallable<RequestT, ResponseT> create(
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/google/api/gax/grpc/ChannelProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
/**
Expand All @@ -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;
}
15 changes: 7 additions & 8 deletions src/main/java/com/google/api/gax/grpc/ExecutorProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
/**
Expand All @@ -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;
}
25 changes: 11 additions & 14 deletions src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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());
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit 0d24ef5

Please sign in to comment.