All Downloads are FREE. Search and download functionalities are using the official Maven repository.

flag.FlagConfigStorage.kt Maven / Gradle / Ivy

package com.amplitude.experiment.flag

import com.amplitude.experiment.evaluation.FlagConfig
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.read
import kotlin.concurrent.write

internal interface FlagConfigStorage {
    fun get(flagKey: String): FlagConfig?
    fun getAll(): Map
    fun overwrite(flagConfigs: Map)
}

internal class InMemoryFlagConfigStorage : FlagConfigStorage {

    private val lock = ReentrantReadWriteLock()
    private val flagConfigStore = mutableMapOf()

    override fun get(flagKey: String): FlagConfig? {
        lock.read {
            return flagConfigStore[flagKey]
        }
    }

    override fun getAll(): Map {
        lock.read {
            return flagConfigStore.toMap()
        }
    }

    override fun overwrite(flagConfigs: Map) {
        lock.write {
            flagConfigStore.clear()
            flagConfigStore.putAll(flagConfigs)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy