Skip to content

Commit 39b3f9a

Browse files
Sync hybrid: clean up and fix docs
1 parent baec971 commit 39b3f9a

File tree

3 files changed

+48
-33
lines changed

3 files changed

+48
-33
lines changed

objectbox-java/src/main/java/io/objectbox/sync/Sync.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,23 @@ public static SyncServerBuilder server(BoxStore boxStore, String url, SyncCreden
8181
}
8282

8383
/**
84-
* Starts building a {@link SyncHybridBuilder}, a client/server hybrid typically used for embedded cluster setups.
85-
* <p/>
84+
* Starts building a {@link SyncHybrid}, a client/server hybrid typically used for embedded cluster setups.
85+
* <p>
8686
* Unlike {@link #client(BoxStore, String, SyncCredentials)} and {@link #server(BoxStore, String, SyncCredentials)},
87-
* you cannot pass in an already built store. Instead, you must pass in the store builder.
88-
* The store will be created internally when calling this method.
89-
* <p/>
90-
* As this is a hybrid, you can configure client and server aspects using the {@link SyncHybridBuilder}.
87+
* the client Store is not built before. Instead, a Store builder must be passed. The client and server Store will
88+
* be built internally when calling this method.
89+
* <p>
90+
* To configure client and server use the methods on {@link SyncHybridBuilder}.
9191
*
92-
* @param storeBuilder the BoxStoreBuilder to use for building the main store.
92+
* @param storeBuilder The {@link BoxStoreBuilder} to use for building the client store.
9393
* @param url The URL of the Sync server on which the Sync protocol is exposed. This is typically a WebSockets URL
9494
* starting with {@code ws://} or {@code wss://} (for encrypted connections), for example
9595
* {@code ws://0.0.0.0:9999}.
96-
* @param authenticatorCredentials A list of enabled authentication methods available to Sync clients. Additional
97-
* authenticator credentials can be supplied using the builder. For the embedded server, currently only
98-
* {@link SyncCredentials#sharedSecret} and {@link SyncCredentials#none} are supported.
99-
* @return an instance of SyncHybridBuilder.
96+
* @param authenticatorCredentials An authentication method available to Sync clients and peers. The client of the
97+
* hybrid is pre-configured with them. Additional credentials can be supplied using the client and server builder of
98+
* the returned builder. For the embedded server, currently only {@link SyncCredentials#sharedSecret} and
99+
* {@link SyncCredentials#none} are supported.
100+
* @return An instance of {@link SyncHybridBuilder}.
100101
*/
101102
public static SyncHybridBuilder hybrid(BoxStoreBuilder storeBuilder, String url,
102103
SyncCredentials authenticatorCredentials) {

objectbox-java/src/main/java/io/objectbox/sync/SyncHybrid.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
import io.objectbox.sync.server.SyncServer;
2323

2424
/**
25-
* The SyncHybrid combines the functionality of a Sync Client and a Sync Server.
25+
* Combines the functionality of a Sync client and a Sync server.
26+
* <p>
2627
* It is typically used in local cluster setups, in which a "hybrid" functions as a client & cluster peer (server).
27-
* <p/>
28-
* Call {@link #getStore()} to retrieve the store.
29-
* To set sync listeners use the {@link SyncClient} that is available from {@link #getClient()}.
30-
* <p/>
31-
* This class implements the Closeable interface, ensuring that resources are cleaned up properly.
28+
* <p>
29+
* Call {@link #getStore()} to retrieve the store. To set sync listeners use the {@link SyncClient} that is available
30+
* from {@link #getClient()}.
31+
* <p>
32+
* This class implements the {@link Closeable} interface, ensuring that resources are cleaned up properly.
3233
*/
3334
public final class SyncHybrid implements Closeable {
3435
private BoxStore store;
@@ -48,39 +49,50 @@ public BoxStore getStore() {
4849
}
4950

5051
/**
51-
* Typically only used to set sync listeners.
52-
* <p/>
53-
* Note: you should not directly call start(), stop(), close() on the {@link SyncClient} directly.
54-
* Instead, call {@link #stop()} or {@link #close()} on this instance (it is already started during creation).
52+
* Returns the {@link SyncClient} of this hybrid, typically only to set Sync listeners.
53+
* <p>
54+
* Note: do not stop or close the client directly. Instead, use the {@link #stop()} and {@link #close()} methods of
55+
* this hybrid.
5556
*/
5657
public SyncClient getClient() {
5758
return client;
5859
}
5960

6061
/**
61-
* Typically, you won't need access to the SyncServer.
62-
* It is still exposed for advanced use cases if you know what you are doing.
63-
* <p/>
64-
* Note: you should not directly call start(), stop(), close() on the {@link SyncServer} directly.
65-
* Instead, call {@link #stop()} or {@link #close()} on this instance (it is already started during creation).
62+
* Returns the {@link SyncServer} of this hybrid.
63+
* <p>
64+
* Typically, the server should not be touched. Yet, it is still exposed for advanced use cases.
65+
* <p>
66+
* Note: do not stop or close the server directly. Instead, use the {@link #stop()} and {@link #close()} methods of
67+
* this hybrid.
6668
*/
6769
public SyncServer getServer() {
6870
return server;
6971
}
7072

73+
/**
74+
* Stops the client and server.
75+
*/
7176
public void stop() {
7277
client.stop();
7378
server.stop();
7479
}
7580

81+
/**
82+
* Closes and cleans up all resources used by this Sync hybrid.
83+
* <p>
84+
* It can no longer be used afterward, build a new one instead.
85+
* <p>
86+
* Does nothing if this has already been closed.
87+
*/
7688
@Override
7789
public void close() {
7890
// Clear reference to boxStore but do not close it (same behavior as SyncClient and SyncServer)
7991
store = null;
8092
client.close();
8193
server.close();
8294
if (storeServer != null) {
83-
storeServer.close(); // The server store is "internal", so we can close it
95+
storeServer.close(); // The server store is "internal", so can safely close it
8496
storeServer = null;
8597
}
8698
}

objectbox-java/src/main/java/io/objectbox/sync/SyncHybridBuilder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import io.objectbox.sync.server.SyncServerBuilder;
2525

2626
/**
27-
* Allows to configure the client and server setup to build a {@link SyncHybrid}.
27+
* Builder for a Sync client and server hybrid setup, a {@link SyncHybrid}.
28+
* <p>
2829
* To change the server/cluster configuration, call {@link #serverBuilder()}, and for the client configuration
2930
* {@link #clientBuilder()}.
3031
*/
@@ -50,26 +51,27 @@ public final class SyncHybridBuilder {
5051
}
5152

5253
/**
53-
* Allows to customize client options of the hybrid.
54+
* Returns the builder of the client of the hybrid for additional configuration.
5455
*/
5556
public SyncBuilder clientBuilder() {
5657
return clientBuilder;
5758
}
5859

5960
/**
60-
* Allows to customize server options of the hybrid.
61+
* Returns the builder of the server of the hybrid for additional configuration.
6162
*/
6263
public SyncServerBuilder serverBuilder() {
6364
return serverBuilder;
6465
}
6566

6667
/**
67-
* Builds, starts and returns a SyncHybrid.
68-
* Note that building and started must be done in one go for hybrids to ensure the correct sequence.
68+
* Builds, starts and returns the hybrid.
69+
* <p>
70+
* Ensures the correct order of starting the server and client.
6971
*/
7072
@SuppressWarnings("resource") // User is responsible for closing
7173
public SyncHybrid buildAndStart() {
72-
// Build and start the server first, we may need to get a port for the client
74+
// Build and start the server first to obtain its URL, the port may have been set to 0 and dynamically assigned
7375
SyncServer server = serverBuilder.buildAndStart();
7476

7577
SyncClient client = clientBuilder

0 commit comments

Comments
 (0)