Docs Menu

Class Sync

On this page

  • io.realm.mongodb.sync
  • Nested Class Summary
  • Method Summary
  • Inherited Methods
  • Method Detail
  • getAllSessions
  • getOrCreateSession
  • getSession
  • reconnect
java.lang.Object
io.realm.mongodb.sync.Sync

A sync manager handling synchronization of local Realms with remote Realm Apps.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();
Tip
See also:
Modifier and Type
Class and Description
public static
Modifier and Type
Method and Description
public synchronized Collection

Gets a collection of all the cached SyncSession .

public synchronized SyncSession

Gets any cached SyncSession for the given SyncConfiguration or create a new one if no one exists.

public synchronized SyncSession
SyncConfiguration syncConfiguration
)

Gets a cached SyncSession for the given SyncConfiguration or throw if no one exists yet.

public void

Realm will automatically detect when a device gets connectivity after being offline and resume syncing.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize
public synchronized Collection getAllSessions ()

Gets a collection of all the cached SyncSession .

Returns

a collection of SyncSession .

public synchronized SyncSession getOrCreateSession (
SyncConfiguration syncConfiguration
)

Gets any cached 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.

Parameters

  • syncConfiguration - configuration object for the synchronized Realm.

Returns

the SyncSession for the specified Realm.

Throws

public synchronized SyncSession getSession (
SyncConfiguration syncConfiguration
)

Gets a cached SyncSession for the given SyncConfiguration or throw if no one exists yet. A session should exist after you open a Realm with a SyncConfiguration .

Parameters

  • syncConfiguration - configuration object for the synchronized Realm.

Returns

the SyncSession for the specified Realm.

Throws

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.

←  Enum ProgressModeClass Sync.Debug →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.