Skip to content

Commit 3319bb2

Browse files
committed
Remove JVM dependency regarding synchronization
Remove @synchronized annotation and CopyOnWriteArraySet usage. They were used just to prevent users from common errors. StateMachine cannot be used from multiple thread without external synchronisation as mentioned in docs same as before. Removing JVM dependency is a next step to Kotlin multiplatform support.
1 parent f1cd987 commit 3319bb2

File tree

4 files changed

+3
-8
lines changed

4 files changed

+3
-8
lines changed

kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/BaseStateImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ package ru.nsk.kstatemachine
22

33
import ru.nsk.kstatemachine.TreeAlgorithms.findPathFromTargetToLca
44
import ru.nsk.kstatemachine.visitors.GetActiveStatesVisitor
5-
import java.util.concurrent.CopyOnWriteArraySet
65

76
open class BaseStateImpl(override val name: String?, override val childMode: ChildMode) : InternalState() {
87

98
private class Data {
10-
val listeners = CopyOnWriteArraySet<IState.Listener>()
9+
val listeners = mutableSetOf<IState.Listener>()
1110
val states = mutableSetOf<InternalState>()
1211
var initialState: InternalState? = null
1312

kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/DefaultTransition.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package ru.nsk.kstatemachine
22

3-
import java.util.concurrent.CopyOnWriteArraySet
4-
53
open class DefaultTransition<E : Event>(
64
override val name: String?,
75
override val eventMatcher: EventMatcher<E>,
86
sourceState: IState
97
) : InternalTransition<E> {
10-
private val _listeners = CopyOnWriteArraySet<Transition.Listener>()
8+
private val _listeners = mutableSetOf<Transition.Listener>()
119
override val listeners: Collection<Transition.Listener> get() = _listeners
1210
override val sourceState = sourceState as InternalState
1311

kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/StateMachine.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface StateMachine : State {
99
var logger: Logger
1010
var ignoredEventHandler: IgnoredEventHandler
1111
var pendingEventHandler: PendingEventHandler
12+
1213
/**
1314
* If machine catches exception from client code (listeners callbacks) it stores it until event processing
1415
* completes, and passes it to this handler. That keeps machine in well-defined predictable state and allows

kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/StateMachineImpl.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ internal class StateMachineImpl(name: String?, childMode: ChildMode, override va
4848
override fun log(message: String) {}
4949
}
5050

51-
@Synchronized
5251
override fun <L : StateMachine.Listener> addListener(listener: L): L {
5352
require(_machineListeners.add(listener)) { "$listener is already added" }
5453
return listener
5554
}
5655

57-
@Synchronized
5856
override fun removeListener(listener: StateMachine.Listener) {
5957
_machineListeners.remove(listener)
6058
}
@@ -104,7 +102,6 @@ internal class StateMachineImpl(name: String?, childMode: ChildMode, override va
104102
}
105103
}
106104

107-
@Synchronized
108105
override fun processEvent(event: Event, argument: Any?) {
109106
check(!isDestroyed) { "$this is already destroyed" }
110107
check(isRunning) { "$this is not started, call start() first" }

0 commit comments

Comments
 (0)