dugenkui03 closed pull request #2593: Improve the implementation of cache
URL: https://github.com/apache/incubator-dubbo/pull/2593
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index fcbb292ec7..730a71fe58 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -865,7 +865,7 @@ private String createAdaptiveExtensionClassCode() {
boolean hasInvocation = false;
for (int i = 0; i < pts.length; ++i) {
- if
(pts[i].getName().equals("org.apache.dubbo.rpc.Invocation")) {
+ if
(("org.apache.dubbo.rpc.Invocation").equals(pts[i].getName())) {
// Null Point check
String s = String.format("\nif (arg%d == null) throw
new IllegalArgumentException(\"invocation == null\");", i);
code.append(s);
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
index 4ba84eb31e..e1e96c6767 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/Cache.java
@@ -25,4 +25,9 @@
Object get(Object key);
+ boolean remove(Object key);
+
+ void clear();
+
+ long size();
}
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
index 9fd61f5950..b920b62d97 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringCache.java
@@ -28,9 +28,9 @@
private final Map<Object, Object> store;
public ExpiringCache(URL url) {
- // cache time (second)
+ // cache time(second)
final int secondsToLive = url.getParameter("cache.seconds", 180);
- // Cache check interval (second)
+ // Cache check interval(second)
final int intervalSeconds = url.getParameter("cache.interval", 4);
ExpiringMap<Object, Object> expiringMap = new ExpiringMap<Object,
Object>(secondsToLive, intervalSeconds);
expiringMap.getExpireThread().startExpiryIfNotStarted();
@@ -47,4 +47,22 @@ public Object get(Object key) {
return store.get(key);
}
+ @Override
+ public boolean remove(Object key) {
+ return store.remove(key)!=null;
+ }
+
+ /**
+ * must invoke this method before abandon this cache
+ */
+ @Override
+ public void clear() {
+ store.clear();
+ }
+
+ @Override
+ public long size() {
+ return store.size();
+ }
+
}
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
index c3cb373bc0..2a09c1efe8 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
@@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
@@ -40,7 +41,7 @@
*/
private static final int DEFAULT_EXPIRATION_INTERVAL = 1;
- private static volatile int expireCount = 1;
+ private static AtomicInteger expireCount = new AtomicInteger(1);
private final ConcurrentHashMap<K, ExpiryObject> delegateMap;
@@ -263,7 +264,7 @@ public String toString() {
}
public ExpireThread() {
- expirerThread = new Thread(this, "ExpiryMapExpire-" +
expireCount++);
+ expirerThread = new Thread(this, "ExpiryMapExpire-" +
Thread.currentThread().getName() + "-" + expireCount.getAndIncrement());
expirerThread.setDaemon(true);
}
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
index 2a28204573..a995d8a70f 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/jcache/JCache.java
@@ -75,4 +75,19 @@ public Object get(Object key) {
return store.get(key);
}
+ @Override
+ public boolean remove(Object key) {
+ return store.remove(key);
+ }
+
+ @Override
+ public void clear() {
+ store.clear();
+ }
+
+ @Override
+ public long size() {
+ throw new UnsupportedOperationException();
+ }
+
}
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java
index 11a00ac60c..8b6bf24f69 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/lru/LruCache.java
@@ -44,4 +44,19 @@ public Object get(Object key) {
return store.get(key);
}
+ @Override
+ public boolean remove(Object key) {
+ return store.remove(key)!=null;
+ }
+
+ @Override
+ public void clear() {
+ store.clear();
+ }
+
+ @Override
+ public long size() {
+ return store.size();
+ }
+
}
diff --git
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
index 4b557bebbb..a8b533630a 100644
---
a/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
+++
b/dubbo-filter/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/threadlocal/ThreadLocalCache.java
@@ -48,4 +48,20 @@ public Object get(Object key) {
return store.get().get(key);
}
+ @Override
+ public boolean remove(Object key) {
+ return store.get().remove(key)!=null;
+ }
+
+ @Override
+ public void clear() {
+ store.get().clear();
+ store.remove();
+ }
+
+ @Override
+ public long size() {
+ return store.get().size();
+ }
+
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services