Package io.realm.mongodb.sync
Class Sync
- java.lang.Object
-
- io.realm.mongodb.sync.Sync
-
public abstract class Sync extends Object
A sync manager handling synchronization of local Realms with remote Realm Apps.The primary role of this is to access the
SyncSessionfor a synchronized Realm. After opening the synchronized Realm you can access theSyncSessionand 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();- See Also:
App.getSync(),getSession(SyncConfiguration)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSync.DebugDebugging related options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<SyncSession>getAllSessions()Gets a collection of all the cachedSyncSession.SyncSessiongetOrCreateSession(SyncConfiguration syncConfiguration)Gets any cachedSyncSessionfor the givenSyncConfigurationor create a new one if no one exists.SyncSessiongetSession(SyncConfiguration syncConfiguration)Gets a cachedSyncSessionfor the givenSyncConfigurationor throw if no one exists yet.voidreconnect()Realm will automatically detect when a device gets connectivity after being offline and resume syncing.
-
-
-
Method Detail
-
getSession
public SyncSession getSession(SyncConfiguration syncConfiguration) throws IllegalStateException
Gets a cachedSyncSessionfor the givenSyncConfigurationor throw if no one exists yet. A session should exist after you open a Realm with aSyncConfiguration.- Parameters:
syncConfiguration- configuration object for the synchronized Realm.- Returns:
- the
SyncSessionfor the specified Realm. - Throws:
IllegalArgumentException- if syncConfiguration isnull.IllegalStateException- if the session could not be found using the providedSyncConfiguration.
-
getAllSessions
public Collection<SyncSession> getAllSessions()
Gets a collection of all the cachedSyncSession.- Returns:
- a collection of
SyncSession.
-
getOrCreateSession
public SyncSession getOrCreateSession(SyncConfiguration syncConfiguration)
Gets any cachedSyncSessionfor the givenSyncConfigurationor create a new one if no one exists. Note: This is mainly for internal usage, consider usinggetSession(SyncConfiguration)instead.- Parameters:
syncConfiguration- configuration object for the synchronized Realm.- Returns:
- the
SyncSessionfor the specified Realm. - Throws:
IllegalArgumentException- if syncConfiguration isnull.
-
reconnect
public void reconnect()
Realm will automatically detect when a device gets connectivity after being offline and resume syncing.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.
-
-