com.godmonth.util.curator.queue.DistributedQueueFactory Maven / Gradle / Ivy
package com.godmonth.util.curator.queue;
import java.util.concurrent.Executor;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.queue.DistributedDelayQueue;
import org.apache.curator.framework.recipes.queue.QueueBuilder;
import org.apache.curator.framework.recipes.queue.QueueConsumer;
import org.apache.curator.framework.recipes.queue.QueueSerializer;
import org.springframework.beans.factory.annotation.Required;
public class DistributedQueueFactory {
private CuratorFramework curatorFramework;
private QueueConsumer queueConsumer;
private QueueSerializer queueSerializer;
private String path;
private Integer maxItems;
private Executor executor;
public DistributedDelayQueue create() {
QueueBuilder builder = QueueBuilder.builder(curatorFramework, queueConsumer, queueSerializer, path);
if (maxItems != null) {
builder = builder.maxItems(maxItems);
}
if (executor != null) {
builder = builder.executor(executor);
}
return builder.buildDelayQueue();
}
@Required
public void setCuratorFramework(CuratorFramework curatorFramework) {
this.curatorFramework = curatorFramework;
}
@Required
public void setQueueConsumer(QueueConsumer queueConsumer) {
this.queueConsumer = queueConsumer;
}
@Required
public void setQueueSerializer(QueueSerializer queueSerializer) {
this.queueSerializer = queueSerializer;
}
@Required
public void setPath(String path) {
this.path = path;
}
public void setMaxItems(Integer maxItems) {
this.maxItems = maxItems;
}
public void setExecutor(Executor executor) {
this.executor = executor;
}
}