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

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

There is a newer version: 1.1.10
Show newest version
package org.enodeframework.messaging.impl;

import org.enodeframework.messaging.IMessage;

import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class QueueMessageDispatching {
    private final DefaultMessageDispatcher dispatcher;
    private final RootDispatching rootDispatching;
    private final ConcurrentLinkedQueue messageQueue;

    public QueueMessageDispatching(DefaultMessageDispatcher dispatcher, RootDispatching rootDispatching, List messages) {
        this.dispatcher = dispatcher;
        messageQueue = new ConcurrentLinkedQueue<>();
        messageQueue.addAll(messages);
        this.rootDispatching = rootDispatching;
        this.rootDispatching.addChildDispatching(this);
    }

    public IMessage dequeueMessage() {
        return messageQueue.poll();
    }

    public void onMessageHandled(IMessage message) {
        IMessage nextMessage = dequeueMessage();
        if (nextMessage == null) {
            rootDispatching.onChildDispatchingFinished(this);
            return;
        }
        dispatcher.dispatchSingleMessage(nextMessage, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy