From da9ea814bd7b6cc23a0be27b3a1e3da3f0922063 Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Tue, 30 Nov 2021 11:44:22 +0200 Subject: [PATCH 1/3] Move cache implementations to internal package --- .../instrumentation/api/cache/Cache.java | 2 +- .../api/cache/WeakLockFreeCache.java | 2 +- .../ConcurrentLinkedHashMap.java | 8 +++---- .../concurrentlinkedhashmap/EntryWeigher.java | 2 +- .../EvictionListener.java | 2 +- .../concurrentlinkedhashmap/LinkedDeque.java | 2 +- .../concurrentlinkedhashmap/Weigher.java | 2 +- .../concurrentlinkedhashmap/Weighers.java | 4 ++-- .../concurrentlinkedhashmap/package-info.java | 22 ++++++++++--------- .../AbstractWeakConcurrentMap.java | 4 ++-- .../weaklockfree/WeakConcurrentMap.java | 8 ++++--- 11 files changed, 31 insertions(+), 27 deletions(-) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java (99%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/EntryWeigher.java (94%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/EvictionListener.java (95%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/LinkedDeque.java (99%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/Weigher.java (94%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/Weighers.java (97%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/concurrentlinkedhashmap/package-info.java (64%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/weaklockfree/AbstractWeakConcurrentMap.java (98%) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/{ => internal}/weaklockfree/WeakConcurrentMap.java (96%) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/Cache.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/Cache.java index d050acca0b9a..6cce6f73171e 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/Cache.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/Cache.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.api.cache; -import io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap; +import io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import java.util.function.Function; import javax.annotation.Nullable; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java index 0c07e323971a..c56a43d67b93 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.api.cache; -import io.opentelemetry.instrumentation.api.cache.weaklockfree.WeakConcurrentMap; +import io.opentelemetry.context.internal.shaded.WeakConcurrentMap; import java.util.function.Function; final class WeakLockFreeCache implements Cache { diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java similarity index 99% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java index 2fd1ba9c7c18..2f4f0d69f714 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java @@ -20,11 +20,11 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; -import static io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.IDLE; -import static io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.PROCESSING; -import static io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.REQUIRED; +import static io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.IDLE; +import static io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.PROCESSING; +import static io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap.DrainStatus.REQUIRED; import static java.util.Collections.emptyList; import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableSet; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EntryWeigher.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EntryWeigher.java similarity index 94% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EntryWeigher.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EntryWeigher.java index cba75b19a42d..4a5ce53624af 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EntryWeigher.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EntryWeigher.java @@ -20,7 +20,7 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; import javax.annotation.concurrent.ThreadSafe; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EvictionListener.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EvictionListener.java similarity index 95% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EvictionListener.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EvictionListener.java index 846c977c3d4e..3487798cb340 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/EvictionListener.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/EvictionListener.java @@ -20,7 +20,7 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; import javax.annotation.concurrent.ThreadSafe; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/LinkedDeque.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/LinkedDeque.java similarity index 99% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/LinkedDeque.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/LinkedDeque.java index e69e746acad6..6f6b6a871b6a 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/LinkedDeque.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/LinkedDeque.java @@ -20,7 +20,7 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; import java.util.AbstractCollection; import java.util.Collection; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weigher.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weigher.java similarity index 94% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weigher.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weigher.java index 3a68b0d63de3..8e0f1528c557 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weigher.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weigher.java @@ -20,7 +20,7 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; import javax.annotation.concurrent.ThreadSafe; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weighers.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weighers.java similarity index 97% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weighers.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weighers.java index 98ba4b053efb..8fa798d7a6dc 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/Weighers.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/Weighers.java @@ -20,9 +20,9 @@ * limitations under the License. */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; -import static io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap.checkNotNull; +import static io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap.checkNotNull; import java.io.Serializable; import java.util.Collection; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/package-info.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/package-info.java similarity index 64% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/package-info.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/package-info.java index ec971a170cd5..94a555154e5b 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/concurrentlinkedhashmap/package-info.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/concurrentlinkedhashmap/package-info.java @@ -30,24 +30,26 @@ * This package contains an implementation of a bounded {@link java.util.concurrent.ConcurrentMap} * data structure. * - *

{@link io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.Weigher} is a simple - * interface for determining how many units of capacity an entry consumes. Depending on which - * concrete Weigher class is used, an entry may consume a different amount of space within the - * cache. The {@link io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.Weighers} - * class provides utility methods for obtaining the most common kinds of implementations. - * - *

{@link io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.EvictionListener} + *

{@link io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.Weigher} is + * a simple interface for determining how many units of capacity an entry consumes. Depending on + * which concrete Weigher class is used, an entry may consume a different amount of space within the + * cache. The {@link + * io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.Weighers} class + * provides utility methods for obtaining the most common kinds of implementations. + * + *

{@link + * io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.EvictionListener} * provides the ability to be notified when an entry is evicted from the map. An eviction occurs * when the entry was automatically removed due to the map exceeding a capacity threshold. It is not * called when an entry was explicitly removed. * *

The {@link - * io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap.ConcurrentLinkedHashMap} class - * supplies an efficient, scalable, thread-safe, bounded map. As with the Java Collections + * io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap.ConcurrentLinkedHashMap} + * class supplies an efficient, scalable, thread-safe, bounded map. As with the Java Collections * Framework the "Concurrent" prefix is used to indicate that the map is not governed by a * single exclusion lock. * * @see * http://code.google.com/p/concurrentlinkedhashmap/ */ -package io.opentelemetry.instrumentation.api.cache.concurrentlinkedhashmap; +package io.opentelemetry.instrumentation.api.cache.internal.concurrentlinkedhashmap; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/AbstractWeakConcurrentMap.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/AbstractWeakConcurrentMap.java similarity index 98% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/AbstractWeakConcurrentMap.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/AbstractWeakConcurrentMap.java index ae92847ebd6a..78f5a36a8209 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/AbstractWeakConcurrentMap.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/AbstractWeakConcurrentMap.java @@ -23,7 +23,7 @@ // Suppress warnings since this is vendored as-is. // CHECKSTYLE:OFF -package io.opentelemetry.instrumentation.api.cache.weaklockfree; +package io.opentelemetry.instrumentation.api.cache.internal.weaklockfree; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; @@ -278,7 +278,7 @@ public String toString() { * The weak key invokes the latent key's equality method upon evaluation. */ - public static final class WeakKey extends WeakReference { + static final class WeakKey extends WeakReference { private final int hashCode; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/WeakConcurrentMap.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/WeakConcurrentMap.java similarity index 96% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/WeakConcurrentMap.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/WeakConcurrentMap.java index 3aee7ea186bc..05e5af3ce6d7 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/weaklockfree/WeakConcurrentMap.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/internal/weaklockfree/WeakConcurrentMap.java @@ -23,7 +23,7 @@ // Suppress warnings since this is vendored as-is. // CHECKSTYLE:OFF -package io.opentelemetry.instrumentation.api.cache.weaklockfree; +package io.opentelemetry.instrumentation.api.cache.internal.weaklockfree; import java.util.Iterator; import java.util.Map; @@ -115,7 +115,9 @@ public WeakConcurrentMap(boolean cleanerThread, boolean reuseKeys) { * @param target ConcurrentMap implementation that this class wraps. */ public WeakConcurrentMap( - boolean cleanerThread, boolean reuseKeys, ConcurrentMap, V> target) { + boolean cleanerThread, + boolean reuseKeys, + ConcurrentMap, V> target) { super(target); this.reuseKeys = reuseKeys; if (cleanerThread) { @@ -180,7 +182,7 @@ public boolean equals(Object other) { if (other instanceof WeakConcurrentMap.LookupKey) { return ((LookupKey) other).key == key; } else { - return ((WeakKey) other).get() == key; + return ((AbstractWeakConcurrentMap.WeakKey) other).get() == key; } } From 840147e8e01c82ae2990efe22ed8505bbc2dea91 Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Tue, 30 Nov 2021 12:37:55 +0200 Subject: [PATCH 2/3] Fix import --- .../instrumentation/api/cache/WeakLockFreeCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java index c56a43d67b93..ed90c8aeb9af 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.api.cache; -import io.opentelemetry.context.internal.shaded.WeakConcurrentMap; import java.util.function.Function; +import io.opentelemetry.instrumentation.api.cache.internal.weaklockfree.WeakConcurrentMap; final class WeakLockFreeCache implements Cache { From b5a50d52ea17a31cdb1550e262d7b10de37f7fba Mon Sep 17 00:00:00 2001 From: Nikita Salnikov-Tarnovski Date: Tue, 30 Nov 2021 17:11:22 +0200 Subject: [PATCH 3/3] Fix import order --- .../instrumentation/api/cache/WeakLockFreeCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java index ed90c8aeb9af..b7cb827676e2 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/cache/WeakLockFreeCache.java @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.api.cache; -import java.util.function.Function; import io.opentelemetry.instrumentation.api.cache.internal.weaklockfree.WeakConcurrentMap; +import java.util.function.Function; final class WeakLockFreeCache implements Cache {