Class SimpleDistributedQueue

java.lang.Object
org.apache.curator.framework.recipes.queue.SimpleDistributedQueue

public class SimpleDistributedQueue extends Object

Drop in replacement for: org.apache.zookeeper.recipes.queue.DistributedQueue that is part of the ZooKeeper distribution

This class is data compatible with the ZK version. i.e. it uses the same naming scheme so it can read from an existing queue

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Return the head of the queue without modifying the queue.
    protected void
     
    boolean
    offer(byte[] data)
    Inserts data into queue.
    byte[]
    Returns the data at the first element of the queue, or null if the queue is empty.
    byte[]
    Attempts to remove the head of the queue and return it.
    byte[]
    poll(long timeout, TimeUnit unit)
    Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
    byte[]
    Attempts to remove the head of the queue and return it.
    byte[]
    Removes the head of the queue and returns it, blocks until it succeeds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SimpleDistributedQueue

      public SimpleDistributedQueue(CuratorFramework client, String path)
      Parameters:
      client - the client
      path - path to store queue nodes
  • Method Details

    • element

      public byte[] element() throws Exception
      Return the head of the queue without modifying the queue.
      Returns:
      the data at the head of the queue.
      Throws:
      Exception - errors
      NoSuchElementException - if the queue is empty
    • remove

      public byte[] remove() throws Exception
      Attempts to remove the head of the queue and return it.
      Returns:
      The former head of the queue
      Throws:
      Exception - errors
      NoSuchElementException - if the queue is empty
    • take

      public byte[] take() throws Exception
      Removes the head of the queue and returns it, blocks until it succeeds.
      Returns:
      The former head of the queue
      Throws:
      Exception - errors
    • offer

      public boolean offer(byte[] data) throws Exception
      Inserts data into queue.
      Parameters:
      data - the data
      Returns:
      true if data was successfully added
      Throws:
      Exception - errors
    • peek

      public byte[] peek() throws Exception
      Returns the data at the first element of the queue, or null if the queue is empty.
      Returns:
      data at the first element of the queue, or null.
      Throws:
      Exception - errors
    • poll

      public byte[] poll(long timeout, TimeUnit unit) throws Exception
      Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
      Parameters:
      timeout - how long to wait before giving up, in units of unit
      unit - a TimeUnit determining how to interpret the timeout parameter
      Returns:
      the head of this queue, or null if the specified waiting time elapses before an element is available
      Throws:
      Exception - errors
    • poll

      public byte[] poll() throws Exception
      Attempts to remove the head of the queue and return it. Returns null if the queue is empty.
      Returns:
      Head of the queue or null.
      Throws:
      Exception - errors
    • ensurePath

      protected void ensurePath() throws Exception
      Throws:
      Exception