You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2022/09/02 13:52:42 UTC

[sling-org-apache-sling-engine] branch master updated: SLING-11566 : Add methods to check whether recording is enabled

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-engine.git


The following commit(s) were added to refs/heads/master by this push:
     new 647f0a9  SLING-11566 : Add methods to check whether recording is enabled
647f0a9 is described below

commit 647f0a97a091224b6cc568b3e20dfe20425ff2a4
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 2 15:52:37 2022 +0200

    SLING-11566 : Add methods to check whether recording is enabled
---
 .../java/org/apache/sling/engine/RequestInfo.java  |  2 ++
 .../apache/sling/engine/RequestInfoProvider.java   | 29 ++++++++++++++-
 .../engine/impl/debug/RequestInfoProviderImpl.java | 41 ++++++++++++++--------
 .../java/org/apache/sling/engine/package-info.java |  2 +-
 4 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/engine/RequestInfo.java b/src/main/java/org/apache/sling/engine/RequestInfo.java
index 428209e..a35c4f2 100644
--- a/src/main/java/org/apache/sling/engine/RequestInfo.java
+++ b/src/main/java/org/apache/sling/engine/RequestInfo.java
@@ -20,12 +20,14 @@ package org.apache.sling.engine;
 
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * Information about a single request.
  * @see RequestInfoProvider
  * @since 2.5
  */
+@ProviderType
 public interface RequestInfo {
     
     /**
diff --git a/src/main/java/org/apache/sling/engine/RequestInfoProvider.java b/src/main/java/org/apache/sling/engine/RequestInfoProvider.java
index 27441e3..20f5840 100644
--- a/src/main/java/org/apache/sling/engine/RequestInfoProvider.java
+++ b/src/main/java/org/apache/sling/engine/RequestInfoProvider.java
@@ -18,13 +18,31 @@
  */
 package org.apache.sling.engine;
 
+import org.osgi.annotation.versioning.ProviderType;
+
 /**
   * This service can be used to gather information about requests processed by the
   * engine.
   *
   * @since 2.5
   */
- public interface RequestInfoProvider {
+@ProviderType
+public interface RequestInfoProvider {
+
+    /**
+     * Is recording of requests enabled?
+     * @return {@code true} if enabled, {@code} false} otherwise
+     * @since 2.6
+     */
+    boolean isEnabled();
+
+    /**
+     * Is recording of requests for this path enabled?
+     * @param path The path
+     * @return {@code true} if enabled, {@code} false} otherwise
+     * @since 2.6
+     */
+    boolean isEnabledFor(String path);
 
     /**
      * Get the request info for the id
@@ -42,9 +60,18 @@ package org.apache.sling.engine;
     /**
      * Get the maximum number of provided infos
      * @return The maximum number, {@code 0} if no infos are recorded
+     * @deprecated Use {@link #getMaxNumberOfInfos()}
      */
+    @Deprecated
     int getMayNumberOfInfos();
 
+    /**
+     * Get the maximum number of provided infos
+     * @return The maximum number, {@code 0} if no infos are recorded
+     * @since 2.6
+     */
+    int getMaxNumberOfInfos();
+
     /**
      * Clear all request infos
      */
diff --git a/src/main/java/org/apache/sling/engine/impl/debug/RequestInfoProviderImpl.java b/src/main/java/org/apache/sling/engine/impl/debug/RequestInfoProviderImpl.java
index 42077d7..85acf34 100644
--- a/src/main/java/org/apache/sling/engine/impl/debug/RequestInfoProviderImpl.java
+++ b/src/main/java/org/apache/sling/engine/impl/debug/RequestInfoProviderImpl.java
@@ -100,31 +100,44 @@ public class RequestInfoProviderImpl implements RequestInfoProvider {
 
     private void addRequest(final SlingHttpServletRequest r) {
         final ConcurrentNavigableMap<String, RequestInfo> local = requests;
-        if (local != null) {
-            final String requestPath = r.getPathInfo();
-            final List<Pattern> patterns = this.patterns;
+        if (local != null && isEnabledFor(r.getPathInfo())) {
+            final RequestInfo info = new RequestInfoImpl(r);
+            synchronized (local) {
+                if ( local.size() == this.maxSize ) {
+                    local.remove(local.firstKey());
+                }
+                local.put(info.getId(), info);
+            }
+        }
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return this.requests != null;
+    }
+
+    @Override
+    public boolean isEnabledFor(final String path) {
+        if ( this.requests != null ) {
             boolean accept = patterns.isEmpty();
             for (Pattern pattern : patterns) {
-                if (pattern.matcher(requestPath).matches()) {
+                if (pattern.matcher(path).matches()) {
                     accept = true;
                     break;
                 }
             }
-
-            if (accept) {
-                final RequestInfo info = new RequestInfoImpl(r);
-                synchronized (local) {
-                    if ( local.size() == this.maxSize ) {
-                        local.remove(local.firstKey());
-                    }
-                    local.put(info.getId(), info);
-                }
-            }
+            return accept;
         }
+        return false;
     }
 
     @Override
     public int getMayNumberOfInfos() {
+        return this.getMaxNumberOfInfos();
+    }
+
+    @Override
+    public int getMaxNumberOfInfos() {
         return this.maxSize;
     }
 
diff --git a/src/main/java/org/apache/sling/engine/package-info.java b/src/main/java/org/apache/sling/engine/package-info.java
index 7843654..4d6a161 100644
--- a/src/main/java/org/apache/sling/engine/package-info.java
+++ b/src/main/java/org/apache/sling/engine/package-info.java
@@ -17,6 +17,6 @@
  * under the License.
  */
 
-@org.osgi.annotation.versioning.Version("2.5.0")
+@org.osgi.annotation.versioning.Version("2.6.0")
 package org.apache.sling.engine;