Package io.realm.mongodb.sync
Class SyncConfiguration
- java.lang.Object
-
- io.realm.RealmConfiguration
-
- io.realm.mongodb.sync.SyncConfiguration
-
public class SyncConfiguration extends RealmConfiguration
ASyncConfigurationis used to setup a Realm Database that can be synchronized between devices using MongoDB Realm.A valid
Useris required to create aSyncConfiguration. SeeCredentialsandApp.loginAsync(Credentials, App.Callback)for more information on how to get a user object.A minimal
SyncConfigurationcan 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 classSyncConfiguration.BuilderBuilder used to construct instances of a SyncConfiguration in a fluent manner.static interfaceSyncConfiguration.InitialFlexibleSyncSubscriptionsInterface 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 SyncConfigurationdefaultConfig(User user)Returns a default Flexible Sync configuration for the given user.static SyncConfigurationdefaultConfig(User user, Integer partitionValue)Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfigurationdefaultConfig(User user, Long partitionValue)Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfigurationdefaultConfig(User user, String partitionValue)Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfigurationdefaultConfig(User user, UUID partitionValue)Returns a default Partition-based Sync configuration for the given user and partition value.static SyncConfigurationdefaultConfig(User user, ObjectId partitionValue)Returns a default Partition-based Sync configuration for the given user and partition value.booleanequals(Object o)static RealmConfigurationforRecovery(String canonicalPath)Returns aRealmConfigurationappropriate to open a read-only, non-synced Realm to recover any pending changes.static RealmConfigurationforRecovery(String canonicalPath, byte[] encryptionKey, Object... modules)Returns aRealmConfigurationappropriate to open a read-only, non-synced Realm to recover any pending changes.SyncSession.ClientResetHandlergetClientResetHandler()Deprecated.replaced bygetSyncClientResetStrategy()SyncSession.ErrorHandlergetErrorHandler()Returns the error handler for this SyncConfiguration.longgetInitialRemoteDataTimeout(TimeUnit unit)Returns the timeout defined when downloading any initial data the first time the Realm is opened.SyncConfiguration.InitialFlexibleSyncSubscriptionsgetInitialSubscriptionsHandler()Returns the configured initial subscription handler for this realm.BsonValuegetPartitionValue()Returns the value this Realm is partitioned on.URIgetServerUrl()Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.io.realm.internal.OsRealmConfig.SyncSessionStopPolicygetSessionStopPolicy()NOTE: Only for internal usage.SyncClientResetStrategygetSyncClientResetStrategy()Returns the sync client reset strategy for this SyncConfiguration.StringgetUrlPrefix()Returns the url prefix used when establishing a sync connection to the Realm Object Server.UsergetUser()Returns the user.inthashCode()booleanisFlexibleSyncConfiguration()Returns whether or not this configuration is for opening a Realm configured for Flexible Sync.booleanisPartitionBasedSyncConfiguration()Returns whether or not this configuration is for opening a Realm configured for Partition-based Sync.booleanshouldDeleteRealmOnLogout()Returnstrueif the Realm file must be deleted once theUserowning it logs out.booleanshouldWaitForInitialRemoteData()Returnstrueif the Realm will download all known changes from the remote server before being opened the first time.StringtoString()-
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 aRealmConfigurationappropriate 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 aRealmConfigurationappropriate 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:
equalsin classRealmConfiguration
-
hashCode
public int hashCode()
- Overrides:
hashCodein classRealmConfiguration
-
toString
public String toString()
- Overrides:
toStringin 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:
URIidentifying 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()
Returnstrueif the Realm file must be deleted once theUserowning it logs out.- Returns:
trueif the Realm file must be deleted if theUserlogs out.falseif the file is allowed to remain behind.
-
shouldWaitForInitialRemoteData
public boolean shouldWaitForInitialRemoteData()
Returnstrueif the Realm will download all known changes from the remote server before being opened the first time.- Returns:
trueif all remote changes will be downloaded before the Realm can be opened.falseif 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:
trueif this configuration is for a Flexible Sync Realm,falseif not.
-
isPartitionBasedSyncConfiguration
public boolean isPartitionBasedSyncConfiguration()
Returns whether or not this configuration is for opening a Realm configured for Partition-based Sync.- Returns:
trueif this configuration is for a Partition-based Sync Realm,falseif not.
-
-