Docs Menu

Docs HomeDevelop ApplicationsAtlas Device SDKs

Class SyncConfiguration

On this page

  • io.realm.mongodb.sync
  • Nested Class Summary
  • Method Summary
  • Inherited Methods
  • Method Detail
  • defaultConfig
  • equals
  • forRecovery
  • getClientResetHandler
  • getErrorHandler
  • getInitialDataTransaction
  • getInitialRemoteDataTimeout
  • getInitialSubscriptionsHandler
  • getPartitionValue
  • getServerUrl
  • getSessionStopPolicy
  • getSyncClientResetStrategy
  • getUrlPrefix
  • getUser
  • hashCode
  • isFlexibleSyncConfiguration
  • isPartitionBasedSyncConfiguration
  • isSyncConfiguration
  • realmExists
  • shouldDeleteRealmOnLogout
  • shouldWaitForInitialRemoteData
  • toString
io.realm.mongodb.sync.SyncConfiguration

A SyncConfiguration is used to setup a realm that can be synchronized between devices using MongoDB Realm.

A valid User is required to create a SyncConfiguration . See Credentials and App.loginAsync(Credentials, App.Callback) for more information on how to get a user object.

A minimal SyncConfiguration can be found below.

App app = new App("app-id");
User user = app.login(Credentials.anonymous());
SyncConfiguration config = SyncConfiguration.defaultConfiguration(user, "partition-value");
Realm realm = Realm.getInstance(config);

Synchronized Realms only support additive migrations which can be detected and performed automatically, so the following builder options are not accessible compared to a normal Realm:

  • deleteRealmIfMigrationNeeded()

  • migration(Migration)

Synchronized Realms are created by using Realm.getInstance(RealmConfiguration) and Realm.getDefaultInstance() like ordinary unsynchronized Realms.

Tip

See also:

  • The docs for more information about synchronization.

Modifier and Type
Class and Description
public static interface
public static final
Modifier and Type
Method and Description
public static SyncConfiguration
User user,
ObjectId partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

public static SyncConfiguration
User user,
Integer partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

public static SyncConfiguration
User user,
Long partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

public static SyncConfiguration
User user,
String partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

public static SyncConfiguration

Returns a default Flexible Sync configuration for the given user.

public boolean
public static RealmConfiguration
String canonicalPath
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes.

public static RealmConfiguration
String canonicalPath,
byte[] encryptionKey,
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes.

Returns the Client Reset handler for this SyncConfiguration.

Returns the error handler for this SyncConfiguration.

Returns the transaction instance with initial data.

public long

Returns the timeout defined when downloading any initial data the first time the Realm is opened.

Returns the configured initial subscription handler for this realm.

public BsonValue

Returns the value this Realm is partitioned on.

public URI

Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.

public OsRealmConfig.SyncSessionStopPolicy

NOTE: Only for internal usage.

Returns the sync client reset strategy for this SyncConfiguration.

public String

Returns the url prefix used when establishing a sync connection to the Realm Object Server.

public User

Returns the user.

public int
public boolean

Returns whether or not this configuration is for opening a Realm configured for Flexible Sync.

public boolean

Returns whether or not this configuration is for opening a Realm configured for Partition-based Sync.

protected boolean
protected boolean

Checks if the Realm file defined by this configuration already exists.

public boolean

Returns true if the Realm file must be deleted once the User owning it logs out.

public boolean

Returns true if the Realm will download all known changes from the remote server before being opened the first time.

public String
  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

  • Methods inherited from class io.realm.RealmConfiguration : getRealmDirectory , getRealmFileName , getEncryptionKey , getSchemaVersion , getMigration , shouldDeleteRealmIfMigrationNeeded , getDurability , getSchemaMediator , getInitialDataTransaction , hasAssetFile , getAssetFilePath , getCompactOnLaunchCallback , getRealmObjectClasses , getPath , realmExists , getRxFactory , getFlowFactory , isReadOnly , isRecoveryConfiguration , getMaxNumberOfActiveVersions , isAllowWritesOnUiThread , isAllowQueriesOnUiThread , equals , getInstance , hashCode , createSchemaMediator , toString , isSyncConfiguration , forRecovery

User user,
ObjectId partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.

  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
Integer partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.

  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
Long partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.

  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
String partitionValue
)

Returns a default Partition-based Sync configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.

  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user
)

Returns a default Flexible Sync configuration for the given user.

Parameters

  • user - The user that will be used for accessing the Realm App.

Returns

the default Flexible Sync configuration for the given user.

Tip

See also:

  • {@link SubscriptionSet} for more information about Flexible Sync.

public boolean equals (
)

Overrides

equals in class RealmConfiguration

String canonicalPath
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. This is useful when trying to open a backup/recovery Realm (after a client reset). Note: This will use the default Realm module (composed of all RealmModel ), and assume no encryption should be used as well.

Parameters

  • canonicalPath - the absolute path to the Realm file defined by this configuration.

Returns

RealmConfiguration that can be used offline

String canonicalPath,
byte[] encryptionKey,
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. This is useful when trying to open a backup/recovery Realm (after a client reset).

Parameters

  • canonicalPath - the absolute path to the Realm file defined by this configuration.

  • encryptionKey - the key used to encrypt/decrypt the Realm file.

  • modules - if specified it will restricts Realm schema to the provided module.

Returns

RealmConfiguration that can be used offline

Returns the Client Reset handler for this SyncConfiguration.

Returns

the Client Reset handler.

Returns the error handler for this SyncConfiguration.

Returns

the error handler.

Returns the transaction instance with initial data.

Returns

the initial data transaction.

Overrides

getInitialDataTransaction in class RealmConfiguration

Returns the timeout defined when downloading any initial data the first time the Realm is opened.This value is only applicable if shouldWaitForInitialRemoteData() returns true .

Returns

the time Realm will wait for all changes to be downloaded before it is aborted and an exception is thrown.

Returns the configured initial subscription handler for this realm.

Returns

the handler used to configure initial subscriptions for this realm.

public BsonValue getPartitionValue ()

Returns the value this Realm is partitioned on. The partition key is a property defined in MongoDB Realm. All classes with a property with this value will be synchronized to the Realm.

Returns

the value being used by MongoDB Realm to partition the server side MongoDB Database into Realms that can be synchronized independently.

Throws

public URI getServerUrl ()

Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.

Returns

URI identifying the MongoDB Realm this local Realm is synchronized with.

public OsRealmConfig.SyncSessionStopPolicy getSessionStopPolicy ()

NOTE: Only for internal usage. May change without warning. Returns the stop policy for the session for this Realm once the Realm has been closed.

Returns

the stop policy used by the session once the Realm is closed.

Returns the sync client reset strategy for this SyncConfiguration.

Returns

the sync client reset strategy.

Returns the url prefix used when establishing a sync connection to the Realm Object Server.
public User getUser ()

Returns the user.

Returns

the user.

public int hashCode ()

Overrides

hashCode in class RealmConfiguration

public boolean isFlexibleSyncConfiguration ()

Returns whether or not this configuration is for opening a Realm configured for Flexible Sync.

Returns

true if this configuration is for a Flexible Sync Realm, false if not.

Returns whether or not this configuration is for opening a Realm configured for Partition-based Sync.

Returns

true if this configuration is for a Partition-based Sync Realm, false if not.

protected boolean isSyncConfiguration ()

Overrides

isSyncConfiguration in class RealmConfiguration

protected boolean realmExists ()

Checks if the Realm file defined by this configuration already exists.WARNING: This method is just a point-in-time check. Unless protected by external synchronization another thread or process might have created or deleted the Realm file right after this method has returned.

Returns

true if the Realm file exists, false otherwise.

Overrides

realmExists in class RealmConfiguration

public boolean shouldDeleteRealmOnLogout ()

Returns true if the Realm file must be deleted once the User owning it logs out.

Returns

true if the Realm file must be deleted if the User logs out. false if the file is allowed to remain behind.

Returns true if the Realm will download all known changes from the remote server before being opened the first time.

Returns

true if all remote changes will be downloaded before the Realm can be opened. false if the Realm can be opened immediately.

public String toString ()

Overrides

toString in class RealmConfiguration

← Interface SyncClientResetStrategy