All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enodeframework.messaging.impl.QueueMessageDispatching.kt Maven / Gradle / Ivy

package org.enodeframework.messaging.impl

import org.enodeframework.messaging.Message
import java.util.concurrent.ConcurrentLinkedQueue

class QueueMessageDispatching(
    private val dispatcher: DefaultMessageDispatcher,
    rootDispatching: RootDispatching,
    messages: List
) {
    private val rootDispatching: RootDispatching
    private val messageQueue: ConcurrentLinkedQueue = ConcurrentLinkedQueue()

    init {
        messageQueue.addAll(messages)
        this.rootDispatching = rootDispatching
        this.rootDispatching.addChildDispatching(this)
    }

    fun dequeueMessage(): Message? {
        return messageQueue.poll()
    }

    fun onMessageHandled(message: Message?) {
        val nextMessage = dequeueMessage()
        if (nextMessage == null) {
            rootDispatching.onChildDispatchingFinished(this)
            return
        }
        dispatcher.dispatchSingleMessage(nextMessage, this)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy