org.enodeframework.messaging.impl.QueuedHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enode Show documentation
Show all versions of enode Show documentation
The enodeframework core implementation.
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);
}
}
}