Interface ReplicatedSet<E>

Type Parameters:
E - The type of elements.
All Superinterfaces:
Iterable<E>, kalix.replicatedentity.ReplicatedData

public interface ReplicatedSet<E> extends kalix.replicatedentity.ReplicatedData, Iterable<E>
A Replicated Set that allows both the addition and removal of elements in a set.

A removal can only be done if all of the additions that added the key have been seen by this node. This means that, for example if node 1 adds element A, and node 2 also adds element A, then node 1's addition is replicated to node 3, and node 3 deletes it before node 2's addition is replicated, then the element will still be in the map because node 2's addition had not yet been observed by node 3, and will cause the element to be re-added when node 3 receives it. However, if both * additions had been replicated to node 3, then the element will be removed.

Care needs to be taken to ensure that the serialized value of elements in the set is stable. For example, if using protobufs, the serialized value of any maps contained in the protobuf is not stable, and can yield a different set of bytes for the same logically equal element. Hence maps should be avoided. Additionally, some changes in protobuf schemas which are backwards compatible from a protobuf perspective, such as changing from sint32 to int32, do result in different serialized bytes, and so must be avoided.

  • Method Details

    • size

      int size()
      Get the number of elements in this set (its cardinality).
      Returns:
      the number of elements in the set
    • isEmpty

      boolean isEmpty()
      Check whether this set is empty.
      Returns:
      true if this set contains no elements
    • elements

      Set<E> elements()
      Elements of this set as a regular Set.
      Returns:
      elements as Set
    • contains

      boolean contains(E element)
      Check whether this set contains the given element.
      Parameters:
      element - element whose presence in this set is to be tested
      Returns:
      true if this set contains the specified element
    • add

      ReplicatedSet<E> add(E element)
      Add an element to this set if it is not already present.
      Parameters:
      element - element to be added to this set
      Returns:
      a new set with the additional element, or this unchanged set
    • remove

      ReplicatedSet<E> remove(E element)
      Remove an element from this set if it is present.
      Parameters:
      element - element to be removed from this set
      Returns:
      a new set without the removed element, or this unchanged set
    • containsAll

      boolean containsAll(Collection<E> elements)
      Check whether this set contains all the given elements.
      Parameters:
      elements - collection to be checked for containment in this set
      Returns:
      true if this set contains all the given elements
    • addAll

      ReplicatedSet<E> addAll(Collection<E> elements)
      Add elements to this set if they're not already present.

      Effectively the union of two sets.

      Parameters:
      elements - collection containing elements to be added to this set
      Returns:
      a new set with the additional elements, or this unchanged set
    • retainAll

      ReplicatedSet<E> retainAll(Collection<E> elements)
      Retain only the elements that are contained in the given collection.

      Effectively the intersection of two sets.

      Parameters:
      elements - collection containing elements to be retained in this set
      Returns:
      a new set with the retained elements, or this unchanged set
    • removeAll

      ReplicatedSet<E> removeAll(Collection<E> elements)
      Remove elements from this set if they're present.

      Effectively the asymmetric set difference of two sets.

      Parameters:
      elements - collection containing elements to be removed from this set
      Returns:
      a new set without the removed elements, or this unchanged set
    • clear

      ReplicatedSet<E> clear()
      Remove all elements from this set.
      Returns:
      a new empty set