Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 26d1825

Browse files
authored
feat: Configurable option for compression (#10)
* feat: Enable GZIP compression * configurable option * alphabetic order
1 parent 878906c commit 26d1825

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

s2-sdk/src/main/java/s2/client/StreamClient.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class StreamClient extends BasinClient {
3535
/** Name of stream associated with this client. */
3636
final String streamName;
3737

38+
private static final String compressionCodec = "gzip";
39+
3840
private final StreamServiceFutureStub futureStub;
3941
final StreamServiceStub asyncStub;
4042

@@ -61,14 +63,23 @@ public StreamClient(
6163
var meta = new Metadata();
6264
meta.put(Key.of("s2-basin", Metadata.ASCII_STRING_MARSHALLER), basin);
6365
this.streamName = streamName;
64-
this.futureStub =
66+
67+
StreamServiceFutureStub futureStub =
6568
StreamServiceGrpc.newFutureStub(channel)
6669
.withCallCredentials(new BearerTokenCallCredentials(config.token))
6770
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(meta));
68-
this.asyncStub =
71+
StreamServiceStub asyncStub =
6972
StreamServiceGrpc.newStub(channel)
7073
.withCallCredentials(new BearerTokenCallCredentials(config.token))
7174
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(meta));
75+
76+
if (config.compression) {
77+
futureStub = futureStub.withCompression(compressionCodec);
78+
asyncStub = asyncStub.withCompression(compressionCodec);
79+
}
80+
81+
this.futureStub = futureStub;
82+
this.asyncStub = asyncStub;
7283
}
7384

7485
/**

s2-sdk/src/main/java/s2/config/Config.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
public class Config {
88
public final String token;
99
public final AppendRetryPolicy appendRetryPolicy;
10+
public final Boolean compression;
1011
public final Endpoints endpoints;
1112
public final Integer maxAppendInflightBytes;
1213
public final Integer maxRetries;
@@ -17,6 +18,7 @@ public class Config {
1718
private Config(
1819
String token,
1920
AppendRetryPolicy appendRetryPolicy,
21+
Boolean compression,
2022
Endpoints endpoints,
2123
Integer maxAppendInflightBytes,
2224
Integer maxRetries,
@@ -25,6 +27,7 @@ private Config(
2527
String userAgent) {
2628
this.token = token;
2729
this.appendRetryPolicy = appendRetryPolicy;
30+
this.compression = compression;
2831
this.endpoints = endpoints;
2932
this.maxAppendInflightBytes = maxAppendInflightBytes;
3033
this.maxRetries = maxRetries;
@@ -46,6 +49,7 @@ public static final class ConfigBuilder {
4649
private Optional<Duration> requestTimeout = Optional.empty();
4750
private Optional<Duration> retryDelay = Optional.empty();
4851
private Optional<String> userAgent = Optional.empty();
52+
private Optional<Boolean> compression = Optional.empty();
4953

5054
ConfigBuilder(String token) {
5155
this.token = token;
@@ -56,6 +60,11 @@ public ConfigBuilder withAppendRetryPolicy(AppendRetryPolicy appendRetryPolicy)
5660
return this;
5761
}
5862

63+
public ConfigBuilder withCompression(Boolean compression) {
64+
this.compression = Optional.of(compression);
65+
return this;
66+
}
67+
5968
public ConfigBuilder withEndpoints(Endpoints endpoints) {
6069
this.endpoints = Optional.of(endpoints);
6170
return this;
@@ -91,6 +100,7 @@ public Config build() {
91100
return new Config(
92101
this.token,
93102
this.appendRetryPolicy.orElse(AppendRetryPolicy.ALL),
103+
this.compression.orElse(false),
94104
this.endpoints.orElse(Endpoints.forCloud(Cloud.AWS)),
95105
this.maxAppendInflightBytes.orElse(Integer.MAX_VALUE),
96106
this.maxRetries.orElse(3),

0 commit comments

Comments
 (0)