28
28
import io .objectbox .sync .Sync ;
29
29
import io .objectbox .sync .SyncCredentials ;
30
30
import io .objectbox .sync .SyncCredentialsToken ;
31
+ import io .objectbox .sync .SyncFlags ;
31
32
import io .objectbox .sync .listener .SyncChangeListener ;
32
33
33
34
/**
@@ -46,6 +47,11 @@ public class SyncServerBuilder {
46
47
private @ Nullable String clusterId ;
47
48
private final List <ClusterPeerInfo > clusterPeers = new ArrayList <>();
48
49
private int clusterFlags ;
50
+ private long historySizeMaxKb ;
51
+ private long historySizeTargetKb ;
52
+ private int syncFlags ;
53
+ private int syncServerFlags ;
54
+ private int workerThreads ;
49
55
50
56
/**
51
57
* Use {@link Sync#server(BoxStore, String, SyncCredentials)} instead.
@@ -107,6 +113,9 @@ public SyncServerBuilder changeListener(SyncChangeListener changeListener) {
107
113
* Enables cluster mode (requires the Cluster feature) and associates this cluster peer with the given ID.
108
114
* <p>
109
115
* Cluster peers need to share the same ID to be in the same cluster.
116
+ *
117
+ * @see #clusterPeer(String, SyncCredentials)
118
+ * @see #clusterFlags(int)
110
119
*/
111
120
public SyncServerBuilder clusterId (String id ) {
112
121
checkNotNull (id , "Cluster ID must not be null" );
@@ -156,6 +165,65 @@ public SyncServerBuilder clusterFlags(int flags) {
156
165
return this ;
157
166
}
158
167
168
+ /**
169
+ * Sets the maximum transaction history size.
170
+ * <p>
171
+ * Once the maximum size is reached, old transaction logs are deleted to stay below this limit. This is sometimes
172
+ * also called "history pruning" in the context of Sync.
173
+ * <p>
174
+ * If not set or set to 0, defaults to no limit.
175
+ *
176
+ * @see #historySizeTargetKb(long)
177
+ */
178
+ public SyncServerBuilder historySizeMaxKb (long historySizeMaxKb ) {
179
+ this .historySizeMaxKb = historySizeMaxKb ;
180
+ return this ;
181
+ }
182
+
183
+ /**
184
+ * Sets the target transaction history size.
185
+ * <p>
186
+ * Once the maximum size ({@link #historySizeMaxKb(long)}) is reached, old transaction logs are deleted until this
187
+ * size target is reached (lower than the maximum size). Using this target size typically lowers the frequency of
188
+ * history pruning and thus may improve efficiency.
189
+ * <p>
190
+ * If not set or set to 0, defaults to {@link #historySizeMaxKb(long)}.
191
+ */
192
+ public SyncServerBuilder historySizeTargetKb (long historySizeTargetKb ) {
193
+ this .historySizeTargetKb = historySizeTargetKb ;
194
+ return this ;
195
+ }
196
+
197
+ /**
198
+ * Sets bit flags to adjust Sync behavior, like additional logging.
199
+ *
200
+ * @param syncFlags One or more of {@link SyncFlags}.
201
+ */
202
+ public SyncServerBuilder syncFlags (int syncFlags ) {
203
+ this .syncFlags = syncFlags ;
204
+ return this ;
205
+ }
206
+
207
+ /**
208
+ * Sets bit flags to configure the Sync server.
209
+ *
210
+ * @param syncServerFlags One or more of {@link SyncServerFlags}.
211
+ */
212
+ public SyncServerBuilder syncServerFlags (int syncServerFlags ) {
213
+ this .syncServerFlags = syncServerFlags ;
214
+ return this ;
215
+ }
216
+
217
+ /**
218
+ * Sets the number of workers for the main task pool.
219
+ * <p>
220
+ * If not set or set to 0, this uses a hardware-dependant default, e.g. 3 * CPU "cores".
221
+ */
222
+ public SyncServerBuilder workerThreads (int workerThreads ) {
223
+ this .workerThreads = workerThreads ;
224
+ return this ;
225
+ }
226
+
159
227
/**
160
228
* Builds and returns a Sync server ready to {@link SyncServer#start()}.
161
229
* <p>
@@ -209,21 +277,28 @@ byte[] buildSyncServerOptions() {
209
277
int authenticationMethodsOffset = buildAuthenticationMethods (fbb );
210
278
int clusterPeersVectorOffset = buildClusterPeers (fbb );
211
279
212
- // TODO Support remaining options
213
280
// After collecting all offsets, create options
214
281
SyncServerOptions .startSyncServerOptions (fbb );
215
282
SyncServerOptions .addUrl (fbb , urlOffset );
216
283
SyncServerOptions .addAuthenticationMethods (fbb , authenticationMethodsOffset );
217
- // SyncServerOptions.addSyncFlags();
218
- // SyncServerOptions.addSyncServerFlags();
284
+ if (syncFlags > 0 ) {
285
+ SyncServerOptions .addSyncFlags (fbb , syncFlags );
286
+ }
287
+ if (syncServerFlags > 0 ) {
288
+ SyncServerOptions .addSyncFlags (fbb , syncServerFlags );
289
+ }
219
290
if (certificatePathOffset > 0 ) {
220
291
SyncServerOptions .addCertificatePath (fbb , certificatePathOffset );
221
292
}
222
- // SyncServerOptions.addWorkerThreads();
223
- // SyncServerOptions.addHistorySizeMaxKb();
224
- // SyncServerOptions.addHistorySizeTargetKb();
225
- // SyncServerOptions.addAdminUrl();
226
- // SyncServerOptions.addAdminThreads();
293
+ if (workerThreads > 0 ) {
294
+ SyncServerOptions .addWorkerThreads (fbb , workerThreads );
295
+ }
296
+ if (historySizeMaxKb > 0 ) {
297
+ SyncServerOptions .addHistorySizeMaxKb (fbb , historySizeMaxKb );
298
+ }
299
+ if (historySizeTargetKb > 0 ) {
300
+ SyncServerOptions .addHistorySizeTargetKb (fbb , historySizeTargetKb );
301
+ }
227
302
if (clusterIdOffset > 0 ) {
228
303
SyncServerOptions .addClusterId (fbb , clusterIdOffset );
229
304
}
0 commit comments