You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/07/10 05:47:15 UTC
[groovy] 01/02: Add deprecated members of `ManagedConcurrentMap`
back for binary compatibility
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9631
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit f9ed34243d5b2eff8b07547b4903f4efd81a4b26
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jul 10 13:43:21 2020 +0800
Add deprecated members of `ManagedConcurrentMap` back for binary compatibility
---
.../groovy/util/AbstractConcurrentMap.java | 4 +-
.../codehaus/groovy/util/ManagedConcurrentMap.java | 99 +++++++++++++++++++++-
2 files changed, 100 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
index d67fd88..6b18602 100644
--- a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
+++ b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
@@ -34,7 +34,7 @@ public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapB
return (V) segmentFor(hash).get(key, hash);
}
- public Entry<K,V> getOrPut(K key, V value) {
+ public Entry<K,V> getOrPut$$bridge(K key, V value) {
int hash = hash(key);
return segmentFor(hash).getOrPut(key, hash, value);
}
@@ -44,7 +44,7 @@ public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapB
segmentFor(hash).put(key, hash, value);
}
- public void remove(K key) {
+ public void remove$$bridge(K key) {
int hash = hash(key);
segmentFor(hash).remove(key, hash);
}
diff --git a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
index 98c375c..4be2c68 100644
--- a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
+++ b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
@@ -31,11 +31,12 @@ import java.util.stream.Collectors;
* @param <K> the key type
* @param <V> the value type
*/
-public class ManagedConcurrentMap<K, V> {
+public class ManagedConcurrentMap<K, V> extends AbstractConcurrentMap<K,V> {
private final ConcurrentMap<IdentityKey<K>, ManagedReference<V>> internalMap = new ConcurrentHashMap<>();
private final ReferenceBundle bundle;
public ManagedConcurrentMap(ReferenceBundle bundle) {
+ super(bundle); // `extends AbstractConcurrentMap<K,V>` is just for binary compatibility
if (bundle == null) throw new IllegalArgumentException("bundle must not be null");
this.bundle = bundle;
}
@@ -164,4 +165,100 @@ public class ManagedConcurrentMap<K, V> {
return hash;
}
}
+
+ // ------------------------- the following members are deprecated ---------------------------
+ @Deprecated
+ protected Segment<K,V> createSegment(Object segmentInfo, int cap) {
+ ReferenceBundle bundle = (ReferenceBundle) segmentInfo;
+ if (bundle==null) throw new IllegalArgumentException("bundle must not be null");
+ return new ManagedConcurrentMap.Segment<K,V>(bundle, cap);
+ }
+
+ @Deprecated
+ public static class Segment<K,V> extends AbstractConcurrentMap.Segment<K,V>{
+ private static final long serialVersionUID = 2742952509311037869L;
+ protected final ReferenceBundle bundle;
+ public Segment(ReferenceBundle bundle, int cap) {
+ super(cap);
+ this.bundle = bundle;
+ if (bundle==null) throw new IllegalArgumentException("bundle must not be null");
+
+ }
+
+ protected AbstractConcurrentMap.Entry<K,V> createEntry(K key, int hash, V value) {
+ if (bundle==null) throw new IllegalArgumentException("bundle must not be null");
+ return new EntryWithValue<K,V>(bundle, this, key, hash, value);
+ }
+ }
+
+ @Deprecated
+ public static class Entry<K,V> extends ManagedReference<K> implements AbstractConcurrentMap.Entry<K,V> {
+ private final Segment segment;
+ private final int hash;
+
+ public Entry(ReferenceBundle bundle, Segment segment, K key, int hash) {
+ super(bundle, key);
+ this.segment = segment;
+ this.hash = hash;
+ }
+
+ public boolean isValid() {
+ return get() != null;
+ }
+
+ public boolean isEqual(K key, int hash) {
+ return this.hash == hash && get() == key;
+ }
+
+ public V getValue() {
+ return (V)this;
+ }
+
+ public void setValue(V value) {
+ }
+
+ public int getHash() {
+ return hash;
+ }
+
+ @Override
+ public void finalizeReference() {
+ segment.removeEntry(this);
+ super.finalizeReference();
+ }
+
+ /**
+ * @deprecated use finalizeReference
+ */
+ @Deprecated
+ public void finalizeRef() {
+ finalizeReference();
+ }
+ }
+
+ @Deprecated
+ public static class EntryWithValue<K,V> extends Entry<K,V> {
+ private V value;
+
+ public EntryWithValue(ReferenceBundle bundle, Segment segment, K key, int hash, V value) {
+ super(bundle, segment, key, hash);
+ setValue(value);
+ }
+
+ @Override
+ public V getValue() {
+ return value;
+ }
+
+ @Override
+ public void setValue(V value) {
+ this.value = value;
+ }
+
+ @Override
+ public void finalizeReference() {
+ value = null;
+ super.finalizeReference();
+ }
+ }
}