Package io.realm.mongodb.sync
Class SyncConfiguration
- java.lang.Object
-
- io.realm.RealmConfiguration
-
- io.realm.mongodb.sync.SyncConfiguration
-
public class SyncConfiguration extends RealmConfiguration
ASyncConfiguration
is used to setup a Realm Database that can be synchronized between devices using MongoDB Realm.A valid
User
is required to create aSyncConfiguration
. SeeCredentials
andApp.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)
andRealm.getDefaultInstance()
like ordinary unsynchronized Realms.- See Also:
- The docs for more information about synchronization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SyncConfiguration.Builder
Builder used to construct instances of a SyncConfiguration in a fluent manner.static interface
SyncConfiguration.InitialFlexibleSyncSubscriptions
Interface for configuring the initial set of of subscriptions.
-
Field Summary
-
Fields inherited from class io.realm.RealmConfiguration
DEFAULT_REALM_NAME
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static SyncConfiguration
defaultConfig(User user)
Returns a default Flexible Sync configuration for the given user.static SyncConfiguration
defaultConfig(User user, Integer partitionValue)
Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfiguration
defaultConfig(User user, Long partitionValue)
Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfiguration
defaultConfig(User user, String partitionValue)
Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfiguration
defaultConfig(User user, UUID partitionValue)
Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfiguration
defaultConfig(User user, ObjectId partitionValue)
Returns a default Partition-based Sync configuration for the given user and partition value.boolean
equals(Object o)
static RealmConfiguration
forRecovery(String canonicalPath)
Returns aRealmConfiguration
appropriate to open a read-only, non-synced Realm to recover any pending changes.static RealmConfiguration
forRecovery(String canonicalPath, byte[] encryptionKey, Object... modules)
Returns aRealmConfiguration
appropriate to open a read-only, non-synced Realm to recover any pending changes.SyncSession.ClientResetHandler
getClientResetHandler()
Deprecated.replaced bygetSyncClientResetStrategy()
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.SyncConfiguration.InitialFlexibleSyncSubscriptions
getInitialSubscriptionsHandler()
Returns the configured initial subscription handler for this realm.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.io.realm.internal.OsRealmConfig.SyncSessionStopPolicy
getSessionStopPolicy()
NOTE: Only for internal usage.SyncClientResetStrategy
getSyncClientResetStrategy()
Returns the sync client reset strategy for this SyncConfiguration.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
isFlexibleSyncConfiguration()
Returns whether or not this configuration is for opening a Realm configured for Flexible Sync.boolean
isPartitionBasedSyncConfiguration()
Returns whether or not this configuration is for opening a Realm configured for Partition-based Sync.boolean
shouldDeleteRealmOnLogout()
Returnstrue
if the Realm file must be deleted once theUser
owning it logs out.boolean
shouldWaitForInitialRemoteData()
Returnstrue
if the Realm will download all known changes from the remote server before being opened the first time.String
toString()
-
Methods inherited from class io.realm.RealmConfiguration
getAssetFilePath, getCompactOnLaunchCallback, getDurability, getEncryptionKey, getFlowFactory, getMaxNumberOfActiveVersions, getMigration, getPath, getRealmDirectory, getRealmFileName, getRealmObjectClasses, getRxFactory, getSchemaVersion, hasAssetFile, isAllowQueriesOnUiThread, isAllowWritesOnUiThread, isReadOnly, isRecoveryConfiguration, shouldDeleteRealmIfMigrationNeeded
-
-
-
-
Method Detail
-
forRecovery
public static RealmConfiguration forRecovery(String canonicalPath, @Nullable byte[] encryptionKey, @Nullable Object... modules)
Returns aRealmConfiguration
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
-
defaultConfig
public static SyncConfiguration defaultConfig(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.
-
defaultConfig
public static SyncConfiguration defaultConfig(User user, @Nullable 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.
-
defaultConfig
public static SyncConfiguration defaultConfig(User user, @Nullable 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.
-
defaultConfig
public static SyncConfiguration defaultConfig(User user, @Nullable 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.
-
defaultConfig
public static SyncConfiguration defaultConfig(User user, @Nullable 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.
-
defaultConfig
public static SyncConfiguration defaultConfig(User user, @Nullable UUID 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.
-
forRecovery
public static RealmConfiguration forRecovery(String canonicalPath)
Returns aRealmConfiguration
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 allRealmModel
), 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
-
getInitialSubscriptionsHandler
public SyncConfiguration.InitialFlexibleSyncSubscriptions getInitialSubscriptionsHandler()
Returns the configured initial subscription handler for this realm.- Returns:
- the handler used to configure initial subscriptions for this realm.
-
equals
public boolean equals(@Nullable Object o)
- Overrides:
equals
in classRealmConfiguration
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classRealmConfiguration
-
toString
public String toString()
- Overrides:
toString
in classRealmConfiguration
-
getUser
public User getUser()
Returns the user.- Returns:
- the user.
-
getServerUrl
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.
-
getErrorHandler
public SyncSession.ErrorHandler getErrorHandler()
Returns the error handler for this SyncConfiguration.- Returns:
- the error handler.
-
getClientResetHandler
@Deprecated public SyncSession.ClientResetHandler getClientResetHandler()
Deprecated.replaced bygetSyncClientResetStrategy()
Returns the Client Reset handler for this SyncConfiguration.- Returns:
- the Client Reset handler.
-
getSyncClientResetStrategy
public SyncClientResetStrategy getSyncClientResetStrategy()
Returns the sync client reset strategy for this SyncConfiguration.- Returns:
- the sync client reset strategy.
-
shouldDeleteRealmOnLogout
public boolean shouldDeleteRealmOnLogout()
Returnstrue
if the Realm file must be deleted once theUser
owning it logs out.- Returns:
true
if the Realm file must be deleted if theUser
logs out.false
if the file is allowed to remain behind.
-
shouldWaitForInitialRemoteData
public boolean shouldWaitForInitialRemoteData()
Returnstrue
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.
-
getInitialRemoteDataTimeout
public long getInitialRemoteDataTimeout(TimeUnit unit)
Returns the timeout defined when downloading any initial data the first time the Realm is opened.This value is only applicable if
shouldWaitForInitialRemoteData()
returnstrue
.- Returns:
- the time Realm will wait for all changes to be downloaded before it is aborted and an exception is thrown.
- See Also:
SyncConfiguration.Builder.waitForInitialRemoteData(long, TimeUnit)
-
getSessionStopPolicy
public io.realm.internal.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.
-
getUrlPrefix
@Nullable public String getUrlPrefix()
Returns the url prefix used when establishing a sync connection to the Realm Object Server.
-
getPartitionValue
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:
IllegalStateException
- if this configuration is for a realm configured for flexible sync. You can useisPartitionBasedSyncConfiguration()
before calling this method to check.
-
isFlexibleSyncConfiguration
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.
-
isPartitionBasedSyncConfiguration
public boolean isPartitionBasedSyncConfiguration()
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.
-
-