Skip to content

Commit

Permalink
Revert "Add additional synchronized blocks to get methods"
Browse files Browse the repository at this point in the history
This reverts commit df534d5.
  • Loading branch information
jennantilla committed Nov 3, 2023
1 parent df534d5 commit 1847cb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ open class Model(
* specified, must also specify [_parentModel]
*/
private val _parentProperty: String? = null,
private val modelSynchronizationLock: Any = Any(),
private val initializationLock: Any = Any(),
) : IEventNotifier<IModelChangedHandler> {
/**
* A unique identifier for this model.
*/
var id: String
get() = synchronized(modelSynchronizationLock) {
getStringProperty(::id.name)
}
get() = getStringProperty(::id.name)
set(value) {
setStringProperty(::id.name, value)
}
Expand Down Expand Up @@ -126,7 +124,7 @@ open class Model(
id: String?,
model: Model,
) {
val newData = mutableMapOf<String, Any?>()
val newData = Collections.synchronizedMap(mutableMapOf<String, Any?>())

for (item in model.data) {
if (item.value is Model) {
Expand All @@ -142,7 +140,7 @@ open class Model(
newData[::id.name] = id
}

synchronized(modelSynchronizationLock) {
synchronized(initializationLock) {
data.clear()
data.putAll(newData)
}
Expand Down Expand Up @@ -669,7 +667,7 @@ open class Model(
* @return The resulting [JSONObject].
*/
fun toJSON(): JSONObject {
synchronized(modelSynchronizationLock) {
synchronized(initializationLock) {
val jsonObject = JSONObject()
for (kvp in data) {
when (val value = kvp.value) {
Expand Down Expand Up @@ -701,7 +699,5 @@ open class Model(
override fun unsubscribe(handler: IModelChangedHandler) = changeNotifier.unsubscribe(handler)

override val hasSubscribers: Boolean
get() = synchronized(modelSynchronizationLock) {
changeNotifier.hasSubscribers
}
get() = changeNotifier.hasSubscribers
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ abstract class ModelStore<TModel>(
}

override fun get(id: String): TModel? {
synchronized(models) {
return models.firstOrNull { it.id == id }
}
return models.firstOrNull { it.id == id }
}

override fun remove(
Expand Down Expand Up @@ -194,9 +192,5 @@ abstract class ModelStore<TModel>(
override fun unsubscribe(handler: IModelStoreChangeHandler<TModel>) = changeSubscription.unsubscribe(handler)

override val hasSubscribers: Boolean
get() {
synchronized(changeSubscription) {
return changeSubscription.hasSubscribers
}
}
get() = changeSubscription.hasSubscribers
}

0 comments on commit 1847cb4

Please sign in to comment.