public static final class SyncConfiguration.Builder extends Object
Constructor and Description |
---|
Builder(User user,
ObjectId partitionValue)
Creates an instance of the builder for a SyncConfiguration with the given user
and partition value.
|
Builder(User user,
String partitionValue)
Creates an instance of the builder for a SyncConfiguration with the given user
and partition value.
|
Modifier and Type | Method and Description |
---|---|
SyncConfiguration.Builder |
addModule(Object module)
Adds a module to the already defined modules.
|
SyncConfiguration.Builder |
allowQueriesOnUiThread(boolean allowQueriesOnUiThread)
Sets whether or not
RealmQueries are allowed from the UI thread. |
SyncConfiguration.Builder |
allowWritesOnUiThread(boolean allowWritesOnUiThread)
Sets whether or not calls to
Realm.executeTransaction(io.realm.Realm.Transaction) are allowed from the UI thread. |
SyncConfiguration |
build()
Creates the RealmConfiguration based on the builder parameters.
|
SyncConfiguration.Builder |
clientResetHandler(SyncSession.ClientResetHandler handler)
Sets the handler for when a Client Reset occurs.
|
SyncConfiguration.Builder |
compactOnLaunch()
Setting this will cause Realm to compact the Realm file if the Realm file has grown too large and a
significant amount of space can be recovered.
|
SyncConfiguration.Builder |
compactOnLaunch(CompactOnLaunchCallback compactOnLaunch)
Sets this to determine if the Realm file should be compacted before returned to the user.
|
SyncConfiguration.Builder |
encryptionKey(byte[] key)
Sets the 64 bytes key used to encrypt and decrypt the Realm file.
|
SyncConfiguration.Builder |
errorHandler(SyncSession.ErrorHandler errorHandler)
Sets the error handler used by this configuration.
|
SyncConfiguration.Builder |
initialData(Realm.Transaction transaction)
Sets the initial data in
Realm . |
SyncConfiguration.Builder |
inMemory()
Setting this will create an in-memory Realm instead of saving it to disk.
|
SyncConfiguration.Builder |
maxNumberOfActiveVersions(long number)
Sets the maximum number of live versions in the Realm file before an
IllegalStateException is thrown when
attempting to write more data. |
SyncConfiguration.Builder |
modules(Iterable<Object> modules)
Replaces the existing module(s) with one or more
RealmModule s. |
SyncConfiguration.Builder |
modules(Object baseModule,
Object... additionalModules)
Replaces the existing module(s) with one or more
RealmModule s. |
SyncConfiguration.Builder |
readOnly()
Setting this will cause the Realm to become read only and all write transactions made against this Realm will
fail with an
IllegalStateException . |
SyncConfiguration.Builder |
rxFactory(RxObservableFactory factory)
Sets the
RxObservableFactory used to create Rx Observables from Realm objects. |
SyncConfiguration.Builder |
schemaVersion(long schemaVersion)
Sets the schema version of the Realm.
|
SyncConfiguration.Builder |
urlPrefix(String urlPrefix)
The prefix that is prepended to the path in the WebSocket request that initiates a sync
connection to MongoDB Realm.
|
SyncConfiguration.Builder |
waitForInitialRemoteData()
Setting this will cause the Realm to download all known changes from the server the first time a Realm is
opened.
|
SyncConfiguration.Builder |
waitForInitialRemoteData(long timeout,
TimeUnit unit)
Setting this will cause the Realm to download all known changes from the server the first time a Realm is
opened.
|
public Builder(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 Builder(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 SyncConfiguration.Builder encryptionKey(byte[] key)
key
- the encryption key.IllegalArgumentException
- if key is invalid.public SyncConfiguration.Builder schemaVersion(long schemaVersion)
Synced Realms only support additive schema changes which can be applied without requiring a manual
migration. The schema version will only be used as an indication to the underlying storage layer to remove
or add indexes. These will be recalculated if the provided schema version differ from the version in the
Realm file.
WARNING: There is no guarantee that the value inserted here is the same returned by BaseRealm.getVersion()
.
Due to the nature of synced Realms, the value can both be higher and lower.
schemaVersion
connected to the server for
the first time after this schemaVersion was used.
schemaVersion
connected to the server after
this Realm was created.
schemaVersion
- the schema version.IllegalArgumentException
- if schema version is invalid.public SyncConfiguration.Builder modules(Object baseModule, Object... additionalModules)
RealmModule
s. Using this method will replace the
current schema for this Realm with the schema defined by the provided modules.
A reference to the default Realm module containing all Realm classes in the project (but not dependencies),
can be found using Realm.getDefaultModule()
. Combining the schema from the app project and a library
dependency is thus done using the following code:
builder.modules(Realm.getDefaultMode(), new MyLibraryModule());
baseModule
- the first Realm module (required).additionalModules
- the additional Realm modulesIllegalArgumentException
- if any of the modules don't have the RealmModule
annotation.Realm.getDefaultModule()
public SyncConfiguration.Builder modules(Iterable<Object> modules)
RealmModule
s. Using this method will replace the
current schema for this Realm with the schema defined by the provided modules.
A reference to the default Realm module containing all Realm classes in the project (but not dependencies),
can be found using Realm.getDefaultModule()
. Combining the schema from the app project and a library
dependency is thus done using the following code:
builder.modules(Realm.getDefaultMode(), new MyLibraryModule());
modules
- list of modules tthe first Realm module (required).IllegalArgumentException
- if any of the modules don't have the RealmModule
annotation.Realm.getDefaultModule()
public SyncConfiguration.Builder addModule(Object module)
public SyncConfiguration.Builder rxFactory(RxObservableFactory factory)
RxObservableFactory
used to create Rx Observables from Realm objects.
The default factory is RealmObservableFactory
.factory
- factory to use.public SyncConfiguration.Builder initialData(Realm.Transaction transaction)
Realm
. This transaction will be executed only the first time
the Realm file is opened (created) or while migrating the data if
RealmConfiguration.Builder#deleteRealmIfMigrationNeeded()
is set.transaction
- transaction to execute.public SyncConfiguration.Builder inMemory()
Note that because in-memory Realms are not persisted, you must be sure to hold on to at least one non-closed reference to the in-memory Realm object with the specific name as long as you want the data to last.
public SyncConfiguration.Builder errorHandler(SyncSession.ErrorHandler errorHandler)
Only errors not handled by the defined SyncPolicy
will be reported to this error handler.
errorHandler
- error handler used to report back errors when communicating with the Realm Object Server.IllegalArgumentException
- if null
is given as an error handler.public SyncConfiguration.Builder clientResetHandler(SyncSession.ClientResetHandler handler)
handler
- custom handler in case of a Client Reset.public SyncConfiguration.Builder waitForInitialRemoteData()
Since downloading all changes can be an lengthy operation that might block the UI thread, Realms with this
setting enabled should only be opened on background threads or with
Realm.getInstanceAsync(RealmConfiguration, Realm.Callback)
on the UI thread.
This check is only enforced the first time a Realm is created. If you otherwise want to make sure a Realm
has the latest changes, use SyncSession.downloadAllServerChanges()
.
public SyncConfiguration.Builder waitForInitialRemoteData(long timeout, TimeUnit unit)
Since downloading all changes can be an lengthy operation that might block the UI thread, Realms with this
setting enabled should only be opened on background threads or with
Realm.getInstanceAsync(RealmConfiguration, Realm.Callback)
on the UI thread.
This check is only enforced the first time a Realm is created. If you otherwise want to make sure a Realm
has the latest changes, use SyncSession.downloadAllServerChanges()
.
timeout
- how long to wait for the download to complete before an DownloadingRealmInterruptedException
is thrown.unit
- the unit of time used to define the timeout.public SyncConfiguration.Builder readOnly()
IllegalStateException
.
This in particular mean that initialData(Realm.Transaction)
will not work in combination with a
read only Realm and setting this will result in a IllegalStateException
being thrown.
public SyncConfiguration.Builder compactOnLaunch()
DefaultCompactOnLaunchCallback
for details.public SyncConfiguration.Builder compactOnLaunch(CompactOnLaunchCallback compactOnLaunch)
compactOnLaunch
- a callback called when opening a Realm for the first time during the life of a process
to determine if it should be compacted before being returned to the user. It is passed
the total file size (data + free space) and the bytes used by data in the file.public SyncConfiguration.Builder urlPrefix(String urlPrefix)
urlPrefix
- The prefix to append to the sync connection url.public SyncConfiguration.Builder maxNumberOfActiveVersions(long number)
IllegalStateException
is thrown when
attempting to write more data.
Realm is capable of concurrently handling many different versions of Realm objects. This can happen if you have a Realm open on many different threads or are freezing objects while data is being written to the file.
Under normal circumstances this is not a problem, but if the number of active versions grow too large, it will have a negative effect on the filesize on disk. Setting this parameters can therefore be used to prevent uses of Realm that can result in very large Realms.
Note, the version number will also increase when changes from other devices are integrated on this device, so the number of active versions will also depend on what other devices writing to the same Realm are doing.
number
- the maximum number of active versions before an exception is thrown.public SyncConfiguration.Builder allowWritesOnUiThread(boolean allowWritesOnUiThread)
Realm.executeTransaction(io.realm.Realm.Transaction)
are allowed from the UI thread.
WARNING: Realm does not allow synchronous transactions to be run on the main thread unless users explicitly opt in
with this method. We recommend diverting calls to executeTransaction
to non-UI threads or, alternatively,
using Realm.executeTransactionAsync(io.realm.Realm.Transaction)
.
public SyncConfiguration.Builder allowQueriesOnUiThread(boolean allowQueriesOnUiThread)
RealmQueries
are allowed from the UI thread.
By default Realm allows queries on the main thread. However, by doing so your application may experience a drop of
frames or even ANRs. We recommend diverting queries to non-UI threads or, alternatively, using
RealmQuery.findAllAsync()
or RealmQuery.findFirstAsync()
.
public SyncConfiguration build()
SyncConfiguration
.IllegalStateException
- if the configuration parameters are invalid or inconsistent.