public class QueueBuilder<T> extends Object
DistributedQueue
and DistributedPriorityQueue
Modifier and Type | Method and Description |
---|---|
DistributedDelayQueue<T> |
buildDelayQueue()
Build a
DistributedDelayQueue from the current builder values. |
static <T> QueueBuilder<T> |
builder(CuratorFramework client,
QueueConsumer<T> consumer,
QueueSerializer<T> serializer,
String queuePath)
Allocate a new builder
|
DistributedIdQueue<T> |
buildIdQueue()
Build a
DistributedIdQueue from the current builder values |
DistributedPriorityQueue<T> |
buildPriorityQueue(int minItemsBeforeRefresh)
Build a
DistributedPriorityQueue from the current builder values. |
DistributedQueue<T> |
buildQueue()
Build a
DistributedQueue from the current builder values |
QueueBuilder<T> |
executor(Executor executor)
Change the executor used.
|
QueueBuilder<T> |
finalFlushTime(int time,
TimeUnit unit)
Sets an amount of time to call
DistributedQueue.flushPuts(long, TimeUnit) when the
queue is closed. |
QueueBuilder<T> |
lockPath(String path)
Without a lock set, queue items are removed before being sent to the queue consumer.
|
QueueBuilder<T> |
maxItems(int maxItems)
By default, the various queues are unbounded.
|
QueueBuilder<T> |
putInBackground(boolean putInBackground)
By default, messages are added in the background.
|
QueueBuilder<T> |
threadFactory(ThreadFactory factory)
Change the thread factory used.
|
public static <T> QueueBuilder<T> builder(CuratorFramework client, QueueConsumer<T> consumer, QueueSerializer<T> serializer, String queuePath)
client
- the curator clientconsumer
- functor to consume messages - NOTE: pass null
to make this a producer-only queueserializer
- serializer to use for itemsqueuePath
- path to store queuepublic DistributedQueue<T> buildQueue()
DistributedQueue
from the current builder valuespublic DistributedIdQueue<T> buildIdQueue()
DistributedIdQueue
from the current builder valuespublic DistributedPriorityQueue<T> buildPriorityQueue(int minItemsBeforeRefresh)
Build a DistributedPriorityQueue
from the current builder values.
When the priority
queue detects an item addition/removal, it will stop processing its current list of items and
refresh the list. minItemsBeforeRefresh
modifies this. It determines the minimum
number of items from the active list that will get processed before a refresh.
Due to a quirk in the way ZooKeeper notifies changes, the queue will get an item addition/remove
notification after every item is processed. This can lead to poor performance. Set
minItemsBeforeRefresh
to the value your application can tolerate being out of sync.
For example: if the queue sees 10 items to process, it will end up making 10 calls to ZooKeeper
to check status. You can control this by setting minItemsBeforeRefresh
to 10 (or more)
and the queue will only refresh with ZooKeeper after 10 items are processed
minItemsBeforeRefresh
- minimum items to process before refreshing the item listpublic DistributedDelayQueue<T> buildDelayQueue()
Build a DistributedDelayQueue
from the current builder values.
public QueueBuilder<T> threadFactory(ThreadFactory factory)
Executors.defaultThreadFactory()
factory
- new thread factory to usepublic QueueBuilder<T> executor(Executor executor)
MoreExecutors#directExectutor()
executor
- new executor to usepublic QueueBuilder<T> lockPath(String path)
Without a lock set, queue items are removed before being sent to the queue consumer. This can result in message loss if the consumer fails to complete the message or the process dies.
Use a lock to make the message recoverable. A lock is held while the message is being processed - this prevents other processes from taking the message. The message will not be removed from the queue until the consumer functor returns. Thus, if there is a failure or the process dies, the message will get sent to another process. There is a small performance penalty for this behavior however.
path
- path for the lockpublic QueueBuilder<T> maxItems(int maxItems)
put
methods will block when the
number of items in the queue approaches maxItems
. NOTE: maxItems
cannot
be exactly achieved. The only guarantee is that approximately maxItems
will cause
puts to block.maxItems
- the upper bound for the queuepublic QueueBuilder<T> putInBackground(boolean putInBackground)
putInBackground
- true to put in the background (default). false to put in the foreground.public QueueBuilder<T> finalFlushTime(int time, TimeUnit unit)
DistributedQueue.flushPuts(long, TimeUnit)
when the
queue is closed. The default is 5 seconds. Pass 0 to turn flushing on close off.time
- timeunit
- the unitCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.