GuavaDataStore.Builder
class GuavaDataStore.Builder<T : Any>
Builder class for a GuavaDataStore.
Summary
Public constructors |
|---|
<T : Any> Builder(serializer: Serializer<T>, produceFile: Callable<File>) |
<T : Any> Builder(Create a GuavaDataStoreBuilder with the |
Public functions |
|
|---|---|
GuavaDataStore.Builder<T> |
addDataMigration(dataMigration: DataMigration<T>)Add a DataMigration to the Datastore. |
GuavaDataStore<T> |
build()Build the DataStore. |
GuavaDataStore.Builder<T> |
Flag used to signal the creation of a multi-process DataStore using a MultiProcessCoordinator. |
GuavaDataStore.Builder<T> |
setCorruptionHandler(Sets the corruption handler to install into the DataStore. |
GuavaDataStore.Builder<T> |
setExecutor(executor: Executor)Sets the |
Public constructors
Builder
<T : Any> Builder(
context: Context,
fileName: String,
serializer: Serializer<T>
)
Create a GuavaDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by File(this.filesDir, "datastore/$fileName"). The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.
Either produceFile or context & name must be set, but not both. This is enforced by the two constructors.
| Parameters | |
|---|---|
context: Context |
the |
fileName: String |
the filename relative to Context.applicationContext.filesDir that |
serializer: Serializer<T> |
the |
Public functions
addDataMigration
fun addDataMigration(dataMigration: DataMigration<T>): GuavaDataStore.Builder<T>
Add a DataMigration to the Datastore. Migrations are run in the order they are added.
| Parameters | |
|---|---|
dataMigration: DataMigration<T> |
the migration to add |
| Returns | |
|---|---|
GuavaDataStore.Builder<T> |
this |
build
fun build(): GuavaDataStore<T>
Build the DataStore.
| Returns | |
|---|---|
GuavaDataStore<T> |
the DataStore with the provided parameters |
enableMultiProcess
fun enableMultiProcess(): GuavaDataStore.Builder<T>
Flag used to signal the creation of a multi-process DataStore using a MultiProcessCoordinator.
By default, the builder sets up a DataStore intended for single-application use. It prioritizes speed and is created using DataStoreFactory. However, if you anticipate any scenario where different parts of your system (even if they are just reading data) might access the DataStore at the same time from separate processes, the enableMultiProcess flag must be set to true. This ensures a MultiProcessDataStoreFactory is used, providing the necessary safeguards for concurrent access across multiple processes.
| Returns | |
|---|---|
GuavaDataStore.Builder<T> |
this |
setCorruptionHandler
fun setCorruptionHandler(
corruptionHandler: ReplaceFileCorruptionHandler<T>
): GuavaDataStore.Builder<T>
Sets the corruption handler to install into the DataStore.
This parameter is optional and defaults to no corruption handler.
| Parameters | |
|---|---|
corruptionHandler: ReplaceFileCorruptionHandler<T> |
the handler to invoke when there is a file corruption |
| Returns | |
|---|---|
GuavaDataStore.Builder<T> |
this |
setExecutor
fun setExecutor(executor: Executor): GuavaDataStore.Builder<T>
Sets the Executor used by the DataStore.
This parameter is optional and defaults to Dispatchers.IO.
| Returns | |
|---|---|
GuavaDataStore.Builder<T> |
this |