T - The queue value type.public class DistributedQueue<T> extends io.atomix.resource.AbstractResource<DistributedQueue<T>>
The distributed queue is closely modeled on Java's queues. All methods present in the
Queue interface are present in this interface. Queued items are held in
memory on each stateful node and backed by replicated logs on disk, thus the size of a queue
is limited by the memory available to the smallest node in the cluster.
Internally, DistributedQueue uses an ArrayDeque to enqueue items
in memory in the replicated state machine. Operations submitted through this interface are
replicated and result in calling the associated method on the replicated ArrayDeque
on each stateful node.
To create a distributed queue, use the getQueue factory method:
DistributedQueue<String> queue = atomix.getQueue("foo").get();
All queue modification operations are linearizable, so items added to or removed from the queue will
be immediately reflected from the perspective of all clients operating on the queue. The queue is
shared by processes based on the queue name.
Queues support relaxed consistency levels for some read operations line size(ReadConsistency)
and contains(Object, ReadConsistency). By default, read operations on a queue are linearizable
but require some level of communication between nodes.
| Modifier and Type | Class and Description |
|---|---|
static class |
DistributedQueue.Events
Distributed queue event types.
|
static class |
DistributedQueue.ValueEvent<T>
Generic queue value event.
|
| Constructor and Description |
|---|
DistributedQueue(CopycatClient client,
Properties options) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Boolean> |
add(T value)
Adds a value to the set.
|
CompletableFuture<Void> |
clear()
Removes all values from the set.
|
CompletableFuture<Boolean> |
contains(Object value)
Checks whether the set contains a value.
|
CompletableFuture<Boolean> |
contains(Object value,
io.atomix.resource.ReadConsistency consistency)
Checks whether the set contains a value.
|
CompletableFuture<T> |
element()
Removes a value from the queue.
|
CompletableFuture<Boolean> |
isEmpty()
Checks whether the set is empty.
|
CompletableFuture<Boolean> |
isEmpty(io.atomix.resource.ReadConsistency consistency)
Checks whether the set is empty.
|
CompletableFuture<Boolean> |
offer(T value)
Adds a value to the queue.
|
CompletableFuture<Listener<DistributedQueue.ValueEvent<T>>> |
onAdd(Consumer<DistributedQueue.ValueEvent<T>> callback)
Registers a queue item add event listener.
|
CompletableFuture<Listener<DistributedQueue.ValueEvent<T>>> |
onRemove(Consumer<DistributedQueue.ValueEvent<T>> callback)
Registers a queue item remove event listener.
|
CompletableFuture<T> |
peek()
Removes a value from the queue.
|
CompletableFuture<T> |
poll()
Removes a value from the queue.
|
CompletableFuture<T> |
remove()
Removes a value from the queue.
|
CompletableFuture<Boolean> |
remove(T value)
Removes a value from the set.
|
CompletableFuture<Integer> |
size()
Gets the set count.
|
CompletableFuture<Integer> |
size(io.atomix.resource.ReadConsistency consistency)
Gets the set count.
|
public DistributedQueue(CopycatClient client, Properties options)
public CompletableFuture<Boolean> add(T value)
value - The value to add.public CompletableFuture<Boolean> offer(T value)
value - The value to add.public CompletableFuture<T> peek()
public CompletableFuture<T> poll()
public CompletableFuture<T> element()
public CompletableFuture<T> remove()
public CompletableFuture<Boolean> remove(T value)
value - The value to remove.public CompletableFuture<Boolean> contains(Object value)
value - The value to check.public CompletableFuture<Boolean> contains(Object value, io.atomix.resource.ReadConsistency consistency)
value - The value to check.consistency - The read consistency level.public CompletableFuture<Integer> size()
public CompletableFuture<Integer> size(io.atomix.resource.ReadConsistency consistency)
consistency - The read consistency level.public CompletableFuture<Boolean> isEmpty()
public CompletableFuture<Boolean> isEmpty(io.atomix.resource.ReadConsistency consistency)
consistency - The read consistency level.public CompletableFuture<Void> clear()
public CompletableFuture<Listener<DistributedQueue.ValueEvent<T>>> onAdd(Consumer<DistributedQueue.ValueEvent<T>> callback)
callback - The event listener callback to be called when an item is added to the queue.public CompletableFuture<Listener<DistributedQueue.ValueEvent<T>>> onRemove(Consumer<DistributedQueue.ValueEvent<T>> callback)
callback - The event listener callback to be called when an item is removed from the queue.Copyright © 2013–2017. All rights reserved.