com.netflix.curator.framework.recipes.queue
Class DistributedQueue<T>

java.lang.Object
  extended by com.netflix.curator.framework.recipes.queue.DistributedQueue<T>
All Implemented Interfaces:
Closeable

public class DistributedQueue<T>
extends Object
implements Closeable

An implementation of the Distributed Queue ZK recipe. Items put into the queue are guaranteed to be ordered (by means of ZK's PERSISTENT_SEQUENTIAL node).

Guarantees:

  • If a single consumer takes items out of the queue, they will be ordered FIFO. i.e. if ordering is important, use a LeaderSelector to nominate a single consumer.
  • Unless a QueueBuilder.lockPath(String) is used, there is only guaranteed processing of each message to the point of receipt by a given instance. If an instance receives an item from the queue but dies while processing it, the item will be lost. If you need message recoverability, use a QueueBuilder.lockPath(String)

  • Method Summary
     void close()
               
     boolean flushPuts(long waitTime, TimeUnit timeUnit)
              Wait until any pending puts are committed
     void put(T item)
              Add an item into the queue.
     void putMulti(MultiItem<T> items)
              Add a set of items into the queue.
     void setErrorMode(ErrorMode newErrorMode)
              Used when the queue is created with a QueueBuilder.lockPath(String).
     void start()
              Start the queue.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Method Detail

    start

    public void start()
               throws Exception
    Start the queue. No other methods work until this is called

    Throws:
    Exception - startup errors

    setErrorMode

    public void setErrorMode(ErrorMode newErrorMode)
    Used when the queue is created with a QueueBuilder.lockPath(String). Determines the behavior when the queue consumer throws an exception

    Parameters:
    newErrorMode - the new error mode (the default is ErrorMode.REQUEUE

    flushPuts

    public boolean flushPuts(long waitTime,
                             TimeUnit timeUnit)
                      throws InterruptedException
    Wait until any pending puts are committed

    Parameters:
    waitTime - max wait time
    timeUnit - time unit
    Returns:
    true if the flush was successful, false if it timed out first
    Throws:
    InterruptedException - if thread was interrupted

    close

    public void close()
               throws IOException
    Specified by:
    close in interface Closeable
    Throws:
    IOException

    put

    public void put(T item)
             throws Exception
    Add an item into the queue. Adding is done in the background - thus, this method will return quickly.

    Parameters:
    item - item to add
    Throws:
    Exception - connection issues

    putMulti

    public void putMulti(MultiItem<T> items)
                  throws Exception
    Add a set of items into the queue. Adding is done in the background - thus, this method will return quickly.

    Parameters:
    items - items to add
    Throws:
    Exception - connection issues


    Copyright © 2012. All Rights Reserved.