@@ -51,13 +51,15 @@ open class Model(
5151 * specified, must also specify [_parentModel]
5252 */
5353 private val _parentProperty : String? = null ,
54- private val initializationLock : Any = Any (),
54+ private val modelSynchronizationLock : Any = Any (),
5555) : IEventNotifier<IModelChangedHandler> {
5656 /* *
5757 * A unique identifier for this model.
5858 */
5959 var id: String
60- get() = getStringProperty(::id.name)
60+ get() = synchronized(modelSynchronizationLock) {
61+ getStringProperty(::id.name)
62+ }
6163 set(value) {
6264 setStringProperty(::id.name, value)
6365 }
@@ -124,7 +126,7 @@ open class Model(
124126 id : String? ,
125127 model : Model ,
126128 ) {
127- val newData = Collections .synchronizedMap( mutableMapOf<String , Any ?>() )
129+ val newData = mutableMapOf<String , Any ?>()
128130
129131 for (item in model.data) {
130132 if (item.value is Model ) {
@@ -140,7 +142,7 @@ open class Model(
140142 newData[::id.name] = id
141143 }
142144
143- synchronized(initializationLock ) {
145+ synchronized(modelSynchronizationLock ) {
144146 data.clear()
145147 data.putAll(newData)
146148 }
@@ -667,7 +669,7 @@ open class Model(
667669 * @return The resulting [JSONObject].
668670 */
669671 fun toJSON (): JSONObject {
670- synchronized(initializationLock ) {
672+ synchronized(modelSynchronizationLock ) {
671673 val jsonObject = JSONObject ()
672674 for (kvp in data) {
673675 when (val value = kvp.value) {
@@ -699,5 +701,7 @@ open class Model(
699701 override fun unsubscribe (handler : IModelChangedHandler ) = changeNotifier.unsubscribe(handler)
700702
701703 override val hasSubscribers: Boolean
702- get() = changeNotifier.hasSubscribers
704+ get() = synchronized(modelSynchronizationLock) {
705+ changeNotifier.hasSubscribers
706+ }
703707}
0 commit comments