Top Description Inners Fields Constructors Methods
io.opentelemetry.context.internal.shaded

pack-priv abstract Class AbstractWeakConcurrentMap<K, V, L>

extends ReferenceQueue<K>
implements Runnable, Iterable<Map.Entry<K, V>>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable, java.lang.Runnable
Known Direct Subclasses
io.opentelemetry.context.internal.shaded.WeakConcurrentMap
Annotations
@SuppressWarnings:MissingSummary, EqualsBrokenForNull, FieldMissingNullable
Imports
java.lang.ref.Reference, .ReferenceQueue, .WeakReference, java.util.Iterator, .Map, .NoSuchElementException, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

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 offers an abstract-base implementation that allows to override methods. 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 and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
public static class

Field Summary

Modifier and TypeField and Description
pack-priv final ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>, V>

Constructor Summary

AccessConstructor and Description
protected
protected
AbstractWeakConcurrentMap(ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>, V>
ConcurrentMap implementation that this class wraps.
target
)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

The minimum size of this map.
approximateSize
()

Returns the approximate size of this map where the returned number is at least as big as the actual number of entries.

public void
clear()

Clears the entire map.

public boolean

Returns:

true if the key already defines a value.
containsKey
(K
The key of the entry.
key
)

protected V

Returns:

The default value for a key without value or null for not defining a default value.
defaultValue
(K
The key for which to create a default value.
key
)

Creates a default value.

public void
expungeStaleEntries()

Cleans all unused references.

public V

Returns:

The value of the entry or the default value if it did not exist.
get
(K
The key of the entry.
key
)

public V

Returns:

The value of the entry or null if it did not exist.
getIfPresent
(K
The key of the entry.
key
)

protected abstract L
getLookupKey(K key)

Override with care as it can cause lookup failures if done incorrectly.

public Iterator<Map.Entry<K, V>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public V

Returns:

The previous entry or null if it does not exist.
put
(K
The key of the entry.
key
,
V
The value of the entry.
value
)

public V

Returns:

The previous entry or null if it does not exist.
putIfAbsent
(K
The key of the entry.
key
,
V
The value of the entry.
value
)

public V

Returns:

The previous entry or null if it does not exist.
putIfProbablyAbsent
(K
The key of the entry.
key
,
V
The value of the entry.
value
)

public V

Returns:

The removed entry or null if it does not exist.
remove
(K
The key of the entry.
key
)

protected abstract void
resetLookupKey(L lookupKey)

Resets any reusable state in the lookup key.

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.ref.ReferenceQueue:
pollremoveremove

Field Detail

targetback to summary
pack-priv final ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>, V> target

Constructor Detail

AbstractWeakConcurrentMapback to summary
protected AbstractWeakConcurrentMap()
AbstractWeakConcurrentMapback to summary
protected AbstractWeakConcurrentMap(ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>, V> target)
Parameters
target:ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>, V>

ConcurrentMap implementation that this class wraps.

Method Detail

approximateSizeback to summary
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:int

The minimum size of this map.

clearback to summary
public void clear()

Clears the entire map.

containsKeyback to summary
public boolean containsKey(K key)
Parameters
key:K

The key of the entry.

Returns:boolean

true if the key already defines a value.

defaultValueback to summary
protected V defaultValue(K key)

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:K

The key for which to create a default value.

Returns:V

The default value for a key without value or null for not defining a default value.

expungeStaleEntriesback to summary
public void expungeStaleEntries()

Cleans all unused references.

getback to summary
public V get(K key)
Parameters
key:K

The key of the entry.

Returns:V

The value of the entry or the default value if it did not exist.

getIfPresentback to summary
public V getIfPresent(K key)
Parameters
key:K

The key of the entry.

Returns:V

The value of the entry or null if it did not exist.

getLookupKeyback to summary
protected abstract L getLookupKey(K key)

