Class WeakConcurrentMap<K,V>
java.lang.Object
io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap<K,V>
- Direct Known Subclasses:
WeakConcurrentMap.WithInlinedExpunction
A thread-safe map with weak keys. Entries are based on a key's system hash code and keys are
considered equal only by reference equality. This class does not implement the
Map interface because this implementation is incompatible with the map contract. While
iterating over a map's entries, any key that has not passed iteration is referenced non-weakly.
This class has been copied as is from https://github.com/raphw/weak-lock-free/blob/ad0e5e0c04d4a31f9485bf12b89afbc9d75473b3/src/main/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMap.java
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAWeakConcurrentMapwhere stale entries are removed as a side effect of interacting with this map. -
Constructor Summary
ConstructorsConstructorDescriptionWeakConcurrentMap(boolean reuseKeys) WeakConcurrentMap(boolean reuseKeys, ConcurrentMap<io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.AbstractWeakConcurrentMap.WeakKey<K>, V> target) -
Method Summary
Modifier and TypeMethodDescriptionintReturns the approximate size of this map where the returned number is at least as big as the actual number of entries.voidclear()Clears the entire map.computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) booleancontainsKey(K key) protected VdefaultValue(K key) Creates a default value.static voidCleans all unused references.getIfPresent(K key) protected io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap.LookupKey<K> getLookupKey(K key) Override with care as it can cause lookup failures if done incorrectly.iterator()putIfAbsent(K key, V value) putIfProbablyAbsent(K key, V value) protected voidresetLookupKey(io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap.LookupKey<K> lookupKey) Resets any reusable state in the lookup key.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
WeakConcurrentMap
public WeakConcurrentMap() -
WeakConcurrentMap
public WeakConcurrentMap(boolean reuseKeys) - Parameters:
reuseKeys-trueif the lookup keys should be reused via aThreadLocal. Note that setting this totruemay result in class loader leaks. SeeisPersistentClassLoader(ClassLoader)for more details.
-
WeakConcurrentMap
public WeakConcurrentMap(boolean reuseKeys, ConcurrentMap<io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.AbstractWeakConcurrentMap.WeakKey<K>, V> target) - Parameters:
reuseKeys-trueif the lookup keys should be reused via aThreadLocal. Note that setting this totruemay result in class loader leaks. SeeisPersistentClassLoader(ClassLoader)for more details.target- ConcurrentMap implementation that this class wraps.
-
-
Method Details
-
getLookupKey
protected io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap.LookupKey<K> getLookupKey(K key) Override with care as it can cause lookup failures if done incorrectly. The result must have the sameObject.hashCode()as the input and beequal toa weak reference of the key. When overriding this, also overrideresetLookupKey(L). -
resetLookupKey
protected void resetLookupKey(io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap.LookupKey<K> lookupKey) Resets any reusable state in the lookup key. -
get
- Parameters:
key- The key of the entry.- Returns:
- The value of the entry or the default value if it did not exist.
-
getIfPresent
- Parameters:
key- The key of the entry.- Returns:
- The value of the entry or null if it did not exist.
-
containsKey
- Parameters:
key- The key of the entry.- Returns:
trueif the key already defines a value.
-
put
- Parameters:
key- The key of the entry.value- The value of the entry.- Returns:
- The previous entry or
nullif it does not exist.
-
putIfAbsent
- Parameters:
key- The key of the entry.value- The value of the entry.- Returns:
- The previous entry or
nullif it does not exist.
-
computeIfAbsent
-
putIfProbablyAbsent
- Parameters:
key- The key of the entry.value- The value of the entry.- Returns:
- The previous entry or
nullif it does not exist.
-
remove
- Parameters:
key- The key of the entry.- Returns:
- The removed entry or
nullif it does not exist.
-
clear
public void clear()Clears the entire map. -
defaultValue
Creates a default value. There is no guarantee that the requested value will be set as a once it is created in case that another thread requests a value for a key concurrently.- Parameters:
key- The key for which to create a default value.- Returns:
- The default value for a key without value or
nullfor not defining a default value.
-
expungeStaleEntries
public static void expungeStaleEntries()Cleans all unused references. -
approximateSize
public int approximateSize()Returns the approximate size of this map where the returned number is at least as big as the actual number of entries.- Returns:
- The minimum size of this map.
-
iterator
-
toString
-