This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ServiceApiSettings provider interfaces public (#75)
Change Channel and Executor provision Make ChannelProvider, ExecutorProvider and CredentialsProvider interfaces public. This allows the ApiSettings object to be constructed without instantiating the channel, executor or credentials until they are required by the Api object. Use executor for channel Added shouldAutoClose parameter to ExecutorProvider Added IllegalStateException to ExecutorProvider and ChannelProvider when a fixed executor/channel is accessed multiple times.
- Loading branch information
1 parent
496005a
commit 6ba722c
Showing
12 changed files
with
428 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/google/api/gax/core/CredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.google.api.gax.core; | ||
|
||
import com.google.auth.Credentials; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Provides an interface to hold and acquire the credentials that will be used to call the service. | ||
*/ | ||
public interface CredentialsProvider { | ||
/** | ||
* Gets the credentials which will be used to call the service. If the credentials have not been | ||
* acquired yet, then they will be acquired when this function is called. | ||
*/ | ||
Credentials getCredentials() throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/google/api/gax/grpc/ChannelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.google.api.gax.grpc; | ||
|
||
import com.google.api.gax.core.ConnectionSettings; | ||
|
||
import io.grpc.ManagedChannel; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.Executor; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Provides an interface to hold and build the channel that will be used. If the channel does not | ||
* already exist, it will be constructed when {@link #getOrBuildChannel} is called. | ||
* | ||
* Implementations of {@link ChannelProvider} may choose to create a new {@link ManagedChannel} for | ||
* each call to {@link #getOrBuildChannel}, or may return a fixed {@link ManagedChannel} instance. | ||
* In cases 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 #getOrBuildChannel} 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 { | ||
/** | ||
* Connection settings used to build the channel. If a channel is provided directly this will be | ||
* set to null. | ||
*/ | ||
@Nullable | ||
ConnectionSettings connectionSettings(); | ||
|
||
/** | ||
* Indicates whether the channel should be closed by the containing API class. | ||
*/ | ||
boolean shouldAutoClose(); | ||
|
||
/** | ||
* Get the channel to be used to connect to the service. The first time this is called, if the | ||
* channel does not already exist, it will be created. The {@link Executor} will only be used when | ||
* the channel is created. For implementations returning a fixed {@link ManagedChannel} object, | ||
* the executor is unused. | ||
* | ||
* 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 #getOrBuildChannel}, | ||
* subsequent calls should throw an {@link IllegalStateException}. See interface level docs for | ||
* {@link ChannelProvider} for more details. | ||
*/ | ||
ManagedChannel getOrBuildChannel(Executor executor) throws IOException; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/google/api/gax/grpc/ExecutorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.google.api.gax.grpc; | ||
|
||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
* 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 #getOrBuildExecutor} is called. | ||
* | ||
* Implementations of ExecutorProvider may choose to create a new {@link ScheduledExecutorService} | ||
* for each call to {@link #getOrBuildExecutor}, or may return a fixed | ||
* {@link ScheduledExecutorService} 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 #getOrBuildExecutor} 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 { | ||
/** | ||
* Indicates whether the channel should be closed by the containing API class. | ||
*/ | ||
boolean shouldAutoClose(); | ||
|
||
/** | ||
* Get the executor to be used to connect to the service. The first time this is called, if the | ||
* executor does not already exist, it will be created. | ||
* | ||
* 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 #getOrBuildExecutor}, subsequent calls should throw an | ||
* {@link IllegalStateException}. See interface level docs for {@link ExecutorProvider} for more | ||
* details. | ||
*/ | ||
ScheduledExecutorService getOrBuildExecutor(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.