@@ -51,13 +51,15 @@ open class Model(
51
51
* specified, must also specify [_parentModel]
52
52
*/
53
53
private val _parentProperty : String? = null ,
54
- private val initializationLock : Any = Any (),
54
+ private val modelSynchronizationLock : Any = Any (),
55
55
) : IEventNotifier<IModelChangedHandler> {
56
56
/* *
57
57
* A unique identifier for this model.
58
58
*/
59
59
var id: String
60
- get() = getStringProperty(::id.name)
60
+ get() = synchronized(modelSynchronizationLock) {
61
+ getStringProperty(::id.name)
62
+ }
61
63
set(value) {
62
64
setStringProperty(::id.name, value)
63
65
}
@@ -124,7 +126,7 @@ open class Model(
124
126
id : String? ,
125
127
model : Model ,
126
128
) {
127
- val newData = Collections .synchronizedMap( mutableMapOf<String , Any ?>() )
129
+ val newData = mutableMapOf<String , Any ?>()
128
130
129
131
for (item in model.data) {
130
132
if (item.value is Model ) {
@@ -140,7 +142,7 @@ open class Model(
140
142
newData[::id.name] = id
141
143
}
142
144
143
- synchronized(initializationLock ) {
145
+ synchronized(modelSynchronizationLock ) {
144
146
data.clear()
145
147
data.putAll(newData)
146
148
}
@@ -667,7 +669,7 @@ open class Model(
667
669
* @return The resulting [JSONObject].
668
670
*/
669
671
fun toJSON (): JSONObject {
670
- synchronized(initializationLock ) {
672
+ synchronized(modelSynchronizationLock ) {
671
673
val jsonObject = JSONObject ()
672
674
for (kvp in data) {
673
675
when (val value = kvp.value) {
@@ -699,5 +701,7 @@ open class Model(
699
701
override fun unsubscribe (handler : IModelChangedHandler ) = changeNotifier.unsubscribe(handler)
700
702
701
703
override val hasSubscribers: Boolean
702
- get() = changeNotifier.hasSubscribers
704
+ get() = synchronized(modelSynchronizationLock) {
705
+ changeNotifier.hasSubscribers
706
+ }
703
707
}
0 commit comments