From 4c5f0e9e43cd26d87cd3ae8be3a2113906bcd2cd Mon Sep 17 00:00:00 2001 From: darksnake Date: Sun, 13 Dec 2020 19:58:20 +0300 Subject: [PATCH] Add synchronization to Config listeners --- build.gradle.kts | 2 +- .../src/commonMain/kotlin/hep/dataforge/meta/Config.kt | 4 ++++ .../src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt | 2 -- gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 734da38d..453064e8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("ru.mipt.npm.project") } -val dataforgeVersion by extra("0.2.1-dev-3") +val dataforgeVersion by extra("0.2.1-dev-4") val bintrayRepo by extra("dataforge") val githubProject by extra("dataforge-core") diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt index 2674d0a8..6dc8c441 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt @@ -10,6 +10,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlin.collections.set +import kotlin.jvm.Synchronized //TODO add validator to configuration @@ -31,6 +32,7 @@ public class Config() : AbstractMutableMeta(), ObservableMeta { private val listeners = HashSet() + @Synchronized private fun itemChanged(name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) { listeners.forEach { it.action(name, oldItem, newItem) } } @@ -38,6 +40,7 @@ public class Config() : AbstractMutableMeta(), ObservableMeta { /** * Add change listener to this meta. Owner is declared to be able to remove listeners later. Listener without owner could not be removed */ + @Synchronized override fun onChange(owner: Any?, action: (Name, MetaItem<*>?, MetaItem<*>?) -> Unit) { listeners.add(MetaListener(owner, action)) } @@ -45,6 +48,7 @@ public class Config() : AbstractMutableMeta(), ObservableMeta { /** * Remove all listeners belonging to given owner */ + @Synchronized override fun removeListener(owner: Any?) { listeners.removeAll { it.owner === owner } } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt index 7903ba87..658f77cc 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MutableMeta.kt @@ -4,8 +4,6 @@ import hep.dataforge.names.* public interface MutableMeta> : MetaNode, MutableItemProvider { override val items: Map> -// fun onChange(owner: Any? = null, action: (Name, MetaItem<*>?, MetaItem<*>?) -> Unit) -// fun removeListener(owner: Any? = null) } /** diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 12d38de6..4d9ca164 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists