GuavaDataStore.Builder


class GuavaDataStore.BuilderAny>

Builder class for a GuavaDataStore.

Summary

Public constructors

Any> Builder(serializer: Serializer, produceFile: Callable<File>)
Any> Builder(
    context: Context,
    fileName: String,
    serializer: Serializer
)

Create a GuavaDataStoreBuilder with the Context and name from which to derive the DataStore file.

Public functions

GuavaDataStore.Builder

Add a DataMigration to the Datastore.

GuavaDataStore

Build the DataStore.

GuavaDataStore.Builder

Flag used to signal the creation of a multi-process DataStore using a MultiProcessCoordinator.

GuavaDataStore.Builder

Sets the corruption handler to install into the DataStore.

GuavaDataStore.Builder
setExecutor(executor: Executor)

Sets the Executor used by the DataStore.

Public constructors

Builder

Any> Builder(serializer: Serializer, produceFile: Callable<File>)

Builder

Any> Builder(
    context: Context,
    fileName: String,
    serializer: Serializer
)

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 Context from which we retrieve files directory.

fileName: String

the filename relative to Context.applicationContext.filesDir that DataStore acts on. The File is obtained from dataStoreFile. It is created in the "/datastore" subdirectory.

serializer: Serializer

the Serializer for the type that this DataStore acts on.

Public functions

addDataMigration

Added in 1.2.0-alpha02
fun addDataMigration(dataMigration: DataMigration): GuavaDataStore.Builder

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

Parameters
dataMigration: DataMigration

the migration to add

Returns
GuavaDataStore.Builder

this

build

Added in 1.2.0-alpha02
fun build(): GuavaDataStore

Build the DataStore.

Returns
GuavaDataStore

the DataStore with the provided parameters

enableMultiProcess

Added in 1.2.0-alpha02
fun enableMultiProcess(): GuavaDataStore.Builder

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

this

setCorruptionHandler

Added in 1.2.0-alpha02
fun setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler
): GuavaDataStore.Builder

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

Parameters
corruptionHandler: ReplaceFileCorruptionHandler

the handler to invoke when there is a file corruption

Returns
GuavaDataStore.Builder

this

setExecutor

Added in 1.2.0-alpha02
fun setExecutor(executor: Executor): GuavaDataStore.Builder

Sets the Executor used by the DataStore.

This parameter is optional and defaults to Dispatchers.IO.

Parameters
executor: Executor

the executor to be used by DataStore

Returns
GuavaDataStore.Builder

this