Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b6df029
build(deps): ditto-java (5.0.0-java-rc.2)
phatblat Dec 1, 2025
1b5f584
refactor: use new DittoException instead of DittoError
phatblat Dec 1, 2025
845d8f3
Update java-server/src/main/java/com/ditto/example/spring/quickstart/…
phatblat Dec 5, 2025
b90112b
Apply suggestion from @Copilot
phatblat Dec 5, 2025
5a50e68
Apply suggestion from @Copilot
phatblat Dec 5, 2025
be4540b
fix(java-server): remove bad copilot suggestions
phatblat Dec 5, 2025
0b15677
feat(java-server): explicitly close all results & observers
phatblat Dec 7, 2025
f2fd7de
refactor(java-server): handle new DittoException type
phatblat Dec 11, 2025
dc05324
feat(java-server): add winsw service config
phatblat Dec 16, 2025
9b6a569
refactor: use new DittoException instead of DittoError
phatblat Dec 1, 2025
27f574a
Update java-server/src/main/java/com/ditto/example/spring/quickstart/…
phatblat Dec 5, 2025
a59ae5a
Apply suggestion from @Copilot
phatblat Dec 5, 2025
7fd6102
Apply suggestion from @Copilot
phatblat Dec 5, 2025
b03b52a
fix(java-server): remove bad copilot suggestions
phatblat Dec 5, 2025
99e5f1f
feat(java-server): explicitly close all results & observers
phatblat Dec 7, 2025
a766759
refactor(java-server): handle new DittoException type
phatblat Dec 11, 2025
49eb30b
refactor: disable custom persistenceDirectory
phatblat Dec 11, 2025
72a9d36
chore(java-server): bump Ditto SDK to 5.0.0-java-rc.3
phatblat Dec 11, 2025
aea81a0
build(deps): ditto 5.0.0-java
phatblat Dec 19, 2025
3c728f9
chore: ignore .claude/
phatblat Dec 12, 2025
ffed2ce
style: handle possible null value from flux flow
phatblat Dec 22, 2025
46855cd
style: use logger instead of printing to stderr
phatblat Dec 22, 2025
bda88db
style: remove unthrown exception
phatblat Dec 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
*.dll
*.hprof
*.iml
*.xccheckout
*.xcscmblueprint
.env
.DS_Store
.build/
.classpath
.claude/
.cxx/
.dart_tool/
.DS_Store
.env
.externalNativeBuild/
.gradle/
.idea/
Expand All @@ -17,20 +14,23 @@
.swiftpm/
.vs/
.vscode/
Carthage/
Pods/
*.dll
*.hprof
*.iml
*.xccheckout
*.xcscmblueprint
bazel-*
bin/
build-cmake
build/
Carthage/
cmake-build-debug/
heapdump.*.phd
javacore.*.txt
local.properties
node_modules/
obj/
bin/
packages/
Pods/
target/
xcuserdata
.env
bazel-*
build-cmake
node_modules/
.dart_tool/
4 changes: 4 additions & 0 deletions java-server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.kotlin/
bin/
build/
ditto-service.err.log
ditto-service.exe
ditto-service.out.log
ditto-service.wrapper.log
10 changes: 5 additions & 5 deletions java-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ spotbugs {

dependencies {
// ditto-java artifact includes the Java API for Ditto
implementation("com.ditto:ditto-java:5.0.0-preview.3")
implementation("com.ditto:ditto-java:5.0.0-java")

// This will include binaries for all the supported platforms and architectures
implementation("com.ditto:ditto-binaries:5.0.0-preview.3")
implementation("com.ditto:ditto-binaries:5.0.0-java")

// To reduce your module artifact's size, consider including just the necessary platforms and architectures
/*
// macOS Apple Silicon
implementation("com.ditto:ditto-binaries:5.0.0-preview.3") {
implementation("com.ditto:ditto-binaries:5.0.0-java") {
capabilities {
requireCapability("com.ditto:ditto-binaries-macos-arm64")
}
}

// Windows x86_64
implementation("com.ditto:ditto-binaries:5.0.0-preview.3") {
implementation("com.ditto:ditto-binaries:5.0.0-java") {
capabilities {
requireCapability("com.ditto:ditto-binaries-windows-x64")
}
}

// Linux x86_64
implementation("com.ditto:ditto-binaries:5.0.0-preview.3") {
implementation("com.ditto:ditto-binaries:5.0.0-java") {
capabilities {
requireCapability("com.ditto:ditto-binaries-linux-x64")
}
Expand Down
24 changes: 24 additions & 0 deletions java-server/ditto-service.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<service>
<id>ditto-service</id>
<name>Ditto Java Quickstart App</name>
<description>Description of your application</description>

<executable>java</executable>
<arguments>-jar "%BASE%\build\libs\quickstart-java-0.0.1-SNAPSHOT.jar"</arguments>

<!-- Optional: Set working directory -->
<workingdirectory>%BASE%</workingdirectory>

<!-- JVM options -->
<env name="JAVA_OPTS" value="-Xmx512m -Xms256m"/>

<!-- Logging -->
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>

<!-- Service restart behavior -->
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
</service>
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class DittoService implements DisposableBean {
* Setup Ditto Config
* https://docs.ditto.live/sdk/latest/install-guides/java#integrating-and-initializing
*/

DittoConfig dittoConfig = new DittoConfig.Builder(DittoSecretsConfiguration.DITTO_APP_ID)
// .persistenceDirectory("/tmp/ditto-quickstart")
.serverConnect(DittoSecretsConfiguration.DITTO_AUTH_URL)
.build();

Expand All @@ -60,7 +60,7 @@ public class DittoService implements DisposableBean {
).thenRun(() -> { })
);

this.ditto.setDeviceName("Spring Java");
this.ditto.setDeviceName("Java");

this.ditto.updateTransportConfig(config -> {
config.connect(connect -> {
Expand Down Expand Up @@ -99,12 +99,8 @@ public Flux<Boolean> getSyncState() {
}

public void toggleSync() {
try {
boolean currentSyncState = mutableSyncStatePublisher.asFlux().blockFirst();
setSyncStateIntoDittoStore(!currentSyncState);
} catch (DittoError e) {
throw new RuntimeException(e);
}
boolean currentSyncState = Boolean.TRUE.equals(mutableSyncStatePublisher.asFlux().blockFirst());
setSyncStateIntoDittoStore(!currentSyncState);
}

private DittoAsyncCancellable observePeersPresence() {
Expand Down Expand Up @@ -145,16 +141,20 @@ private DittoStoreObserver setupAndObserveSyncState() {
(result) -> {
List<? extends DittoQueryResultItem> items = result.getItems();
boolean newSyncState = false;
if (!items.isEmpty()) {
newSyncState = items.get(0).getValue()
.get(DITTO_SYNC_STATE_ID)
.asBoolean();
try {
if (!items.isEmpty()) {
newSyncState = items.get(0).getValue()
.get(DITTO_SYNC_STATE_ID)
.asBoolean();
}
} catch (DittoException e) {
logger.error("Error: {}", String.valueOf(e));
}

if (newSyncState) {
try {
ditto.startSync();
} catch (DittoError e) {
} catch (DittoException e) {
throw new RuntimeException(e);
}
} else {
Expand All @@ -163,12 +163,12 @@ private DittoStoreObserver setupAndObserveSyncState() {

mutableSyncStatePublisher.tryEmitNext(newSyncState);
});
} catch (DittoError e) {
} catch (DittoException e) {
throw new RuntimeException(e);
}
}

private void setSyncStateIntoDittoStore(boolean newState) throws DittoError {
private void setSyncStateIntoDittoStore(boolean newState) {
CompletionStage<DittoQueryResult> future = ditto.getStore().execute(
"UPDATE %s SET %s = :syncState".formatted(DITTO_SYNC_STATE_COLLECTION, DITTO_SYNC_STATE_ID),
DittoCborSerializable.buildDictionary()
Expand All @@ -178,7 +178,7 @@ private void setSyncStateIntoDittoStore(boolean newState) throws DittoError {

try {
future.toCompletableFuture().join().close();
} catch (DittoError e) {
} catch (DittoException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public void toggleTaskDone(@Nonnull String taskId) {
"UPDATE %s SET done = :done WHERE _id = :taskId".formatted(TASKS_COLLECTION_NAME),
DittoCborSerializable.Dictionary.buildDictionary()
.put("done", !isDone)
.put("taskId", taskId)
.put("taskId", taskId)
.build()
).toCompletableFuture().join();
} catch (Error e) {
} catch (Error | DittoException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -115,23 +115,27 @@ public Flux<List<Task>> observeAll() {
}
try {
observer.close();
} catch (DittoError e) {
} catch (DittoException e) {
throw new RuntimeException(e);
}
});
} catch (DittoError e) {
} catch (DittoException e) {
emitter.error(e);
}
}, FluxSink.OverflowStrategy.LATEST);
}

private Task itemToTask(@Nonnull DittoQueryResultItem item) {
DittoCborSerializable.Dictionary value = item.getValue();
return new Task(
value.get("_id").asString(),
value.get("title").asString(),
value.get("done").asBoolean(),
value.get("deleted").asBoolean()
);
try {
return new Task(
value.get("_id").asString(),
value.get("title").asString(),
value.get("done").asBoolean(),
value.get("deleted").asBoolean()
);
} catch (DittoException e) {
throw new RuntimeException(e);
}
}
}
Loading