public abstract class Sync extends Object
The primary role of this is to access the SyncSession
for a synchronized Realm. After
opening the synchronized Realm you can access the SyncSession
and perform synchronization
related operations as shown below:
App app = new App("app-id"); User user = app.login(Credentials.anonymous()); SyncConfiguration syncConfiguration = new SyncConfiguration.Builder(user, "<partition value>") .build(); Realm instance = Realm.getInstance(syncConfiguration); SyncSession session = app.getSync().getSession(syncConfiguration); instance.executeTransaction(realm -> { realm.insert(...); }); session.uploadAllLocalChanges(); instance.close();
App.getSync()
,
getSession(SyncConfiguration)
Modifier and Type | Class and Description |
---|---|
static class |
Sync.Debug
Debugging related options.
|
Modifier and Type | Method and Description |
---|---|
Collection<SyncSession> |
getAllSessions()
Gets a collection of all the cached
SyncSession . |
SyncSession |
getOrCreateSession(SyncConfiguration syncConfiguration)
Gets any cached
SyncSession for the given SyncConfiguration or create a new one if
no one exists. |
SyncSession |
getSession(SyncConfiguration syncConfiguration)
Gets a cached
SyncSession for the given SyncConfiguration or throw if no one exists yet. |
void |
reconnect()
Realm will automatically detect when a device gets connectivity after being offline and
resume syncing.
|
public SyncSession getSession(SyncConfiguration syncConfiguration) throws IllegalStateException
SyncSession
for the given SyncConfiguration
or throw if no one exists yet.
A session should exist after you open a Realm with a SyncConfiguration
.syncConfiguration
- configuration object for the synchronized Realm.SyncSession
for the specified Realm.IllegalArgumentException
- if syncConfiguration is null
.IllegalStateException
- if the session could not be found using the provided SyncConfiguration
.public Collection<SyncSession> getAllSessions()
SyncSession
.SyncSession
.public SyncSession getOrCreateSession(SyncConfiguration syncConfiguration)
SyncSession
for the given SyncConfiguration
or create a new one if
no one exists.
Note: This is mainly for internal usage, consider using getSession(SyncConfiguration)
instead.syncConfiguration
- configuration object for the synchronized Realm.SyncSession
for the specified Realm.IllegalArgumentException
- if syncConfiguration is null
.public void reconnect()
However, as some of these checks are performed using incremental backoff, this will in some cases not happen immediately.
In those cases it can be beneficial to call this method manually, which will force all sessions to attempt to reconnect immediately and reset any timers they are using for incremental backoff.