Skip to content

Commit 63cd886

Browse files
committed
SyncClient: change some "request" methods to return a bool
1 parent ce59546 commit 63cd886

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.objectbox.sync;
22

33
import io.objectbox.annotation.apihint.Experimental;
4+
import io.objectbox.annotation.apihint.Temporary;
45
import io.objectbox.sync.SyncBuilder.RequestUpdatesMode;
56
import io.objectbox.sync.listener.SyncChangeListener;
67
import io.objectbox.sync.listener.SyncCompletedListener;
@@ -116,30 +117,38 @@ public interface SyncClient extends Closeable {
116117
* {@link SyncBuilder#requestUpdatesMode(RequestUpdatesMode) requestUpdatesMode(MANUAL)}.
117118
*
118119
* @see #cancelUpdates()
120+
* @return 'true' if the request was likely sent (e.g. the sync client is in "logged in" state)
121+
* or 'false' if the request was not sent (and will not be sent in the future)
119122
*/
120-
void requestUpdates();
123+
boolean requestUpdates();
121124

122125
/**
123126
* Asks the server to send sync updates until this sync client is up-to-date, then pauses sync updates again.
124127
* This is useful if sync updates were turned off with
125128
* {@link SyncBuilder#requestUpdatesMode(RequestUpdatesMode) requestUpdatesMode(MANUAL)}.
129+
* @return 'true' if the request was likely sent (e.g. the sync client is in "logged in" state)
130+
* or 'false' if the request was not sent (and will not be sent in the future)
126131
*/
127-
void requestUpdatesOnce();
132+
boolean requestUpdatesOnce();
128133

129134
/**
130135
* Asks the server to pause sync updates.
131136
*
137+
* @return 'true' if the request was likely sent (e.g. the sync client is in "logged in" state)
138+
* or 'false' if the request was not sent (and will not be sent in the future)
132139
* @see #requestUpdates()
133140
*/
134-
void cancelUpdates();
141+
boolean cancelUpdates();
135142

136143
/**
137144
* Experimental. This API might change or be removed in the future.
138145
* <p>
139146
* Request a sync of all previous changes from the server.
147+
* @return 'true' if the request was likely sent (e.g. the sync client is in "logged in" state)
148+
* or 'false' if the request was not sent (and will not be sent in the future)
140149
*/
141-
@Experimental
142-
void requestFullSync();
150+
@Temporary
151+
boolean requestFullSync();
143152

144153
/**
145154
* Lets the sync client know that a working network connection

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import io.objectbox.BoxStore;
44
import io.objectbox.InternalAccess;
5-
import io.objectbox.annotation.apihint.Experimental;
65
import io.objectbox.annotation.apihint.Internal;
6+
import io.objectbox.annotation.apihint.Temporary;
77
import io.objectbox.sync.SyncBuilder.RequestUpdatesMode;
88
import io.objectbox.sync.listener.SyncChangeListener;
99
import io.objectbox.sync.listener.SyncCompletedListener;
@@ -210,29 +210,30 @@ protected void finalize() throws Throwable {
210210
}
211211

212212
@Override
213-
public void requestFullSync() {
214-
nativeRequestFullSync(handle, false);
213+
@Temporary
214+
public boolean requestFullSync() {
215+
return nativeRequestFullSync(handle, false);
215216
}
216217

217218
// TODO: broken?
218-
@Experimental
219-
public void requestFullSyncAndUpdates() {
220-
nativeRequestFullSync(handle, true);
219+
@Temporary
220+
public boolean requestFullSyncAndUpdates() {
221+
return nativeRequestFullSync(handle, true);
221222
}
222223

223224
@Override
224-
public void requestUpdates() {
225-
nativeRequestUpdates(handle, true);
225+
public boolean requestUpdates() {
226+
return nativeRequestUpdates(handle, true);
226227
}
227228

228229
@Override
229-
public void requestUpdatesOnce() {
230-
nativeRequestUpdates(handle, false);
230+
public boolean requestUpdatesOnce() {
231+
return nativeRequestUpdates(handle, false);
231232
}
232233

233234
@Override
234-
public void cancelUpdates() {
235-
nativeCancelUpdates(handle);
235+
public boolean cancelUpdates() {
236+
return nativeCancelUpdates(handle);
236237
}
237238

238239
@Override
@@ -272,13 +273,13 @@ public void notifyConnectionAvailable() {
272273
private native int nativeGetState(long handle);
273274

274275
/** @param subscribeForPushes Pass true to automatically receive updates for future changes. */
275-
private native void nativeRequestUpdates(long handle, boolean subscribeForPushes);
276+
private native boolean nativeRequestUpdates(long handle, boolean subscribeForPushes);
276277

277278
/** @param subscribeForPushes Pass true to automatically receive updates for future changes. */
278-
private native void nativeRequestFullSync(long handle, boolean subscribeForPushes);
279+
private native boolean nativeRequestFullSync(long handle, boolean subscribeForPushes);
279280

280281
/** (Optional) Pause sync updates. */
281-
private native void nativeCancelUpdates(long handle);
282+
private native boolean nativeCancelUpdates(long handle);
282283

283284
/**
284285
* Hints to the native client that an active network connection is available.

tests/objectbox-java-test/src/test/java/io/objectbox/sync/ConnectivityMonitorTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,23 @@ public void close() {
159159
}
160160

161161
@Override
162-
public void requestUpdates() {
163-
162+
public boolean requestUpdates() {
163+
return false;
164164
}
165165

166166
@Override
167-
public void requestUpdatesOnce() {
168-
167+
public boolean requestUpdatesOnce() {
168+
return false;
169169
}
170170

171171
@Override
172-
public void cancelUpdates() {
173-
172+
public boolean cancelUpdates() {
173+
return false;
174174
}
175175

176176
@Override
177-
public void requestFullSync() {
178-
177+
public boolean requestFullSync() {
178+
return false;
179179
}
180180

181181
@Override

0 commit comments

Comments
 (0)