Skip to content

Commit 8e82229

Browse files
authored
chore: lang version to 11 (#12)
1 parent a352918 commit 8e82229

32 files changed

+356
-149
lines changed

app/src/main/java/org/example/app/AccountDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void main(String[] args) throws Exception {
2626
try (var client = Client.newBuilder(config).build()) {
2727

2828
var basins = client.listBasins(ListBasinsRequest.newBuilder().build()).get();
29-
basins.elems().forEach(basin -> logger.info("basin={}", basin));
29+
basins.elems.forEach(basin -> logger.info("basin={}", basin));
3030

3131
var newBasin =
3232
client

app/src/main/java/org/example/app/BasinDemo.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ public static void main(String[] args) throws Exception {
2222
try (final var basinClient =
2323
BasinClient.newBuilder(config, System.getenv("S2_BASIN")).build()) {
2424
final var streams = basinClient.listStreams(ListStreamsRequest.newBuilder().build()).get();
25-
streams
26-
.elems()
27-
.forEach(
28-
stream -> {
29-
logger.info("stream={}", stream);
30-
});
25+
streams.elems.forEach(
26+
stream -> {
27+
logger.info("stream={}", stream);
28+
});
3129

3230
var newStream =
3331
basinClient

app/src/main/java/org/example/app/ManagedReadSessionDemo.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ public static void main(String[] args) throws Exception {
3333
throw new IllegalStateException("S2_STREAM not set");
3434
}
3535

36-
var config = Config.newBuilder(authToken).withEndpoints(Endpoints.fromEnvironment()).build();
36+
var config =
37+
Config.newBuilder(authToken)
38+
.withEndpoints(Endpoints.fromEnvironment())
39+
.withCompression(true)
40+
.build();
3741

38-
try (final var executor = new ScheduledThreadPoolExecutor(1);
42+
try (final var executor = new ScheduledThreadPoolExecutor(12);
3943
final var channel = ManagedChannelFactory.forBasinOrStreamService(config, basinName)) {
4044

4145
final var streamClient =
@@ -47,7 +51,7 @@ public static void main(String[] args) throws Exception {
4751
try (final var managedSession =
4852
streamClient.managedReadSession(
4953
ReadSessionRequest.newBuilder().withReadLimit(ReadLimit.count(100_000)).build(),
50-
1024 * 1024 * 1024)) {
54+
1024 * 1024 * 1024 * 5)) {
5155

5256
AtomicLong receivedBytes = new AtomicLong();
5357
while (!managedSession.isClosed()) {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.0.13-SNAPSHOT
1+
version=0.0.13

s2-internal/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protobuf {
5454

5555
java {
5656
toolchain {
57-
languageVersion.set(JavaLanguageVersion.of(17))
57+
languageVersion.set(JavaLanguageVersion.of(11))
5858
}
5959
withJavadocJar()
6060
withSourcesJar()

s2-sdk/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tasks.test {
4545

4646
java {
4747
toolchain {
48-
languageVersion.set(JavaLanguageVersion.of(17))
48+
languageVersion.set(JavaLanguageVersion.of(11))
4949
}
5050
withJavadocJar()
5151
withSourcesJar()

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ public Thread newThread(Runnable r) {
5252
}
5353

5454
static boolean retryableStatus(Status status) {
55-
return switch (status.getCode()) {
56-
case UNKNOWN, DEADLINE_EXCEEDED, UNAVAILABLE -> true;
57-
default -> false;
58-
};
55+
switch (status.getCode()) {
56+
case UNKNOWN:
57+
case DEADLINE_EXCEEDED:
58+
case UNAVAILABLE:
59+
return true;
60+
default:
61+
return false;
62+
}
5963
}
6064

6165
public void close() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Optional;
99
import java.util.UUID;
1010
import java.util.concurrent.ScheduledExecutorService;
11+
import java.util.stream.Collectors;
1112
import s2.auth.BearerTokenCallCredentials;
1213
import s2.channel.BasinCompatibleChannel;
1314
import s2.channel.ManagedChannelFactory;
@@ -66,7 +67,9 @@ public ListenableFuture<Paginated<StreamInfo>> listStreams(
6667
resp ->
6768
new Paginated<>(
6869
resp.getHasMore(),
69-
resp.getStreamsList().stream().map(StreamInfo::fromProto).toList()),
70+
resp.getStreamsList().stream()
71+
.map(StreamInfo::fromProto)
72+
.collect(Collectors.toList())),
7073
executor));
7174
}
7275

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Optional;
99
import java.util.UUID;
1010
import java.util.concurrent.ScheduledExecutorService;
11+
import java.util.stream.Collectors;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
1314
import s2.auth.BearerTokenCallCredentials;
@@ -61,7 +62,9 @@ public ListenableFuture<Paginated<BasinInfo>> listBasins(s2.types.ListBasinsRequ
6162
resp ->
6263
new Paginated<>(
6364
resp.getHasMore(),
64-
resp.getBasinsList().stream().map(BasinInfo::fromProto).toList()),
65+
resp.getBasinsList().stream()
66+
.map(BasinInfo::fromProto)
67+
.collect(Collectors.toList())),
6568
executor));
6669
}
6770

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

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,19 @@ record -> {
179179
throw Status.CANCELLED
180180
.withDescription("hit deadline while retransmitting")
181181
.asRuntimeException();
182-
} else if (notification instanceof Ack ack) {
182+
} else if (notification instanceof Ack) {
183+
final Ack ack = (Ack) notification;
183184
this.remainingAttempts.set(this.client.config.maxRetries);
184185
var correspondingInflight = inflightQueue.poll();
185186
if (correspondingInflight == null) {
186187
throw Status.INTERNAL.withDescription("inflight queue is empty").asRuntimeException();
187188
} else {
188189
validate(correspondingInflight, ack.output);
189190
correspondingInflight.callback.set(ack.output);
190-
this.inflightBytes.release(correspondingInflight.meteredBytes.intValue());
191+
this.inflightBytes.release((int) correspondingInflight.meteredBytes);
191192
}
192-
} else if (notification instanceof Error error) {
193+
} else if (notification instanceof Error) {
194+
final Error error = (Error) notification;
193195
throw new RuntimeException(error.throwable);
194196
} else {
195197
throw Status.INTERNAL
@@ -218,7 +220,8 @@ private synchronized Void cleanUp(Status fatal) throws InterruptedException {
218220
// through them and cancel any pending batches via their callback.
219221
while (!notificationQueue.isEmpty()) {
220222
var entry = notificationQueue.poll();
221-
if (entry instanceof Batch batch) {
223+
if (entry instanceof Batch) {
224+
final Batch batch = (Batch) entry;
222225
batch.input.callback.setException(fatal.asRuntimeException());
223226
}
224227
}
@@ -228,7 +231,7 @@ private synchronized Void cleanUp(Status fatal) throws InterruptedException {
228231
}
229232

230233
private void validate(InflightRecord record, AppendOutput output) {
231-
var numRecordsForAcknowledgement = output.endSeqNum() - output.startSeqNum();
234+
var numRecordsForAcknowledgement = output.endSeqNum - output.startSeqNum;
232235
if (numRecordsForAcknowledgement != record.input.records.size()) {
233236
throw Status.INTERNAL
234237
.withDescription(
@@ -287,7 +290,8 @@ public void onCompleted() {
287290
clientObserver.onError(Status.CANCELLED.asRuntimeException());
288291
throw Status.CANCELLED.asRuntimeException();
289292
}
290-
} else if (notification instanceof Batch batch) {
293+
} else if (notification instanceof Batch) {
294+
final Batch batch = (Batch) notification;
291295
logger.debug("notification=BATCH");
292296
if (!inflightQueue.offer(batch.input)) {
293297
throw Status.INTERNAL.asRuntimeException();
@@ -304,7 +308,8 @@ public void onCompleted() {
304308
+ TimeUnit.NANOSECONDS.convert(this.client.config.requestTimeout)));
305309
}
306310

307-
} else if (notification instanceof Ack ack) {
311+
} else if (notification instanceof Ack) {
312+
final Ack ack = (Ack) notification;
308313
logger.debug("notification=ACK");
309314
this.remainingAttempts.set(this.client.config.maxRetries);
310315
var correspondingInflight = inflightQueue.poll();
@@ -313,7 +318,7 @@ public void onCompleted() {
313318
} else {
314319
validate(correspondingInflight, ack.output);
315320
correspondingInflight.callback.set(ack.output);
316-
this.inflightBytes.release(correspondingInflight.meteredBytes.intValue());
321+
this.inflightBytes.release((int) correspondingInflight.meteredBytes);
317322

318323
// Reset the next deadline.
319324
this.nextDeadlineSystemNanos.set(
@@ -323,18 +328,20 @@ public void onCompleted() {
323328
entry.entryNanos
324329
+ TimeUnit.NANOSECONDS.convert(this.client.config.requestTimeout)));
325330
}
326-
} else if (notification instanceof Error error) {
331+
} else if (notification instanceof Error) {
332+
final Error error = (Error) notification;
327333
logger.debug("notification=ERROR");
328334
clientObserver.onError(Status.CANCELLED.asRuntimeException());
329335
throw new RuntimeException(error.throwable);
330336

331-
} else if (notification instanceof ClientClose close) {
337+
} else if (notification instanceof ClientClose) {
338+
final ClientClose close = (ClientClose) notification;
332339
logger.debug("notification=CLIENT_CLOSE,gracefully={}", close.gracefully);
333340
clientObserver.onCompleted();
334341
if (!close.gracefully) {
335342
return null;
336343
}
337-
} else if (notification instanceof ServerClose close) {
344+
} else if (notification instanceof ServerClose) {
338345
logger.debug("notification=SERVER_CLOSE");
339346
if (acceptingAppends.get() || !inflightQueue.isEmpty() || !notificationQueue.isEmpty()) {
340347
throw Status.INTERNAL
@@ -363,25 +370,63 @@ public ListenableFuture<Void> closeGracefully() {
363370
return daemon;
364371
}
365372

366-
sealed interface Notification permits Ack, Batch, ClientClose, Error, ServerClose {}
373+
static class InflightRecord {
374+
final AppendInput input;
375+
final long entryNanos;
376+
final SettableFuture<AppendOutput> callback;
377+
final long meteredBytes;
378+
379+
InflightRecord(
380+
AppendInput input,
381+
long entryNanos,
382+
SettableFuture<AppendOutput> callback,
383+
long meteredBytes) {
384+
this.input = input;
385+
this.entryNanos = entryNanos;
386+
this.callback = callback;
387+
this.meteredBytes = meteredBytes;
388+
}
367389

368-
record InflightRecord(
369-
AppendInput input,
370-
Long entryNanos,
371-
SettableFuture<AppendOutput> callback,
372-
Long meteredBytes) {
373390
static InflightRecord construct(AppendInput input, Long meteredBytes) {
374391
return new InflightRecord(input, System.nanoTime(), SettableFuture.create(), meteredBytes);
375392
}
376393
}
377394

378-
record Batch(InflightRecord input) implements Notification {}
395+
interface Notification {}
396+
397+
class Ack implements Notification {
398+
final AppendOutput output;
399+
400+
Ack(AppendOutput output) {
401+
this.output = output;
402+
}
403+
}
379404

380-
record Ack(AppendOutput output) implements Notification {}
405+
class Batch implements Notification {
406+
final InflightRecord input;
381407

382-
record Error(Throwable throwable) implements Notification {}
408+
Batch(InflightRecord input) {
409+
this.input = input;
410+
}
411+
}
383412

384-
record ClientClose(boolean gracefully) implements Notification {}
413+
class ClientClose implements Notification {
414+
final boolean gracefully;
385415

386-
record ServerClose() implements Notification {}
416+
ClientClose(boolean gracefully) {
417+
this.gracefully = gracefully;
418+
}
419+
}
420+
421+
class Error implements Notification {
422+
final Throwable throwable;
423+
424+
Error(Throwable throwable) {
425+
this.throwable = throwable;
426+
}
427+
}
428+
429+
class ServerClose implements Notification {
430+
ServerClose() {}
431+
}
387432
}

0 commit comments

Comments
 (0)