android-components / mozilla.components.service.glean.storages / GenericScalarStorageEngine

# GenericScalarStorageEngine

`abstract class GenericScalarStorageEngine<ScalarType> : StorageEngine` (source)

A base class for 'scalar' like metrics. This allows sharing the common store managing and lifetime behaviours.

### Constructors

<init> | `GenericScalarStorageEngine()` A base class for 'scalar' like metrics. This allows sharing the common store managing and lifetime behaviours.

### Properties

applicationContext | `open lateinit var applicationContext: Context`
dataStores | `val dataStores: Array<GenericStorageMap<ScalarType>>`
logger | `abstract val logger: Logger`
userLifetimeStorage | `val userLifetimeStorage: SharedPreferences`

### Functions

deserializeSingleMetric | `abstract fun deserializeSingleMetric(value: Any?): ScalarType?` Implementor's provided function to convert deserialized 'user' lifetime data to the destination ScalarType.
deserializeUserLifetime | `open fun deserializeUserLifetime(): SharedPreferences` Deserialize the metrics with a lifetime = User that are on disk. This will be called the first time a metric is used or before a snapshot is taken.
getSnapshot | `fun getSnapshot(storeName: String, clearStore: Boolean): GenericDataStorage<ScalarType>?` Retrieves the recorded metric data for the provided store name.
getSnapshotAsJSON | `open fun getSnapshotAsJSON(storeName: String, clearStore: Boolean): Any?` Get a snapshot of the stored data as a JSON object.
recordScalar | `fun recordScalar(stores: List<String>, category: String, name: String, lifetime: Lifetime, value: ScalarType): Unit` Helper function for the derived classes. It can be used to record simple scalars to the internal storage.
serializeSingleMetric | `fun serializeSingleMetric(value: ScalarType): String?` Implementor's provided function to serialized 'user' lifetime data to String.

### Inheritors

StringsStorageEngineImplementation | `open class StringsStorageEngineImplementation : GenericScalarStorageEngine<String>`
UuidsStorageEngineImplementation | `open class UuidsStorageEngineImplementation : GenericScalarStorageEngine<UUID>`