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 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java surface refactoring on GAX - Settings classes (ApiCallSettings, ServiceApiSettings) are converted from mutable classes to immutable classes with builders. - The builders in ApiCallable become builders in individual top-level settings classes. - ServiceApiSettings.allCallSettings removed, replaced with applyToAllMethods(ApiCallSettings.Builder) - Renamed getChannel (now in ServiceApiSettings.Builder) to getOrBuildChannel; also getExecutor -> getOrBuildExecutor - Rename RetryParams to RetrySettings for consistency.
- Loading branch information
Showing
10 changed files
with
757 additions
and
434 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
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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/google/api/gax/grpc/ApiCallSettingsTyped.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,71 @@ | ||
package com.google.api.gax.grpc; | ||
|
||
import com.google.api.gax.core.RetrySettings; | ||
import com.google.common.collect.ImmutableSet; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.MethodDescriptor; | ||
import io.grpc.Status; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
/** | ||
* Package-private: Use other concrete settings classes instead of this class from outside of | ||
* the package. | ||
* A settings class with generic typing which can be used to configure an API method or create | ||
* the method callable object. This class can be used as the base class that other concrete | ||
* call settings classes inherit from. | ||
*/ | ||
class ApiCallSettingsTyped<RequestT, ResponseT> extends ApiCallSettings { | ||
|
||
private final MethodDescriptor<RequestT, ResponseT> methodDescriptor; | ||
|
||
public MethodDescriptor<RequestT, ResponseT> getMethodDescriptor() { | ||
return methodDescriptor; | ||
} | ||
|
||
protected ApiCallSettingsTyped(ImmutableSet<Status.Code> retryableCodes, | ||
RetrySettings retrySettings, | ||
MethodDescriptor<RequestT, ResponseT> methodDescriptor) { | ||
super(retryableCodes, retrySettings); | ||
this.methodDescriptor = methodDescriptor; | ||
} | ||
|
||
protected ApiCallable<RequestT, ResponseT> createBaseCallable( | ||
ServiceApiSettings.Builder serviceSettingsBuilder) throws IOException { | ||
ClientCallFactory<RequestT, ResponseT> clientCallFactory = | ||
new DescriptorClientCallFactory<>(methodDescriptor); | ||
ApiCallable<RequestT, ResponseT> callable = | ||
new ApiCallable<>(new DirectCallable<>(clientCallFactory), this); | ||
ManagedChannel channel = serviceSettingsBuilder.getOrBuildChannel(); | ||
ScheduledExecutorService executor = serviceSettingsBuilder.getOrBuildExecutor(); | ||
if (getRetryableCodes() != null) { | ||
callable = callable.retryableOn(ImmutableSet.copyOf(getRetryableCodes())); | ||
} | ||
if (getRetrySettings() != null) { | ||
callable = callable.retrying(getRetrySettings(), executor); | ||
} | ||
return callable.bind(channel); | ||
} | ||
|
||
public static class Builder<RequestT, ResponseT> extends ApiCallSettings.Builder { | ||
private MethodDescriptor<RequestT, ResponseT> grpcMethodDescriptor; | ||
|
||
public Builder(MethodDescriptor<RequestT, ResponseT> grpcMethodDescriptor) { | ||
this.grpcMethodDescriptor = grpcMethodDescriptor; | ||
} | ||
|
||
public MethodDescriptor<RequestT, ResponseT> getMethodDescriptor() { | ||
return grpcMethodDescriptor; | ||
} | ||
|
||
@Override | ||
public ApiCallSettingsTyped<RequestT, ResponseT> build() { | ||
return new ApiCallSettingsTyped<RequestT, ResponseT>( | ||
ImmutableSet.<Status.Code>copyOf(getRetryableCodes()), | ||
getRetrySettingsBuilder().build(), | ||
grpcMethodDescriptor); | ||
} | ||
} | ||
} |
Oops, something went wrong.