Interface ReplicatedMap<K,V extends kalix.replicatedentity.ReplicatedData>
- Type Parameters:
K- The type of keys.V- The replicated data type to be used for values.
- All Superinterfaces:
kalix.replicatedentity.ReplicatedData
ReplicatedData objects.
Use the more specialized maps if possible, such as ReplicatedCounterMap, ReplicatedRegisterMap, and ReplicatedMultiMap.
A removal can only be done if all of the additions that caused the key to be in the map have been seen by this node. This means that, for example, if node 1 adds key A, and node 2 also adds key 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 item will still be in the map because node 2's addition had not yet been observed by node 3. However, if both additions had been replicated to node 3, then the key will be removed.
The values of the map are themselves ReplicatedData types, and hence allow concurrent
updates that will eventually converge. New ReplicatedData objects may only be created
when using the getOrElse(Object, Function) method, using the provided
ReplicatedDataFactory for the create function.
While removing entries from the map is supported, if the entries are added back again, it is possible that the value of the deleted entry may be merged into the value of the current entry, depending on whether the removal has been replicated to all nodes before the addition is performed.
The map may contain different data types as values, however, for a given key, the type must never change. If two different types for the same key are inserted on different nodes, the replicated entity will enter an invalid state that can never be merged, and behavior of the replicated entity is undefined.
Care needs to be taken to ensure that the serialized value of keys 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 Summary
Modifier and TypeMethodDescriptionclear()Remove all entries from this map.booleancontainsKey(K key) Check whether this map contains a mapping for the given key.Get theReplicatedDatavalue for the given key.getOrElse(K key, Function<ReplicatedDataFactory, V> create) Get theReplicatedDatavalue for the given key.default ReplicatedCountergetReplicatedCounter(K key) Get aReplicatedCounterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <KeyT> ReplicatedCounterMap<KeyT> getReplicatedCounterMap(K key) Get aReplicatedCounterMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <KeyT,ValueT extends kalix.replicatedentity.ReplicatedData>
ReplicatedMap<KeyT, ValueT> getReplicatedMap(K key) Get aReplicatedMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <KeyT,ValueT>
ReplicatedMultiMap<KeyT, ValueT> getReplicatedMultiMap(K key) Get aReplicatedMultiMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <ValueT> ReplicatedRegister<ValueT> getReplicatedRegister(K key) Get aReplicatedRegisterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <ValueT> ReplicatedRegister<ValueT> getReplicatedRegister(K key, Supplier<ValueT> defaultValue) Get aReplicatedRegisterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <KeyT,ValueT>
ReplicatedRegisterMap<KeyT, ValueT> Get aReplicatedRegisterMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).default <ElementT> ReplicatedSet<ElementT> getReplicatedSet(K key) Get aReplicatedSetfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).booleanisEmpty()Check whether this map is empty.keySet()Get aSetview of the keys contained in this map.Remove the mapping for a key if it is present.intsize()Get the number of key-value mappings in this map.Update theReplicatedDatavalue associated with the given key.
-
Method Details
-
get
Get theReplicatedDatavalue for the given key.- Parameters:
key- the key of the mapping- Returns:
- the
ReplicatedDatafor the key - Throws:
NoSuchElementException- if the key is not preset in the map
-
getOrElse
Get theReplicatedDatavalue for the given key. If the key is not present in the map, then a new value is created with a creation function.- Parameters:
key- the key of the mappingcreate- function used to create an empty value using the givenReplicatedDataFactoryif the key is not present in the map- Returns:
- the
ReplicatedDatafor the key
-
update
Update theReplicatedDatavalue associated with the given key.- Parameters:
key- the key of the mappingvalue- the updatedReplicatedDatavalue- Returns:
- a new map with the updated value
-
remove
Remove the mapping for a key if it is present.- Parameters:
key- key whose mapping is to be removed from the map- Returns:
- a new map with the removed mapping
-
clear
ReplicatedMap<K,V> clear()Remove all entries from this map.- Returns:
- a new empty map
-
size
int size()Get the number of key-value mappings in this map.- Returns:
- the number of key-value mappings in this map
-
isEmpty
boolean isEmpty()Check whether this map is empty.- Returns:
trueif this map contains no key-value mappings
-
containsKey
Check whether this map contains a mapping for the given key.- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the given key
-
keySet
Get aSetview of the keys contained in this map.- Returns:
- the keys contained in this map
-
getReplicatedCounter
Get aReplicatedCounterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Parameters:
key- the key for a Replicated Counter in this map- Returns:
- the
ReplicatedCounterassociated with the given key, or an empty counter
-
getReplicatedRegister
Get aReplicatedRegisterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
ValueT- the value type for the Replicated Register- Parameters:
key- the key for a Replicated Register in this map- Returns:
- the
ReplicatedRegisterassociated with the given key, or an empty register
-
getReplicatedRegister
default <ValueT> ReplicatedRegister<ValueT> getReplicatedRegister(K key, Supplier<ValueT> defaultValue) Get aReplicatedRegisterfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
ValueT- the value type for the Replicated Register- Parameters:
key- the key for a Replicated Register in this mapdefaultValue- the supplier for a default value when the register is not present- Returns:
- the
ReplicatedRegisterassociated with the given key, or a default register
-
getReplicatedSet
Get aReplicatedSetfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
ElementT- the element type for the Replicated Set- Parameters:
key- the key for a Replicated Set in this map- Returns:
- the
ReplicatedSetassociated with the given key, or an empty set
-
getReplicatedCounterMap
Get aReplicatedCounterMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
KeyT- the key type for the Replicated Counter Map- Parameters:
key- the key for a Replicated Counter Map in this map- Returns:
- the
ReplicatedCounterMapassociated with the given key, or an empty map
-
getReplicatedRegisterMap
Get aReplicatedRegisterMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
KeyT- the key type for the Replicated Register MapValueT- the value type for the Replicated Register Map- Parameters:
key- the key for a Replicated Register Map in this map- Returns:
- the
ReplicatedRegisterMapassociated with the given key, or an empty map
-
getReplicatedMultiMap
Get aReplicatedMultiMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
KeyT- the key type for the Replicated Multi-MapValueT- the value type for the Replicated Multi-Map- Parameters:
key- the key for a Replicated Multi-Map in this map- Returns:
- the
ReplicatedMultiMapassociated with the given key, or an empty multi-map
-
getReplicatedMap
default <KeyT,ValueT extends kalix.replicatedentity.ReplicatedData> ReplicatedMap<KeyT,ValueT> getReplicatedMap(K key) Get aReplicatedMapfrom a heterogeneous Replicated Map (a map with different types of Replicated Data values).- Type Parameters:
KeyT- the key type for the Replicated MapValueT- the value type for the Replicated Map- Parameters:
key- the key for a Replicated Map in this map- Returns:
- the
ReplicatedMapassociated with the given key, or an empty map
-