Package org.onosproject.store.primitives
Class DefaultConsistentMap<K,V>
- java.lang.Object
- 
- org.onosproject.store.service.Synchronous<AsyncConsistentMap<K,V>>
- 
- org.onosproject.store.primitives.DefaultConsistentMap<K,V>
 
 
- 
- Type Parameters:
- K- type of key.
- V- type of value.
 - All Implemented Interfaces:
- Iterable<Map.Entry<K,Versioned<V>>>,- ConsistentMap<K,V>,- DistributedPrimitive
 
 public class DefaultConsistentMap<K,V> extends Synchronous<AsyncConsistentMap<K,V>> implements ConsistentMap<K,V> Default implementation ofConsistentMap.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitiveDistributedPrimitive.Status, DistributedPrimitive.Type
 
- 
 - 
Field Summary- 
Fields inherited from interface org.onosproject.store.service.DistributedPrimitiveDEFAULT_OPERATION_TIMEOUT_MILLIS
 
- 
 - 
Constructor SummaryConstructors Constructor Description DefaultConsistentMap(AsyncConsistentMap<K,V> asyncMap, long operationTimeoutMillis)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(MapEventListener<K,V> listener, Executor executor)Registers the specified listener to be notified whenever the map is updated.voidaddStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)Registers a listener to be called when the primitive's status changes.Map<K,V>asJavaMap()Returns a java.util.Map instance backed by this ConsistentMap.voidclear()Removes all of the mappings from this map (optional operation).Versioned<V>compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).Versioned<V>computeIf(K key, Predicate<? super V> condition, BiFunction<? super K,? super V,? extends V> remappingFunction)If the value for the specified key satisfies a condition, attempts to compute a new mapping given the key and its current mapped value.Versioned<V>computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.Versioned<V>computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.booleancontainsKey(K key)Returns true if this map contains a mapping for the specified key.booleancontainsValue(V value)Returns true if this map contains the specified value.Set<Map.Entry<K,Versioned<V>>>entrySet()Returns the set of entries contained in this map.Versioned<V>get(K key)Returns the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key.Versioned<V>getOrDefault(K key, V defaultValue)Returns the value (and version) to which the specified key is mapped, or the provided default value if this map contains no mapping for the key.booleanisEmpty()Returns true if the map is empty.Iterator<Map.Entry<K,Versioned<V>>>iterator()Set<K>keySet()Returns a Set view of the keys contained in this map.Versioned<V>put(K key, V value)Associates the specified value with the specified key in this map (optional operation).Versioned<V>putAndGet(K key, V value)Associates the specified value with the specified key in this map (optional operation).Versioned<V>putIfAbsent(K key, V value)If the specified key is not already associated with a value associates it with the given value and returns null, else returns the current value.Versioned<V>remove(K key)Removes the mapping for a key from this map if it is present (optional operation).booleanremove(K key, long version)Removes the entry for the specified key only if its current version in the map is equal to the specified version.booleanremove(K key, V value)Removes the entry for the specified key only if it is currently mapped to the specified value.voidremoveListener(MapEventListener<K,V> listener)Unregisters the specified listener such that it will no longer receive map change notifications.voidremoveStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)Unregisters a previously registered listener to be called when the primitive's status changes.booleanreplace(K key, long oldVersion, V newValue)Replaces the entry for the specified key only if it is currently mapped to the specified version.Versioned<V>replace(K key, V value)Replaces the entry for the specified key only if there is any value which associated with specified key.booleanreplace(K key, V oldValue, V newValue)Replaces the entry for the specified key only if currently mapped to the specified value.intsize()Returns the number of entries in the map.Collection<Consumer<DistributedPrimitive.Status>>statusChangeListeners()Returns the collection of status change listeners previously registered.StringtoString()Collection<Versioned<V>>values()Returns the collection of values (and associated versions) contained in this map.- 
Methods inherited from class org.onosproject.store.service.Synchronousdestroy, name, primitiveType
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.onosproject.store.service.ConsistentMapaddListener, stream
 - 
Methods inherited from interface org.onosproject.store.service.DistributedPrimitiveapplicationId, destroy, name, primitiveType
 - 
Methods inherited from interface java.lang.IterableforEach, spliterator
 
- 
 
- 
- 
- 
Constructor Detail- 
DefaultConsistentMappublic DefaultConsistentMap(AsyncConsistentMap<K,V> asyncMap, long operationTimeoutMillis) 
 
- 
 - 
Method Detail- 
sizepublic int size() Description copied from interface:ConsistentMapReturns the number of entries in the map.- Specified by:
- sizein interface- ConsistentMap<K,V>
- Returns:
- map size.
 
 - 
isEmptypublic boolean isEmpty() Description copied from interface:ConsistentMapReturns true if the map is empty.- Specified by:
- isEmptyin interface- ConsistentMap<K,V>
- Returns:
- true if map has no entries, false otherwise
 
 - 
containsKeypublic boolean containsKey(K key) Description copied from interface:ConsistentMapReturns true if this map contains a mapping for the specified key.- Specified by:
- containsKeyin interface- ConsistentMap<K,V>
- Parameters:
- key- key
- Returns:
- true if map contains key, false otherwise
 
 - 
containsValuepublic boolean containsValue(V value) Description copied from interface:ConsistentMapReturns true if this map contains the specified value.- Specified by:
- containsValuein interface- ConsistentMap<K,V>
- Parameters:
- value- value
- Returns:
- true if map contains value, false otherwise.
 
 - 
getpublic Versioned<V> get(K key) Description copied from interface:ConsistentMapReturns the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key.- Specified by:
- getin interface- ConsistentMap<K,V>
- Parameters:
- key- the key whose associated value (and version) is to be returned
- Returns:
- the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key
 
 - 
getOrDefaultpublic Versioned<V> getOrDefault(K key, V defaultValue) Description copied from interface:ConsistentMapReturns the value (and version) to which the specified key is mapped, or the provided default value if this map contains no mapping for the key.Note: a non-null Versionedvalue will be returned even if thedefaultValueisnull.- Specified by:
- getOrDefaultin interface- ConsistentMap<K,V>
- Parameters:
- key- the key whose associated value (and version) is to be returned
- defaultValue- the default value to return if the key is not set
- Returns:
- the value (and version) to which the specified key is mapped, or null if this map contains no mapping for the key
 
 - 
computeIfAbsentpublic Versioned<V> computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction) Description copied from interface:ConsistentMapIf the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.- Specified by:
- computeIfAbsentin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- mappingFunction- the function to compute a value
- Returns:
- the current (existing or computed) value associated with the specified key,
 or null if the computed value is null. Method throws ConsistentMapException.ConcurrentModificationif a concurrent modification of map is detected
 
 - 
computeIfPresentpublic Versioned<V> computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> remappingFunction) Description copied from interface:ConsistentMapIf the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. If the computed value is null, the current mapping will be removed from the map.- Specified by:
- computeIfPresentin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- remappingFunction- the function to compute a value
- Returns:
- the new value associated with the specified key, or null if none.
 This method throws ConsistentMapException.ConcurrentModificationif a concurrent modification of map is detected
 
 - 
computepublic Versioned<V> compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction) Description copied from interface:ConsistentMapAttempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). If the computed value is null, the current mapping will be removed from the map.- Specified by:
- computein interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- remappingFunction- the function to compute a value
- Returns:
- the new value associated with the specified key, or null if none.
 This method throws ConsistentMapException.ConcurrentModificationif a concurrent modification of map is detected
 
 - 
computeIfpublic Versioned<V> computeIf(K key, Predicate<? super V> condition, BiFunction<? super K,? super V,? extends V> remappingFunction) Description copied from interface:ConsistentMapIf the value for the specified key satisfies a condition, attempts to compute a new mapping given the key and its current mapped value. If the computed value is null, the current mapping will be removed from the map.- Specified by:
- computeIfin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- condition- condition that should evaluate to true for the computation to proceed
- remappingFunction- the function to compute a value
- Returns:
- the new value associated with the specified key, or the old value if condition evaluates to false.
 This method throws ConsistentMapException.ConcurrentModificationif a concurrent modification of map is detected
 
 - 
putpublic Versioned<V> put(K key, V value) Description copied from interface:ConsistentMapAssociates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value.- Specified by:
- putin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- value- value to be associated with the specified key
- Returns:
- the previous value (and version) associated with key, or null if there was no mapping for key.
 
 - 
putAndGetpublic Versioned<V> putAndGet(K key, V value) Description copied from interface:ConsistentMapAssociates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value.- Specified by:
- putAndGetin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- value- value to be associated with the specified key
- Returns:
- new value.
 
 - 
removepublic Versioned<V> remove(K key) Description copied from interface:ConsistentMapRemoves the mapping for a key from this map if it is present (optional operation).- Specified by:
- removein interface- ConsistentMap<K,V>
- Parameters:
- key- key whose value is to be removed from the map
- Returns:
- the value (and version) to which this map previously associated the key, or null if the map contained no mapping for the key.
 
 - 
clearpublic void clear() Description copied from interface:ConsistentMapRemoves all of the mappings from this map (optional operation). The map will be empty after this call returns.- Specified by:
- clearin interface- ConsistentMap<K,V>
 
 - 
keySetpublic Set<K> keySet() Description copied from interface:ConsistentMapReturns a Set view of the keys contained in this map. This method differs from the behavior of java.util.Map.keySet() in that what is returned is a unmodifiable snapshot view of the keys in the ConsistentMap. Attempts to modify the returned set, whether direct or via its iterator, result in an UnsupportedOperationException.- Specified by:
- keySetin interface- ConsistentMap<K,V>
- Returns:
- a set of the keys contained in this map
 
 - 
valuespublic Collection<Versioned<V>> values() Description copied from interface:ConsistentMapReturns the collection of values (and associated versions) contained in this map. This method differs from the behavior of java.util.Map.values() in that what is returned is a unmodifiable snapshot view of the values in the ConsistentMap. Attempts to modify the returned collection, whether direct or via its iterator, result in an UnsupportedOperationException.- Specified by:
- valuesin interface- ConsistentMap<K,V>
- Returns:
- a collection of the values (and associated versions) contained in this map
 
 - 
entrySetpublic Set<Map.Entry<K,Versioned<V>>> entrySet() Description copied from interface:ConsistentMapReturns the set of entries contained in this map. This method differs from the behavior of java.util.Map.entrySet() in that what is returned is a unmodifiable snapshot view of the entries in the ConsistentMap. Attempts to modify the returned set, whether direct or via its iterator, result in an UnsupportedOperationException.- Specified by:
- entrySetin interface- ConsistentMap<K,V>
- Returns:
- set of entries contained in this map.
 
 - 
putIfAbsentpublic Versioned<V> putIfAbsent(K key, V value) Description copied from interface:ConsistentMapIf the specified key is not already associated with a value associates it with the given value and returns null, else returns the current value.- Specified by:
- putIfAbsentin interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is to be associated
- value- value to be associated with the specified key
- Returns:
- the previous value associated with the specified key or null if key does not already mapped to a value.
 
 - 
removepublic boolean remove(K key, V value) Description copied from interface:ConsistentMapRemoves the entry for the specified key only if it is currently mapped to the specified value.- Specified by:
- removein interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is associated
- value- value expected to be associated with the specified key
- Returns:
- true if the value was removed
 
 - 
removepublic boolean remove(K key, long version) Description copied from interface:ConsistentMapRemoves the entry for the specified key only if its current version in the map is equal to the specified version.- Specified by:
- removein interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified version is associated
- version- version expected to be associated with the specified key
- Returns:
- true if the value was removed
 
 - 
replacepublic Versioned<V> replace(K key, V value) Description copied from interface:ConsistentMapReplaces the entry for the specified key only if there is any value which associated with specified key.- Specified by:
- replacein interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is associated
- value- value expected to be associated with the specified key
- Returns:
- the previous value associated with the specified key or null
 
 - 
replacepublic boolean replace(K key, V oldValue, V newValue) Description copied from interface:ConsistentMapReplaces the entry for the specified key only if currently mapped to the specified value.- Specified by:
- replacein interface- ConsistentMap<K,V>
- Parameters:
- key- key with which the specified value is associated
- oldValue- value expected to be associated with the specified key
- newValue- value to be associated with the specified key
- Returns:
- true if the value was replaced
 
 - 
replacepublic boolean replace(K key, long oldVersion, V newValue) Description copied from interface:ConsistentMapReplaces the entry for the specified key only if it is currently mapped to the specified version.- Specified by:
- replacein interface- ConsistentMap<K,V>
- Parameters:
- key- key key with which the specified value is associated
- oldVersion- version expected to be associated with the specified key
- newValue- value to be associated with the specified key
- Returns:
- true if the value was replaced
 
 - 
addListenerpublic void addListener(MapEventListener<K,V> listener, Executor executor) Description copied from interface:ConsistentMapRegisters the specified listener to be notified whenever the map is updated.- Specified by:
- addListenerin interface- ConsistentMap<K,V>
- Parameters:
- listener- listener to notify about map events
- executor- executor to use for handling incoming map events
 
 - 
removeListenerpublic void removeListener(MapEventListener<K,V> listener) Description copied from interface:ConsistentMapUnregisters the specified listener such that it will no longer receive map change notifications.- Specified by:
- removeListenerin interface- ConsistentMap<K,V>
- Parameters:
- listener- listener to unregister
 
 - 
addStatusChangeListenerpublic void addStatusChangeListener(Consumer<DistributedPrimitive.Status> listener) Description copied from interface:DistributedPrimitiveRegisters a listener to be called when the primitive's status changes.- Specified by:
- addStatusChangeListenerin interface- DistributedPrimitive
- Parameters:
- listener- The listener to be called when the status changes.
 
 - 
removeStatusChangeListenerpublic void removeStatusChangeListener(Consumer<DistributedPrimitive.Status> listener) Description copied from interface:DistributedPrimitiveUnregisters a previously registered listener to be called when the primitive's status changes.- Specified by:
- removeStatusChangeListenerin interface- DistributedPrimitive
- Parameters:
- listener- The listener to unregister
 
 - 
statusChangeListenerspublic Collection<Consumer<DistributedPrimitive.Status>> statusChangeListeners() Description copied from interface:DistributedPrimitiveReturns the collection of status change listeners previously registered.- Specified by:
- statusChangeListenersin interface- DistributedPrimitive
- Returns:
- collection of status change listeners
 
 - 
asJavaMappublic Map<K,V> asJavaMap() Description copied from interface:ConsistentMapReturns a java.util.Map instance backed by this ConsistentMap.- Specified by:
- asJavaMapin interface- ConsistentMap<K,V>
- Returns:
- java.util.Map
 
 
- 
 
-