RemoteSource

class RemoteSource(initial: Map<String, String> = emptyMap(), val keyFormat: KeyFormat = KeyFormat.DOT_NOTATION, val fallbackKeyFormats: List<KeyFormat> = listOf(KeyFormat.SCREAMING_SNAKE), val name: String = "RemoteSource") : ReloadableSource(source)

A source whose values are pushed in by the app, typically from a remote config service. It works with any provider: fetch the values, then call update. Each change is reported on changes, so ReloadableConfig.watch reloads the config:

val remote = RemoteSource(name = "Firebase")
val appConfig = ReloadableConfig.load(load = { loadAppConfig() }) {
sources {
+remote // first, so remote values override the local defaults
+TomlSource.fromResource("config.toml")
}
}
appConfig.watch(scope, remote)

// Whenever the provider has new values
remote.update(fetchedValues)

Keys use keyFormat (dot notation by default, e.g. server.port) and are matched case-insensitively, like the file sources.

Constructors

Link copied to clipboard
constructor(initial: Map<String, String> = emptyMap(), keyFormat: KeyFormat = KeyFormat.DOT_NOTATION, fallbackKeyFormats: List<KeyFormat> = listOf(KeyFormat.SCREAMING_SNAKE), name: String = "RemoteSource")

Properties

Link copied to clipboard
open override val changes: Flow<Unit>

Emits once when collection starts and again after each update that changed the values, so updates made before ReloadableConfig.watch starts collecting are not missed. Updating to equal values emits nothing.

Link copied to clipboard
open override val fallbackKeyFormats: List<KeyFormat>
Link copied to clipboard
open override val keyFormat: KeyFormat
Link copied to clipboard
open override val name: String
Link copied to clipboard

The current values.

Functions

Link copied to clipboard
open override fun children(key: String): Map<String, String>?
Link copied to clipboard
open override fun get(key: String): String?
Link copied to clipboard
fun update(values: Map<String, String>)

Replaces all values. Keys missing from values fall through to the next source. A reload that runs during an update may read some keys before it and some after; the reload the update triggers then reads the new values.