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

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

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

import org.enodeframework.common.function.Action2;
import org.enodeframework.infrastructure.IObjectProxy;

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

public class QueuedHandler {
    private final Action2, T> dispatchToNextHandler;
    private final ConcurrentLinkedQueue handlerQueue;

    public QueuedHandler(List handlers, Action2, T> dispatchToNextHandler) {
        handlerQueue = new ConcurrentLinkedQueue<>();
        handlerQueue.addAll(handlers);
        this.dispatchToNextHandler = dispatchToNextHandler;
    }

    public T dequeueHandler() {
        return handlerQueue.poll();
    }

    public void onHandlerFinished(T handler) {
        T nextHandler = dequeueHandler();
        if (nextHandler != null) {
            dispatchToNextHandler.apply(this, nextHandler);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy