public class SyncConfiguration extends RealmConfiguration
SyncConfiguration
is used to setup a Realm Database 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)
Realm.getInstance(RealmConfiguration)
and
Realm.getDefaultInstance()
like ordinary unsynchronized Realms.Modifier and Type | Class and Description |
---|---|
static class |
SyncConfiguration.Builder
Builder used to construct instances of a SyncConfiguration in a fluent manner.
|
DEFAULT_REALM_NAME
Modifier and Type | Method and Description |
---|---|
static SyncConfiguration |
defaultConfig(User user,
Integer partitionValue)
Returns a default configuration for the given user and partition value.
|
static SyncConfiguration |
defaultConfig(User user,
Long partitionValue)
Returns a default configuration for the given user and partition value.
|
static SyncConfiguration |
defaultConfig(User user,
ObjectId partitionValue)
Returns a default configuration for the given user and partition value.
|
static SyncConfiguration |
defaultConfig(User user,
String partitionValue)
Returns a default configuration for the given user and partition value.
|
boolean |
equals(Object o) |
static RealmConfiguration |
forRecovery(String canonicalPath)
Returns a
RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. |
static RealmConfiguration |
forRecovery(String canonicalPath,
byte[] encryptionKey,
Object... modules)
Returns a
RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. |
SyncSession.ClientResetHandler |
getClientResetHandler()
Returns the Client Reset handler for this SyncConfiguration.
|
SyncSession.ErrorHandler |
getErrorHandler()
Returns the error handler for this SyncConfiguration.
|
long |
getInitialRemoteDataTimeout(TimeUnit unit)
Returns the timeout defined when downloading any initial data the first time the Realm is opened.
|
BsonValue |
getPartitionValue()
Returns the value this Realm is partitioned on.
|
URI |
getServerUrl()
Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.
|
OsRealmConfig.SyncSessionStopPolicy |
getSessionStopPolicy()
NOTE: Only for internal usage.
|
String |
getUrlPrefix()
Returns the url prefix used when establishing a sync connection to the Realm Object Server.
|
User |
getUser()
Returns the user.
|
int |
hashCode() |
boolean |
shouldDeleteRealmOnLogout()
Returns
true if the Realm file must be deleted once the User owning it logs out. |
boolean |
shouldWaitForInitialRemoteData()
Returns
true if the Realm will download all known changes from the remote server before being opened the
first time. |
String |
toString() |
getCompactOnLaunchCallback, getDurability, getEncryptionKey, getMaxNumberOfActiveVersions, getMigration, getPath, getRealmDirectory, getRealmFileName, getRealmObjectClasses, getRxFactory, getSchemaVersion, isAllowQueriesOnUiThread, isAllowWritesOnUiThread, isReadOnly, isRecoveryConfiguration, shouldDeleteRealmIfMigrationNeeded
public static RealmConfiguration forRecovery(String canonicalPath, byte[] encryptionKey, Object... modules)
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).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.public static SyncConfiguration defaultConfig(User user, String partitionValue)
user
- The user that will be used for accessing the Realm App.partitionValue
- The partition value identifying the remote Realm that will be synchronized.public static SyncConfiguration defaultConfig(User user, Long partitionValue)
user
- The user that will be used for accessing the Realm App.partitionValue
- The partition value identifying the remote Realm that will be synchronized.public static SyncConfiguration defaultConfig(User user, Integer partitionValue)
user
- The user that will be used for accessing the Realm App.partitionValue
- The partition value identifying the remote Realm that will be synchronized.public static SyncConfiguration defaultConfig(User user, ObjectId partitionValue)
user
- The user that will be used for accessing the Realm App.partitionValue
- The partition value identifying the remote Realm that will be synchronized.public static RealmConfiguration forRecovery(String canonicalPath)
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.canonicalPath
- the absolute path to the Realm file defined by this configuration.public boolean equals(Object o)
equals
in class RealmConfiguration
public int hashCode()
hashCode
in class RealmConfiguration
public String toString()
toString
in class RealmConfiguration
public User getUser()
public URI getServerUrl()
URI
identifying the MongoDB Realm this local Realm is synchronized with.public SyncSession.ErrorHandler getErrorHandler()
public SyncSession.ClientResetHandler getClientResetHandler()
public boolean shouldDeleteRealmOnLogout()
true
if the Realm file must be deleted once the User
owning it logs out.true
if the Realm file must be deleted if the User
logs out. false
if the file
is allowed to remain behind.public boolean shouldWaitForInitialRemoteData()
true
if the Realm will download all known changes from the remote server before being opened the
first time.true
if all remote changes will be downloaded before the Realm can be opened. false
if
the Realm can be opened immediately.public long getInitialRemoteDataTimeout(TimeUnit unit)
This value is only applicable if shouldWaitForInitialRemoteData()
returns true
.
SyncConfiguration.Builder.waitForInitialRemoteData(long, TimeUnit)
public OsRealmConfig.SyncSessionStopPolicy getSessionStopPolicy()
public String getUrlPrefix()
public BsonValue getPartitionValue()