public class SyncConfiguration extends RealmConfiguration
SyncConfiguration
is used to setup a Realm that can be synchronized between devices using the Realm
Object Server.
A valid SyncUser
is required to create a SyncConfiguration
. See SyncCredentials
and
SyncUser.logInAsync(SyncCredentials, String, SyncUser.Callback)
for more information on how to get a user object.
A minimal SyncConfiguration
can be found below.
SyncUser user = SyncUser.current();
String url = "realm://myinstance.cloud.realm.io/default";
SyncConfiguration config = new SyncConfiguration.Builder(user, url).build();
Synchronized Realms come in two forms:
SyncConfiguration.Builder.fullSynchronization()
. In this mode
the entire Realm is synchronized in the background without having to query for
data first. This means that data generally will be available quicker but should only
be used if the server side Realm is small and doesn't contain data the device is not
allowed to see.
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, KEY_LENGTH
Modifier and Type | Method and Description |
---|---|
static SyncConfiguration |
automatic()
Deprecated.
use
SyncUser.getDefaultConfiguration() instead. |
static SyncConfiguration |
automatic(SyncUser user)
Deprecated.
use
SyncUser.getDefaultConfiguration() instead. |
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.ErrorHandler |
getErrorHandler() |
long |
getInitialRemoteDataTimeout(TimeUnit unit)
Returns the timeout defined when downloading any initial data the first time the Realm is opened.
|
String |
getServerCertificateAssetName()
Returns the name of certificate stored under the
assets , to be used to validate
the TLS connection to the Realm Object Server. |
String |
getServerCertificateFilePath()
Returns the name of the certificate copied from
assets into internal storage, so it
can be used to validate the TLS connection to the Realm Object Server. |
URI |
getServerUrl()
Returns the fully disambiguated URI for the remote Realm i.e., the
/~/ placeholder has been replaced
by the proper user ID. |
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.
|
SyncUser |
getUser()
Returns the user.
|
int |
hashCode() |
boolean |
isFullySynchronizedRealm()
Returns whether this configuration is for a fully synchronized Realm or not.
|
boolean |
isPartialRealm()
Deprecated.
use
isFullySynchronizedRealm() instead. |
boolean |
shouldDeleteRealmOnLogout()
Returns
true if the Realm file must be deleted once the SyncUser 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. |
boolean |
syncClientValidateSsl()
Whether the Realm Object Server certificate should be validated in order
to establish a valid TLS connection.
|
String |
toString() |
getCompactOnLaunchCallback, getDurability, getEncryptionKey, getMigration, getPath, getRealmDirectory, getRealmFileName, getRealmObjectClasses, getRxFactory, getSchemaVersion, 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 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.@Deprecated public static SyncConfiguration automatic()
SyncUser.getDefaultConfiguration()
instead.This configuration will point to the default Realm on the server where the user was authenticated.
SyncConfiguration
.IllegalStateException
- if no user are logged in, or multiple users have. Only one should
be logged in when calling this method.@Deprecated public static SyncConfiguration automatic(SyncUser user)
SyncUser.getDefaultConfiguration()
instead.This configuration will point to the default Realm on the server where the user was authenticated.
SyncConfiguration
.IllegalArgumentException
- if no user was provided or the user isn't valid.public boolean equals(Object o)
equals
in class RealmConfiguration
public int hashCode()
hashCode
in class RealmConfiguration
public String toString()
toString
in class RealmConfiguration
public SyncUser getUser()
public URI getServerUrl()
/~/
placeholder has been replaced
by the proper user ID.URI
identifying the remote Realm this local Realm is synchronized with.public SyncSession.ErrorHandler getErrorHandler()
public boolean shouldDeleteRealmOnLogout()
true
if the Realm file must be deleted once the SyncUser
owning it logs out.true
if the Realm file must be deleted if the SyncUser
logs out. false
if the file
is allowed to remain behind.public String getServerCertificateAssetName()
assets
, to be used to validate
the TLS connection to the Realm Object Server.assets
.getServerCertificateFilePath()
public String getServerCertificateFilePath()
assets
into internal storage, so it
can be used to validate the TLS connection to the Realm Object Server.getServerCertificateAssetName()
public boolean syncClientValidateSsl()
true
to validate the remote certificate, or false
to bypass certificate validation.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()
@Deprecated public boolean isPartialRealm()
isFullySynchronizedRealm()
instead.Query-based synchronization allows a synchronized Realm to be opened in such a way that only objects queried by the user are synchronized to the device.
true
to open a query-based Realm false
otherwise.public boolean isFullySynchronizedRealm()
for more details.
public String getUrlPrefix()