You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2019/10/21 07:07:52 UTC

svn commit: r1868678 - in /jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak: cache/CacheLIRS.java spi/GuavaDeprecation.java

Author: reschke
Date: Mon Oct 21 07:07:52 2019
New Revision: 1868678

URL: http://svn.apache.org/viewvc?rev=1868678&view=rev
Log:
OAK-8702: deprecate Guava based APIs in o.a.j.o.cache

Modified:
    jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
    jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/GuavaDeprecation.java

Modified: jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java?rev=1868678&r1=1868677&r2=1868678&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java (original)
+++ jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/CacheLIRS.java Mon Oct 21 07:07:52 2019
@@ -17,7 +17,9 @@
 package org.apache.jackrabbit.oak.cache;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -38,6 +40,8 @@ import com.google.common.cache.Weigher;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.UncheckedExecutionException;
+
+import org.apache.jackrabbit.oak.spi.GuavaDeprecation;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
@@ -78,7 +82,13 @@ public class CacheLIRS<K, V> implements
     static final ThreadLocal<Integer> CURRENTLY_LOADING = new ThreadLocal<Integer>();
     private static final AtomicInteger NEXT_CACHE_ID = new AtomicInteger();
     private static final boolean PUT_HOT = Boolean.parseBoolean(System.getProperty("oak.cacheLIRS.putHot", "true"));
-    
+
+    // see OAK-8702
+    private static final List<String> ALLOWED_USERS = Collections
+            .unmodifiableList(Arrays
+                    .asList(new String[] { "org.apache.jackrabbit.oak.plugins.blob.", "org.apache.jackrabbit.oak.plugins.document.",
+                            "org.apache.jackrabbit.oak.segment." }));
+
     /**
      * Listener for items that are evicted from the cache. The listener
      * is called for both, resident and non-resident items. In the
@@ -167,6 +177,7 @@ public class CacheLIRS<K, V> implements
     CacheLIRS(Weigher<K, V> weigher, long maxMemory, int averageMemory,
             int segmentCount, int stackMoveDistance, final CacheLoader<K, V> loader,
             EvictionCallback<K, V> evicted, String module) {
+        GuavaDeprecation.handleCall("OAK-8702", CacheLIRS.class.getName(), ALLOWED_USERS);
         LOG.debug("Init #{}, module={}, maxMemory={}, segmentCount={}, stackMoveDistance={}",
                 cacheId, module, maxMemory, segmentCount, segmentCount);
         this.weigher = weigher;

Modified: jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/GuavaDeprecation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/GuavaDeprecation.java?rev=1868678&r1=1868677&r2=1868678&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/GuavaDeprecation.java (original)
+++ jackrabbit/oak/trunk/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/spi/GuavaDeprecation.java Mon Oct 21 07:07:52 2019
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.spi;
 
+import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
 
 import org.slf4j.Logger;
@@ -53,29 +55,73 @@ public class GuavaDeprecation {
     }
 
     public static void handleCall(String ticket) throws UnsupportedOperationException {
+        handleCall(ticket, null, Collections.emptyList());
+    }
+
+    public static void handleCall(String ticket, String className, List<String> allowed) throws UnsupportedOperationException {
         String message = "use of deprecated Guava-related API - this method is going to be removed in future Oak releases - see %s for details";
 
         switch (LOGLEVEL) {
             case "error":
                 if (LOG.isErrorEnabled()) {
-                    LOG.error(String.format(message, ticket), new Exception("call stack"));
+                    Exception ex = new Exception("call stack");
+                    if (deprecatedCaller(ex, className, allowed)) {
+                        LOG.error(String.format(message, ticket), ex);
+                    }
                 }
                 break;
             case "warn":
                 if (LOG.isWarnEnabled()) {
-                    LOG.warn(String.format(message, ticket), new Exception("call stack"));
+                    Exception ex = new Exception("call stack");
+                    if (deprecatedCaller(ex, className, allowed)) {
+                        LOG.warn(String.format(message, ticket), ex);
+                    }
                 }
                 break;
             case "info":
                 if (LOG.isInfoEnabled()) {
-                    LOG.info(String.format(message, ticket), new Exception("call stack"));
+                    Exception ex = new Exception("call stack");
+                    if (deprecatedCaller(ex, className, allowed)) {
+                        LOG.info(String.format(message, ticket), ex);
+                    }
                 }
                 break;
             case "debug":
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug(String.format(message, ticket), new Exception("call stack"));
+                    Exception ex = new Exception("call stack");
+                    if (deprecatedCaller(ex, className, allowed)) {
+                        LOG.debug(String.format(message, ticket), ex);
+                    }
                 }
                 break;
         }
     }
+
+    public static boolean deprecatedCaller(Exception ex, String className, List<String> allowed) {
+        if (allowed == null) {
+            return true;
+        } else {
+            boolean classFound = false;
+            for (StackTraceElement el : ex.getStackTrace()) {
+                String cn = el.getClassName();
+                if (!classFound) {
+                    // still looking for the entry
+                    classFound = cn.equals(className);
+                } else {
+                    // still in class checked for?
+                    if (cn.equals(className)) {
+                        // go one
+                    } else {
+                        // check caller
+                        for (String a : allowed) {
+                            if (cn.startsWith(a)) {
+                                return false;
+                            }
+                        }
+                    }
+                }
+            }
+            return true;
+        }
+    }
 }