Class WeakConcurrentMap<K,V>
- java.lang.Object
-
- java.lang.ref.ReferenceQueue<K>
-
- io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap<K,V,io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>>
-
- io.opentelemetry.context.internal.shaded.WeakConcurrentMap<K,V>
-
- Direct Known Subclasses:
WeakConcurrentMap.WithInlinedExpunction
public class WeakConcurrentMap<K,V> extends AbstractWeakConcurrentMap<K,V,io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>>
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 theMapinterface 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 is used in multiple artifacts in OpenTelemetry and while it is in our internal API, generally backwards compatible changes should not be made to avoid a situation where different versions of OpenTelemetry artifacts become incompatible with each other.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWeakConcurrentMap.WithInlinedExpunction<K,V>AWeakConcurrentMapwhere stale entries are removed as a side effect of interacting with this map.-
Nested classes/interfaces inherited from class io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap
AbstractWeakConcurrentMap.WeakKey<K>
-
-
Constructor Summary
Constructors Constructor Description WeakConcurrentMap(boolean cleanerThread)WeakConcurrentMap(boolean cleanerThread, boolean reuseKeys)WeakConcurrentMap(boolean cleanerThread, boolean reuseKeys, ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>,V> target)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadgetCleanerThread()protected io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>getLookupKey(K key)Override with care as it can cause lookup failures if done incorrectly.protected voidresetLookupKey(io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K> lookupKey)Resets any reusable state in the lookup key.-
Methods inherited from class io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap
approximateSize, clear, containsKey, defaultValue, expungeStaleEntries, get, getIfPresent, iterator, put, putIfAbsent, putIfProbablyAbsent, remove, run, toString
-
Methods inherited from class java.lang.ref.ReferenceQueue
poll, remove, remove
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
WeakConcurrentMap
public WeakConcurrentMap(boolean cleanerThread)
- Parameters:
cleanerThread-trueif a thread should be started that removes stale entries.
-
WeakConcurrentMap
public WeakConcurrentMap(boolean cleanerThread, boolean reuseKeys)- Parameters:
cleanerThread-trueif a thread should be started that removes stale entries.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 cleanerThread, boolean reuseKeys, ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>,V> target)- Parameters:
cleanerThread-trueif a thread should be started that removes stale entries.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 Detail
-
getLookupKey
protected io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K> getLookupKey(K key)
Description copied from class:AbstractWeakConcurrentMapOverride 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 overrideAbstractWeakConcurrentMap.resetLookupKey(L).- Specified by:
getLookupKeyin classAbstractWeakConcurrentMap<K,V,io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>>
-
resetLookupKey
protected void resetLookupKey(io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K> lookupKey)
Description copied from class:AbstractWeakConcurrentMapResets any reusable state in the lookup key.- Specified by:
resetLookupKeyin classAbstractWeakConcurrentMap<K,V,io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>>
-
getCleanerThread
public Thread getCleanerThread()
- Returns:
- The cleaner thread or
nullif no such thread was set.
-
-