GuavaDataStore.Builder
public final class GuavaDataStore.Builder<T extends Object>
Builder class for a GuavaDataStore
.
Summary
Public constructors |
---|
<T extends Object> Builder( Create a GuavaDataStoreBuilder with the |
Public methods |
|
---|---|
final @NonNull GuavaDataStore.Builder<@NonNull T> |
addDataMigration(@NonNull DataMigration<@NonNull T> dataMigration) Add a DataMigration to the Datastore. |
final @NonNull GuavaDataStore<@NonNull T> |
build() Build the DataStore. |
final @NonNull GuavaDataStore.Builder<@NonNull T> |
Flag used to signal the creation of a multi-process DataStore using a MultiProcessCoordinator. |
final @NonNull GuavaDataStore.Builder<@NonNull T> |
setCorruptionHandler( Sets the corruption handler to install into the DataStore. |
final @NonNull GuavaDataStore.Builder<@NonNull T> |
setExecutor(@NonNull Executor executor) Sets the |
Public constructors
Builder
public <T extends Object> Builder(
@NonNull Serializer<@NonNull T> serializer,
@NonNull Callable<@NonNull File> produceFile
)
Builder
public <T extends Object> Builder(
@NonNull Context context,
@NonNull String fileName,
@NonNull Serializer<@NonNull T> 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 | |
---|---|
@NonNull Context context |
the |
@NonNull String fileName |
the filename relative to Context.applicationContext.filesDir that |
@NonNull Serializer<@NonNull T> serializer |
the |
Public methods
addDataMigration
public final @NonNull GuavaDataStore.Builder<@NonNull T> addDataMigration(@NonNull DataMigration<@NonNull T> dataMigration)
Add a DataMigration to the Datastore. Migrations are run in the order they are added.
Parameters | |
---|---|
@NonNull DataMigration<@NonNull T> dataMigration |
the migration to add |
Returns | |
---|---|
@NonNull GuavaDataStore.Builder<@NonNull T> |
this |
build
public final @NonNull GuavaDataStore<@NonNull T> build()
Build the DataStore.
Returns | |
---|---|
@NonNull GuavaDataStore<@NonNull T> |
the DataStore with the provided parameters |
enableMultiProcess
public final @NonNull GuavaDataStore.Builder<@NonNull T> enableMultiProcess()
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 | |
---|---|
@NonNull GuavaDataStore.Builder<@NonNull T> |
this |
setCorruptionHandler
public final @NonNull GuavaDataStore.Builder<@NonNull T> setCorruptionHandler(
@NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler
)
Sets the corruption handler to install into the DataStore.
This parameter is optional and defaults to no corruption handler.
Parameters | |
---|---|
@NonNull ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler |
the handler to invoke when there is a file corruption |
Returns | |
---|---|
@NonNull GuavaDataStore.Builder<@NonNull T> |
this |
setExecutor
public final @NonNull GuavaDataStore.Builder<@NonNull T> setExecutor(@NonNull Executor executor)
Sets the Executor
used by the DataStore.
This parameter is optional and defaults to Dispatchers.IO
.
Returns | |
---|---|
@NonNull GuavaDataStore.Builder<@NonNull T> |
this |