Proxy listeners of synched delegates (so they are removed when slot is removed)
This commit is contained in:
parent
6f60a4cd24
commit
07c2353911
@ -4,7 +4,7 @@ kotlin.code.style=official
|
||||
specifyKotlinAsDependency=false
|
||||
|
||||
projectGroup=ru.dbotthepony.kommons
|
||||
projectVersion=2.9.7
|
||||
projectVersion=2.9.8
|
||||
|
||||
guavaDepVersion=33.0.0
|
||||
gsonDepVersion=2.8.9
|
||||
|
@ -138,8 +138,9 @@ class DelegateSyncher : Observer {
|
||||
}
|
||||
|
||||
inner class Slot<V>(val delegate: ListenableDelegate<V>, val codec: StreamCodec<V>) : AbstractSlot(), ListenableDelegate<V> {
|
||||
private val l = delegate.addListener(Runnable {
|
||||
private val l = delegate.addListener(Consumer {
|
||||
markDirty()
|
||||
listeners.accept(it)
|
||||
})
|
||||
|
||||
init {
|
||||
@ -314,9 +315,36 @@ class DelegateSyncher : Observer {
|
||||
}
|
||||
|
||||
private val l = delegate.addListener(listener)
|
||||
private val listeners = CopyOnWriteArrayList<Listener>()
|
||||
|
||||
override fun remove0() {
|
||||
l.remove()
|
||||
listeners.clear()
|
||||
}
|
||||
|
||||
private inner class Listener(val listener: ListenableSet.SetListener<V>): Listenable.L {
|
||||
private var isRemoved = false
|
||||
|
||||
init {
|
||||
listeners.add(this)
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
if (!isRemoved) {
|
||||
isRemoved = true
|
||||
listeners.remove(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addListener(listener: ListenableSet.SetListener<V>): Listenable.L {
|
||||
check(!isRemoved.get()) { "This network slot was removed" }
|
||||
return Listener(listener)
|
||||
}
|
||||
|
||||
fun addListener(listener: Runnable): Listenable.L {
|
||||
check(!isRemoved.get()) { "This network slot was removed" }
|
||||
return Listener(ListenableSet.RunnableAdapter(listener))
|
||||
}
|
||||
|
||||
override fun read(stream: DataInputStream) {
|
||||
@ -391,9 +419,36 @@ class DelegateSyncher : Observer {
|
||||
}
|
||||
|
||||
private val l = delegate.addListener(listener)
|
||||
private val listeners = CopyOnWriteArrayList<Listener>()
|
||||
|
||||
override fun remove0() {
|
||||
l.remove()
|
||||
listeners.clear()
|
||||
}
|
||||
|
||||
private inner class Listener(val listener: ListenableMap.MapListener<K, V>): Listenable.L {
|
||||
private var isRemoved = false
|
||||
|
||||
init {
|
||||
listeners.add(this)
|
||||
}
|
||||
|
||||
override fun remove() {
|
||||
if (!isRemoved) {
|
||||
isRemoved = true
|
||||
listeners.remove(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun addListener(listener: ListenableMap.MapListener<K, V>): Listenable.L {
|
||||
check(!isRemoved.get()) { "This network slot was removed" }
|
||||
return Listener(listener)
|
||||
}
|
||||
|
||||
fun addListener(listener: Runnable): Listenable.L {
|
||||
check(!isRemoved.get()) { "This network slot was removed" }
|
||||
return Listener(ListenableMap.RunnableAdapter(listener))
|
||||
}
|
||||
|
||||
override fun read(stream: DataInputStream) {
|
||||
|
Loading…
Reference in New Issue
Block a user