Skip to content

Commit

Permalink
fix: visibility, code ordering (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgbalogh authored Jan 31, 2025
1 parent ff9b6c6 commit 878906c
Show file tree
Hide file tree
Showing 63 changed files with 90 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ jobs:
git checkout gh-pages
git pull origin gh-pages
mkdir -p "javadocs/s2/${VERSION}"
cp -r s2/build/docs/javadoc/* "javadocs/s2/${VERSION}"
mkdir -p "javadocs/s2-sdk/${VERSION}"
cp -r s2-sdk/build/docs/javadoc/* "javadocs/s2-sdk/${VERSION}"
mkdir -p "javadocs/s2-internal/${VERSION}"
cp -r s2-internal/build/docs/javadoc/* "javadocs/s2-internal/${VERSION}"
git add "javadocs/s2/${VERSION}"
git add "javadocs/s2-sdk/${VERSION}"
git add "javadocs/s2-internal/${VERSION}"
git commit -m "Add JavaDoc for version ${VERSION}" || echo "No changes to commit"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ A Java SDK for interacting with the S2 streaming service.

#### Current Java API Documentation

- [s2 @ 0.0.11](https://s2-streamstore.github.io/s2-sdk-java/javadocs/s2/0.0.11/)
- [s2-internal @ 0.0.11](https://s2-streamstore.github.io/s2-sdk-java/javadocs/s2-internal/0.0.11/)
- [s2-sdk @ 0.0.12](https://s2-streamstore.github.io/s2-sdk-java/javadocs/s2-sdk/0.0.12/)
- [s2-internal @ 0.0.12](https://s2-streamstore.github.io/s2-sdk-java/javadocs/s2-internal/0.0.12/)

## Prerequisites

Expand Down Expand Up @@ -82,7 +82,7 @@ dependencies {

## Project Structure

- `s2/` - The main SDK module.
- `s2-sdk/` - The main SDK module.
- `s2-internal/` - Code and types generated from
the [S2 protobuf definitions](https://github.com/s2-streamstore/s2-protos).
- `app/` - Example application demonstrating SDK usage.
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
val grpcVersion = "1.64.0"

dependencies {
implementation(project(":s2"))
implementation(project(":s2-sdk"))
implementation("io.grpc:grpc-protobuf:$grpcVersion")
implementation("io.grpc:grpc-stub:$grpcVersion")
implementation("javax.annotation:javax.annotation-api:1.3.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void main(String[] args) throws Exception {
.withRecords(
List.of(
AppendRecord.newBuilder()
.withBytes(payload.getBytes(StandardCharsets.UTF_8))
.withBody(payload.getBytes(StandardCharsets.UTF_8))
.build()))
.build(),
// Duration is how long we are willing to wait to receive a future.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.0.11
version=0.0.12
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Objects;

public abstract sealed class BasinEndpoint permits ParentZone, Direct {
final Address address;
public final Address address;

BasinEndpoint(Address address) {
this.address = address;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@

public class Config {
public final String token;
public final AppendRetryPolicy appendRetryPolicy;
public final Endpoints endpoints;
public final String userAgent;
public final Integer maxAppendInflightBytes;
public final Integer maxRetries;
public final Duration retryDelay;
public final Duration requestTimeout;
public final AppendRetryPolicy appendRetryPolicy;
public final Integer maxAppendInflightBytes;
public final Duration retryDelay;
public final String userAgent;

private Config(
String token,
AppendRetryPolicy appendRetryPolicy,
Endpoints endpoints,
String userAgent,
Integer maxAppendInflightBytes,
Integer maxRetries,
Duration retryDelay,
Duration requestTimeout,
AppendRetryPolicy appendRetryPolicy,
Integer maxAppendInflightBytes) {
Duration retryDelay,
String userAgent) {
this.token = token;
this.appendRetryPolicy = appendRetryPolicy;
this.endpoints = endpoints;
this.userAgent = userAgent;
this.maxAppendInflightBytes = maxAppendInflightBytes;
this.maxRetries = maxRetries;
this.retryDelay = retryDelay;
this.requestTimeout = requestTimeout;
this.appendRetryPolicy = appendRetryPolicy;
this.maxAppendInflightBytes = maxAppendInflightBytes;
this.retryDelay = retryDelay;
this.userAgent = userAgent;
}

public static ConfigBuilder newBuilder(String token) {
Expand All @@ -39,64 +39,64 @@ public static ConfigBuilder newBuilder(String token) {

public static final class ConfigBuilder {
private final String token;
private Optional<String> userAgent = Optional.empty();
private Optional<AppendRetryPolicy> appendRetryPolicy = Optional.empty();
private Optional<Endpoints> endpoints = Optional.empty();
private Optional<Duration> requestTimeout = Optional.empty();
private Optional<Integer> maxAppendInflightBytes = Optional.empty();
private Optional<Integer> maxRetries = Optional.empty();
private Optional<Duration> requestTimeout = Optional.empty();
private Optional<Duration> retryDelay = Optional.empty();
private Optional<AppendRetryPolicy> appendRetryPolicy = Optional.empty();
private Optional<Integer> maxAppendInflightBytes = Optional.empty();
private Optional<String> userAgent = Optional.empty();

ConfigBuilder(String token) {
this.token = token;
}

public ConfigBuilder withUserAgent(String userAgent) {
this.userAgent = Optional.of(userAgent);
public ConfigBuilder withAppendRetryPolicy(AppendRetryPolicy appendRetryPolicy) {
this.appendRetryPolicy = Optional.of(appendRetryPolicy);
return this;
}

public ConfigBuilder withRequestTimeout(long timeout, TemporalUnit unit) {
this.requestTimeout = Optional.of(Duration.of(timeout, unit));
public ConfigBuilder withEndpoints(Endpoints endpoints) {
this.endpoints = Optional.of(endpoints);
return this;
}

public ConfigBuilder withMaxRetries(int retries) {
this.maxRetries = Optional.of(retries);
public ConfigBuilder withMaxAppendInflightBytes(int maxAppendInflightBytes) {
this.maxAppendInflightBytes = Optional.of(maxAppendInflightBytes);
return this;
}

public ConfigBuilder withRetryDelay(Duration delay) {
this.retryDelay = Optional.of(delay);
public ConfigBuilder withMaxRetries(int retries) {
this.maxRetries = Optional.of(retries);
return this;
}

public ConfigBuilder withEndpoints(Endpoints endpoints) {
this.endpoints = Optional.of(endpoints);
public ConfigBuilder withRequestTimeout(long timeout, TemporalUnit unit) {
this.requestTimeout = Optional.of(Duration.of(timeout, unit));
return this;
}

public ConfigBuilder withAppendRetryPolicy(AppendRetryPolicy appendRetryPolicy) {
this.appendRetryPolicy = Optional.of(appendRetryPolicy);
public ConfigBuilder withRetryDelay(Duration delay) {
this.retryDelay = Optional.of(delay);
return this;
}

public ConfigBuilder withMaxAppendInflightBytes(int maxAppendInflightBytes) {
this.maxAppendInflightBytes = Optional.of(maxAppendInflightBytes);
public ConfigBuilder withUserAgent(String userAgent) {
this.userAgent = Optional.of(userAgent);
return this;
}

public Config build() {
validate();
return new Config(
this.token,
this.appendRetryPolicy.orElse(AppendRetryPolicy.ALL),
this.endpoints.orElse(Endpoints.forCloud(Cloud.AWS)),
this.userAgent.orElse("s2-sdk-java"),
this.maxAppendInflightBytes.orElse(Integer.MAX_VALUE),
this.maxRetries.orElse(3),
this.retryDelay.orElse(Duration.ofMillis(50)),
this.requestTimeout.orElse(Duration.ofSeconds(10)),
this.appendRetryPolicy.orElse(AppendRetryPolicy.ALL),
this.maxAppendInflightBytes.orElse(Integer.MAX_VALUE));
this.retryDelay.orElse(Duration.ofMillis(50)),
this.userAgent.orElse("s2-sdk-java"));
}

private void validate() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.Duration;

public final class Age extends RetentionPolicy {
final Duration age;
public final Duration age;

public Age(Duration age) {
this.age = age;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,57 @@

public class AppendRecord implements MeteredBytes, Serializable {

private final List<Header> headers;
private final byte[] bytes;
public final List<Header> headers;
public final ByteString body;

// Private constructor to prevent direct instantiation
private AppendRecord(List<Header> headers, byte[] bytes) {
private AppendRecord(List<Header> headers, ByteString body) {
this.headers = headers;
this.bytes = bytes;
this.body = body;
}

// Factory method to create a builder
public static AppendRecordBuilder newBuilder() {
return new AppendRecordBuilder();
}

public List<Header> getHeaders() {
return headers;
}

public byte[] getBytes() {
return bytes;
}

@Override
public long meteredBytes() {
return 8
+ (2L * this.headers.size())
+ this.headers.stream().map(h -> h.name().size() + h.value().size()).reduce(0, Integer::sum)
+ this.bytes.length;
+ this.body.size();
}

public s2.v1alpha.AppendRecord toProto() {
return s2.v1alpha.AppendRecord.newBuilder()
.addAllHeaders(() -> this.headers.stream().map(Header::toProto).iterator())
.setBody(ByteString.copyFrom(this.bytes))
.setBody(this.body)
.build();
}

// Builder class for constructing AppendRecord
public static class AppendRecordBuilder {
private Optional<List<Header>> headers = Optional.empty();
private Optional<byte[]> bytes = Optional.empty();
private Optional<ByteString> body = Optional.empty();

// Set the headers with validation (if needed)
public AppendRecordBuilder withHeaders(List<Header> headers) {
this.headers = Optional.of(new ArrayList<>(headers));
return this;
}

// Set the bytes with validation (if needed)
public AppendRecordBuilder withBytes(byte[] bytes) {
this.bytes = Optional.of(bytes);
public AppendRecordBuilder withBody(byte[] body) {
this.body = Optional.of(ByteString.copyFrom(body));
return this;
}

public AppendRecordBuilder withBody(ByteString body) {
this.body = Optional.of(body);
return this;
}

// Build the AppendRecord with optional validation before returning
public AppendRecord build() {
List<Header> validatedHeaders = headers.orElse(new ArrayList<>());
byte[] validatedBytes = bytes.orElse(new byte[0]);
ByteString validatedBody = body.orElse(ByteString.EMPTY);

// Example validation: check that the headers are not empty or that bytes are not empty
var provisional = new AppendRecord(validatedHeaders, validatedBytes);
var provisional = new AppendRecord(validatedHeaders, validatedBody);
var meteredBytes = provisional.meteredBytes();
if (meteredBytes > 1024 * 1024) {
throw new IllegalStateException(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

public record Batch(SequencedRecordBatch sequencedRecordBatch) implements ReadOutput, MeteredBytes {

public Optional<Long> firstSeqNum() {
return this.sequencedRecordBatch.records().stream().findFirst().map(SequencedRecord::seqNum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class CreateBasinRequest {

final Optional<String> basin;
final BasinConfig config;
final Optional<BasinAssignment> assignment;
public final Optional<String> basin;
public final BasinConfig config;
public final Optional<BasinAssignment> assignment;

private CreateBasinRequest(
Optional<String> basin, BasinConfig config, Optional<BasinAssignment> assignment) {
Expand All @@ -27,22 +27,20 @@ public s2.v1alpha.CreateBasinRequest toProto() {
}

abstract static sealed class BasinAssignment permits Scope, Cell {
final String value;
public final String value;

BasinAssignment(String value) {
this.value = value;
}
}

static final class Scope extends BasinAssignment {

Scope(String value) {
super(value);
}
}

static final class Cell extends BasinAssignment {

Cell(String value) {
super(value);
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.Optional;

public class ListBasinsRequest {
final String prefix;
final String startAfter;
final Optional<Integer> limit;
public final String prefix;
public final String startAfter;
public final Optional<Integer> limit;

ListBasinsRequest(String prefix, String startAfter, Optional<Integer> limit) {
this.prefix = prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.util.Optional;

public class ListStreamsRequest {
final String prefix;
final String startAfter;
final Optional<Integer> limit;
public final String prefix;
public final String startAfter;
public final Optional<Integer> limit;

ListStreamsRequest(String prefix, String startAfter, Optional<Integer> limit) {
this.prefix = prefix;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class ReadLimit {

public static final ReadLimit NONE = new ReadLimit(Optional.empty(), Optional.empty());

public final Optional<Long> count;
public final Optional<Long> bytes;

Expand All @@ -13,10 +14,9 @@ private ReadLimit(Optional<Long> count, Optional<Long> bytes) {
this.bytes = bytes;
}

// Static factory methods for different ways to instantiate ReadLimit
public static ReadLimit count(long count) {
if (count < 0) {
throw new IllegalArgumentException("Bytes must be positive");
throw new IllegalArgumentException("Count must be positive");
}
return new ReadLimit(Optional.of(count), Optional.empty());
}
Expand All @@ -33,7 +33,7 @@ public static ReadLimit countOrBytes(long count, long bytes) {
throw new IllegalArgumentException("Bytes must be positive");
}
if (count < 0) {
throw new IllegalArgumentException("Bytes must be positive");
throw new IllegalArgumentException("Count must be positive");
}
return new ReadLimit(Optional.of(count), Optional.of(bytes));
}
Expand Down
File renamed without changes.
Loading

0 comments on commit 878906c

Please sign in to comment.