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 and Description |
---|
SimpleDistributedQueue(CuratorFramework client,
String path) |
Modifier and Type | Method and Description |
---|---|
byte[] |
element()
Return the head of the queue without modifying the queue.
|
protected void |
ensurePath() |
boolean |
offer(byte[] data)
Inserts data into queue.
|
byte[] |
peek()
Returns the data at the first element of the queue, or null if the queue is empty.
|
byte[] |
poll()
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[] |
remove()
Attempts to remove the head of the queue and return it.
|
byte[] |
take()
Removes the head of the queue and returns it, blocks until it succeeds.
|
public SimpleDistributedQueue(CuratorFramework client, String path)
client
- the clientpath
- path to store queue nodespublic byte[] element() throws Exception
Exception
- errorsNoSuchElementException
- if the queue is emptypublic byte[] remove() throws Exception
Exception
- errorsNoSuchElementException
- if the queue is emptypublic byte[] take() throws Exception
Exception
- errorspublic boolean offer(byte[] data) throws Exception
data
- the dataException
- errorspublic byte[] peek() throws Exception
Exception
- errorspublic byte[] poll(long timeout, TimeUnit unit) throws Exception
timeout
- how long to wait before giving up, in units of
unitunit
- a TimeUnit determining how to interpret the
timeout parameterException
- errorspublic byte[] poll() throws Exception
Exception
- errorsCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.