|
49 | 49 | import com.google.spanner.admin.database.v1.RestoreDatabaseRequest;
|
50 | 50 | import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
|
51 | 51 | import io.grpc.CallCredentials;
|
| 52 | +import io.grpc.CompressorRegistry; |
| 53 | +import io.grpc.ExperimentalApi; |
52 | 54 | import io.grpc.ManagedChannelBuilder;
|
53 | 55 | import java.io.IOException;
|
54 | 56 | import java.net.MalformedURLException;
|
|
58 | 60 | import java.util.Map.Entry;
|
59 | 61 | import java.util.Set;
|
60 | 62 | import javax.annotation.Nonnull;
|
| 63 | +import javax.annotation.Nullable; |
61 | 64 | import org.threeten.bp.Duration;
|
62 | 65 |
|
63 | 66 | /** Options for the Cloud Spanner service. */
|
@@ -104,6 +107,7 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
|
104 | 107 | private final Map<DatabaseId, QueryOptions> mergedQueryOptions;
|
105 | 108 |
|
106 | 109 | private final CallCredentialsProvider callCredentialsProvider;
|
| 110 | +private final String compressorName; |
107 | 111 |
|
108 | 112 | /**
|
109 | 113 | * Interface that can be used to provide {@link CallCredentials} instead of {@link Credentials} to
|
@@ -174,6 +178,7 @@ private SpannerOptions(Builder builder) {
|
174 | 178 | this.mergedQueryOptions = ImmutableMap.copyOf(merged);
|
175 | 179 | }
|
176 | 180 | callCredentialsProvider = builder.callCredentialsProvider;
|
| 181 | +compressorName = builder.compressorName; |
177 | 182 | }
|
178 | 183 |
|
179 | 184 | /**
|
@@ -238,6 +243,7 @@ public static class Builder
|
238 | 243 | private boolean autoThrottleAdministrativeRequests = false;
|
239 | 244 | private Map<DatabaseId, QueryOptions> defaultQueryOptions = new HashMap<>();
|
240 | 245 | private CallCredentialsProvider callCredentialsProvider;
|
| 246 | +private String compressorName; |
241 | 247 | private String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
|
242 | 248 |
|
243 | 249 | private Builder() {
|
@@ -309,6 +315,7 @@ private Builder() {
|
309 | 315 | this.autoThrottleAdministrativeRequests = options.autoThrottleAdministrativeRequests;
|
310 | 316 | this.defaultQueryOptions = options.defaultQueryOptions;
|
311 | 317 | this.callCredentialsProvider = options.callCredentialsProvider;
|
| 318 | +this.compressorName = options.compressorName; |
312 | 319 | this.channelProvider = options.channelProvider;
|
313 | 320 | this.channelConfigurator = options.channelConfigurator;
|
314 | 321 | this.interceptorProvider = options.interceptorProvider;
|
@@ -558,6 +565,28 @@ public Builder setCallCredentialsProvider(CallCredentialsProvider callCredential
|
558 | 565 | return this;
|
559 | 566 | }
|
560 | 567 |
|
| 568 | +/** |
| 569 | +* Sets the compression to use for all gRPC calls. The compressor must be a valid name known in |
| 570 | +* the {@link CompressorRegistry}. |
| 571 | +* |
| 572 | +* <p>Supported values are: |
| 573 | +* |
| 574 | +* <ul> |
| 575 | +* <li>gzip: Enable gzip compression |
| 576 | +* <li>identity: Disable compression |
| 577 | +* <li><code>null</code>: Use default compression |
| 578 | +* </ul> |
| 579 | +*/ |
| 580 | +@ExperimentalApi("https://.com/grpc/grpc-java/issues/1704") |
| 581 | +public Builder setCompressorName(@Nullable String compressorName) { |
| 582 | +Preconditions.checkArgument( |
| 583 | +compressorName == null |
| 584 | +|| CompressorRegistry.getDefaultInstance().lookupCompressor(compressorName) != null, |
| 585 | +String.format("%s is not a known compressor", compressorName)); |
| 586 | +this.compressorName = compressorName; |
| 587 | +return this; |
| 588 | +} |
| 589 | + |
561 | 590 | /**
|
562 | 591 | * Specifying this will allow the client to prefetch up to {@code prefetchChunks} {@code
|
563 | 592 | * PartialResultSet} chunks for each read and query. The data size of each chunk depends on the
|
@@ -690,6 +719,10 @@ public CallCredentialsProvider getCallCredentialsProvider() {
|
690 | 719 | return callCredentialsProvider;
|
691 | 720 | }
|
692 | 721 |
|
| 722 | +public String getCompressorName() { |
| 723 | +return compressorName; |
| 724 | +} |
| 725 | + |
693 | 726 | /** Returns the default query options to use for the specific database. */
|
694 | 727 | public QueryOptions getDefaultQueryOptions(DatabaseId databaseId) {
|
695 | 728 | // Use the specific query options for the database if any have been specified. These have
|
|
0 commit comments