camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/5] camel git commit: CAMEL-8602: Java 8: ConcurrentLinkedHashMap -> Caffeine
Date Thu, 31 Mar 2016 10:09:35 GMT
CAMEL-8602: Java 8: ConcurrentLinkedHashMap -> Caffeine


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1f48a57f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1f48a57f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1f48a57f

Branch: refs/heads/master
Commit: 1f48a57f1af4de79e3902c9b05ae4ab4f28b9e8f
Parents: 2292934
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Mar 31 11:24:08 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Mar 31 11:30:59 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/util/LRUCache.java    | 23 +++++++++++---------
 .../org/apache/camel/util/LRUSoftCache.java     |  8 +++----
 .../org/apache/camel/util/LRUWeakCache.java     |  5 +++--
 3 files changed, 19 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1f48a57f/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/LRUCache.java b/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
index 4c18a31..dda974f 100644
--- a/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
+++ b/camel-core/src/main/java/org/apache/camel/util/LRUCache.java
@@ -30,7 +30,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A Least Recently Used Cache.
+ * A cache that uses a near optional LRU Cache.
+ * <p/>
+ * The Cache is implemented by Caffeine which provides an <a href="https://github.com/ben-manes/caffeine/wiki/Efficiency">efficient
cache</a>.
  * <p/>
  * If this cache stores {@link org.apache.camel.Service} then this implementation will on
eviction
  * invoke the {@link org.apache.camel.Service#stop()} method, to auto-stop the service.
@@ -39,7 +41,6 @@ import org.slf4j.LoggerFactory;
  * @see LRUWeakCache
  */
 public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K, V>,
Serializable {
-    private static final long serialVersionUID = -342098639681884414L;
     private static final Logger LOG = LoggerFactory.getLogger(LRUCache.class);
 
     protected final AtomicLong hits = new AtomicLong();
@@ -190,14 +191,16 @@ public class LRUCache<K, V> implements Map<K, V>, RemovalListener<K,
V>, Seriali
 
     @Override
     public void onRemoval(K key, V value, RemovalCause cause) {
-        evicted.incrementAndGet();
-        LOG.trace("onRemoval {} -> {}", key, value);
-        if (stopOnEviction) {
-            try {
-                // stop service as its evicted from cache
-                ServiceHelper.stopService(value);
-            } catch (Exception e) {
-                LOG.warn("Error stopping service: " + value + ". This exception will be ignored.",
e);
+        if (cause.wasEvicted()) {
+            evicted.incrementAndGet();
+            LOG.trace("onRemoval {} -> {}", key, value);
+            if (stopOnEviction) {
+                try {
+                    // stop service as its evicted from cache
+                    ServiceHelper.stopService(value);
+                } catch (Exception e) {
+                    LOG.warn("Error stopping service: " + value + ". This exception will
be ignored.", e);
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1f48a57f/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java b/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
index 6189026..4224d1d 100644
--- a/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
+++ b/camel-core/src/main/java/org/apache/camel/util/LRUSoftCache.java
@@ -16,10 +16,10 @@
  */
 package org.apache.camel.util;
 
-import java.lang.ref.SoftReference;
-
 /**
- * A Least Recently Used Cache which uses {@link SoftReference}.
+ * A cache that uses a near optional LRU Cache using {@link java.lang.ref.SoftReference}.
+ * <p/>
+ * The Cache is implemented by Caffeine which provides an <a href="https://github.com/ben-manes/caffeine/wiki/Efficiency">efficient
cache</a>.
  * <p/>
  * This implementation uses {@link java.lang.ref.SoftReference} for stored values in the
cache, to support the JVM
  * when it wants to reclaim objects when it's running out of memory. Therefore this implementation
does
@@ -50,8 +50,6 @@ import java.lang.ref.SoftReference;
  */
 public class LRUSoftCache<K, V> extends LRUCache<K, V> {
 
-    private static final long serialVersionUID = 1L;
-
     public LRUSoftCache(int maximumCacheSize) {
         this(16, maximumCacheSize);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1f48a57f/camel-core/src/main/java/org/apache/camel/util/LRUWeakCache.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/LRUWeakCache.java b/camel-core/src/main/java/org/apache/camel/util/LRUWeakCache.java
index 16d48f6..e624f44 100644
--- a/camel-core/src/main/java/org/apache/camel/util/LRUWeakCache.java
+++ b/camel-core/src/main/java/org/apache/camel/util/LRUWeakCache.java
@@ -17,7 +17,9 @@
 package org.apache.camel.util;
 
 /**
- * A Least Recently Used Cache which uses {@link java.lang.ref.WeakReference}.
+ * A cache that uses a near optional LRU Cache using {@link java.lang.ref.WeakReference}.
+ * <p/>
+ * The Cache is implemented by Caffeine which provides an <a href="https://github.com/ben-manes/caffeine/wiki/Efficiency">efficient
cache</a>.
  * <p/>
  * This implementation uses {@link java.lang.ref.WeakReference} for stored values in the
cache, to support the JVM
  * when it wants to reclaim objects for example during garbage collection. Therefore this
implementation does
@@ -47,7 +49,6 @@ package org.apache.camel.util;
  * @see LRUSoftCache
  */
 public class LRUWeakCache<K, V> extends LRUCache<K, V> {
-    private static final long serialVersionUID = 1L;
 
     public LRUWeakCache(int maximumCacheSize) {
         this(16, maximumCacheSize);


Mime
View raw message