org.enodeframework.messaging.impl.MultiMessageDispatching.kt Maven / Gradle / Ivy
package org.enodeframework.messaging.impl
import org.enodeframework.infrastructure.ObjectProxy
import org.enodeframework.infrastructure.TypeNameProvider
import org.enodeframework.messaging.Message
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentMap
class MultiMessageDispatching(
messages: List,
handlers: List,
rootDispatching: RootDispatching,
typeNameProvider: TypeNameProvider
) {
val messages: Array
private val handlerDict: ConcurrentMap
private val rootDispatching: RootDispatching
init {
this.messages = messages.toTypedArray()
handlerDict = ConcurrentHashMap()
handlers.forEach { objectProxy ->
handlerDict.putIfAbsent(
typeNameProvider.getTypeName(objectProxy.getInnerObject().javaClass),
objectProxy
)
}
this.rootDispatching = rootDispatching
this.rootDispatching.addChildDispatching(this)
}
fun removeHandledHandler(handlerTypeName: String) {
if (handlerDict.remove(handlerTypeName) != null) {
if (handlerDict.isEmpty()) {
rootDispatching.onChildDispatchingFinished(this)
}
}
}
}