-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDefaultLiveObjectsPlugin.kt
More file actions
35 lines (27 loc) · 1.01 KB
/
DefaultLiveObjectsPlugin.kt
File metadata and controls
35 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package io.ably.lib.objects
import io.ably.lib.realtime.ChannelState
import io.ably.lib.types.ProtocolMessage
import java.util.concurrent.ConcurrentHashMap
public class DefaultLiveObjectsPlugin(private val adapter: LiveObjectsAdapter) : LiveObjectsPlugin {
private val liveObjects = ConcurrentHashMap<String, DefaultLiveObjects>()
override fun getInstance(channelName: String): LiveObjects {
return liveObjects.getOrPut(channelName) { DefaultLiveObjects(channelName, adapter) }
}
override fun handle(msg: ProtocolMessage) {
val channelName = msg.channel
liveObjects[channelName]?.handle(msg)
}
override fun handleStateChange(channelName: String, state: ChannelState, hasObjects: Boolean) {
liveObjects[channelName]?.handleStateChange(state, hasObjects)
}
override fun dispose(channelName: String) {
liveObjects[channelName]?.dispose()
liveObjects.remove(channelName)
}
override fun dispose() {
liveObjects.values.forEach {
it.dispose()
}
liveObjects.clear()
}
}