T - The set value type.public class DistributedSet<T> extends io.atomix.resource.AbstractResource<DistributedSet<T>>
The distributed set is closely modeled on Java's HashSet. All methods present in the
Set interface are present in this interface. Set items are held in memory on each stateful node and
backed by replicated logs on disk, thus the size of a set is limited by the memory available to the smallest node in
the cluster. Internally, DistributedSet uses a HashMap to store set items in memory in the
replicated state machine.
To create a distributed set, use the getSet factory method:
DistributedSet<String> set = atomix.getSet("foo").get();
All set modification operations are linearizable, so items added to or removed from the set will be
immediately reflected from the perspective of all clients operating on the set. The set is shared by processes based
on the set name.
Sets support relaxed consistency levels for some read operations line size(ReadConsistency) and
contains(Object, ReadConsistency). By default, read operations on a set are linearizable but require some
level of communication between nodes.
| Modifier and Type | Class and Description |
|---|---|
static class |
DistributedSet.Events
Distributed set event types.
|
static class |
DistributedSet.ValueEvent<T>
Generic set value event.
|
| Constructor and Description |
|---|
DistributedSet(CopycatClient client,
Properties options) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Boolean> |
add(T value)
Adds a value to the set.
|
CompletableFuture<Boolean> |
add(T value,
Duration ttl)
Adds a value to the set with a TTL.
|
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<Boolean> |
isEmpty()
Checks whether the set is empty.
|
CompletableFuture<Boolean> |
isEmpty(io.atomix.resource.ReadConsistency consistency)
Checks whether the set is empty.
|
CompletableFuture<Iterator<T>> |
iterator()
Returns an Iterator over the values in the set.
|
CompletableFuture<Listener<DistributedSet.ValueEvent<T>>> |
onAdd(Consumer<DistributedSet.ValueEvent<T>> callback)
Registers a queue item add event listener.
|
CompletableFuture<Listener<DistributedSet.ValueEvent<T>>> |
onRemove(Consumer<DistributedSet.ValueEvent<T>> callback)
Registers a queue item remove event listener.
|
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 DistributedSet(CopycatClient client, Properties options)
public CompletableFuture<Boolean> add(T value)
value - The value to add.public CompletableFuture<Boolean> add(T value, Duration ttl)
value - The value to add.ttl - The time to live duration.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<Iterator<T>> iterator()
public CompletableFuture<Void> clear()
public CompletableFuture<Listener<DistributedSet.ValueEvent<T>>> onAdd(Consumer<DistributedSet.ValueEvent<T>> callback)
callback - The event listener callback to be called when an item is added to the queue.public CompletableFuture<Listener<DistributedSet.ValueEvent<T>>> onRemove(Consumer<DistributedSet.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.