You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2021/11/25 06:14:39 UTC

[GitHub] [jackrabbit-oak] averma21 commented on a change in pull request #420: OAK-9624 print the name of the calling class invoking a query in some cases

averma21 commented on a change in pull request #420:
URL: https://github.com/apache/jackrabbit-oak/pull/420#discussion_r756596980



##########
File path: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
##########
@@ -241,4 +242,37 @@ public static String getAsyncLaneName(NodeState idxState, String indexPath, Prop
         }
         return null;
     }
+
+    /**
+     * Retrieves the calling class and method from the call stack; this is determined by unwinding
+     * the stack until it finds a combination of full qualified classname + method (separated by ".") which
+     * do not start with any of the values provided by the ignoredJavaPackages parameters. If the provided
+     * parameters cover all stack frames, the whole query is considered to be internal, where the 
+     * actual caller doesn't matter (or cannot be determined clearly). In this case a short message
+     * indicating this is returned.
+     *
+     * If the ignoredJavaPackages parameter is null or empty, the caller is not looked up, but
+     * instead it is assumed, that the feature is not configured; in that case a short messages
+     * is returned indicating that the feature is not configured.
+     *
+     * @param ignoredJavaPackages the java packages or class names
+     * @return the calling class or another non-null value
+     */
+    @NotNull
+    public static String getCaller(@Nullable String[] ignoredJavaPackages) {
+        if (ignoredJavaPackages == null || ignoredJavaPackages.length == 0) {
+            return "(<function not configured>)";
+        }
+
+        // With java9 we would use https://docs.oracle.com/javase/9/docs/api/java/lang/StackWalker.html
+        final StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
+        for (StackTraceElement stackFrame : callStack) {

Review comment:
       This means we are capturing the top of the stack first. Wondering if we would be interested in bottom of the stack or top. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org