Override with care as it can cause lookup failures if done incorrectly. The result must have the same Object#hashCode() as the input and be equal to a weak reference of the key. When overriding this, also override resetLookupKey.

iteratorback to summary
public Iterator<Map.Entry<K, V>> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Map.Entry<K, V>>

an Iterator.

Annotations
@Override
putback to summary
public V put(K key, V value)
Parameters
key:K

The key of the entry.

value:V

The value of the entry.

Returns:V

The previous entry or null if it does not exist.

putIfAbsentback to summary
public V putIfAbsent(K key, V value)
Parameters
key:K

The key of the entry.

value:V

The value of the entry.

Returns:V

The previous entry or null if it does not exist.

putIfProbablyAbsentback to summary
public V putIfProbablyAbsent(K key, V value)
Parameters
key:K

The key of the entry.

value:V

The value of the entry.

Returns:V

The previous entry or null if it does not exist.

removeback to summary
public V remove(K key)
Parameters
key:K

The key of the entry.

Returns:V

The removed entry or null if it does not exist.

resetLookupKeyback to summary
protected abstract void resetLookupKey(L lookupKey)

Resets any reusable state in the lookup key.

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
io.opentelemetry.context.internal.shaded back to summary

private Class AbstractWeakConcurrentMap.EntryIterator

extends Object
implements Iterator<Map.Entry<K, V>>
Class Inheritance
  • java.lang.Object
  • io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap.EntryIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
private final Iterator<Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V>>
private Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V>
private K

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Map.Entry<K, V>
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private final Iterator<Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V>> iterator
nextEntryback to summary
private Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V> nextEntry
nextKeyback to summary
private K nextKey

Constructor Detail

EntryIteratorback to summary
private EntryIterator(Iterator<Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V>> iterator)

Method Detail

findNextback to summary
private void findNext()
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Map.Entry<K, V> next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Map.Entry<K, V>

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
io.opentelemetry.context.internal.shaded back to summary

private Class AbstractWeakConcurrentMap.SimpleEntry

extends Object
implements Map.Entry<K, V>
Class Inheritance
  • java.lang.Object
  • io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap.SimpleEntry
All Implemented Interfaces
java.util.Map.Entry

Field Summary

Modifier and TypeField and Description
pack-priv final Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V>
private final K

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public K
getKey()

Implements java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

public V
getValue()

Implements java.util.Map.Entry.getValue.

Returns the value corresponding to this entry.

public V
setValue(V
new value to be stored in this entry
value
)

Implements java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryback to summary
pack-priv final Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V> entry
keyback to summary
private final K key

Constructor Detail

SimpleEntryback to summary
private SimpleEntry(K key, Map.Entry<AbstractWeakConcurrentMap.WeakKey<K>, V> entry)

Method Detail

getKeyback to summary
public K getKey()

Implements java.util.Map.Entry.getKey.

Doc from java.util.Map.Entry.getKey.

Returns the key corresponding to this entry.

Returns:K

the key corresponding to this entry

Annotations
@Override
getValueback to summary
public V getValue()

Implements java.util.Map.Entry.getValue.

Doc from java.util.Map.Entry.getValue.

Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove operation), the results of this call are undefined.

Returns:V

the value corresponding to this entry

Annotations
@Override
setValueback to summary
public V setValue(V value)

Implements java.util.Map.Entry.setValue.

Doc from java.util.Map.Entry.setValue.

Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove operation).

Parameters
value:V

new value to be stored in this entry

Returns:V

old value corresponding to the entry

Annotations
@Override
io.opentelemetry.context.internal.shaded back to summary

public final Class AbstractWeakConcurrentMap.WeakKey<K>

extends WeakReference<K>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
WeakKey(K key, ReferenceQueue<? super K> queue)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

hashCodeback to summary
private final int hashCode

Constructor Detail

WeakKeyback to summary
pack-priv WeakKey(K key, ReferenceQueue<? super K> queue)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override