r.0.9.1.source-code.Configuration.kt Maven / Gradle / Ivy
The newest version!
package se.wollan.tolr
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
/**
* @param locallyExposedHostname only relevant to specify for nodes that will receive incoming replication requests
*/
data class Configuration(
val localNodeId: NodeId,
private val remoteHostnames: Set,
val retryDelayOnFailure: Duration = 10.seconds,
val heartbeatTriggerInterval: Duration = 5.minutes,
val pageSize: PageSize = PageSize.default,
val locallyExposedHostname: RemoteHostname = RemoteHostname(localNodeId.value)
) {
val remoteHostnamesSafe = remoteHostnames - locallyExposedHostname - RemoteHostname(localNodeId.value)
}
interface ConfigurationProvider {
suspend fun getConfiguration(): Configuration
}
class StaticConfigurationProvider(private val configuration: Configuration) : ConfigurationProvider {
override suspend fun getConfiguration(): Configuration = configuration
}
/**
* This class in not thread-safe as the initial configuration is supposed to get resolved indirectly with
* the start-lock inside [TotalOrderedLog.startReplicating].
*/
internal class CachedConfigurationProviderDecorator(private val inner: ConfigurationProvider) : ConfigurationProvider {
@Volatile
private var cachedConfiguration: Configuration? = null
override suspend fun getConfiguration(): Configuration {
cachedConfiguration?.let { return it }
val configuration = inner.getConfiguration()
cachedConfiguration = configuration
return configuration
}
}