22
22
import io .objectbox .sync .server .SyncServer ;
23
23
24
24
/**
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>
26
27
* 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.
32
33
*/
33
34
public final class SyncHybrid implements Closeable {
34
35
private BoxStore store ;
@@ -48,39 +49,50 @@ public BoxStore getStore() {
48
49
}
49
50
50
51
/**
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 .
55
56
*/
56
57
public SyncClient getClient () {
57
58
return client ;
58
59
}
59
60
60
61
/**
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.
66
68
*/
67
69
public SyncServer getServer () {
68
70
return server ;
69
71
}
70
72
73
+ /**
74
+ * Stops the client and server.
75
+ */
71
76
public void stop () {
72
77
client .stop ();
73
78
server .stop ();
74
79
}
75
80
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
+ */
76
88
@ Override
77
89
public void close () {
78
90
// Clear reference to boxStore but do not close it (same behavior as SyncClient and SyncServer)
79
91
store = null ;
80
92
client .close ();
81
93
server .close ();
82
94
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
84
96
storeServer = null ;
85
97
}
86
98
}
0 commit comments