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 kw...@apache.org on 2022/09/29 07:32:08 UTC

[jackrabbit-oak] branch feature/optional-session-mbean created (now 4ba9458fa1)

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

kwin pushed a change to branch feature/optional-session-mbean
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


      at 4ba9458fa1 OAK-9959 allow to disable registering MBeans for every Session

This branch includes the following new commits:

     new 4ba9458fa1 OAK-9959 allow to disable registering MBeans for every Session

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[jackrabbit-oak] 01/01: OAK-9959 allow to disable registering MBeans for every Session

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/optional-session-mbean
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 4ba9458fa1d1a838958f93eb469b2860997ce7b2
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Sep 29 09:32:00 2022 +0200

    OAK-9959 allow to disable registering MBeans for every Session
---
 .../main/java/org/apache/jackrabbit/oak/jcr/Jcr.java | 17 +++++++++++++++--
 .../oak/jcr/repository/RepositoryImpl.java           | 20 +++++++++++++-------
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
index d11c0cc9e7..eaf91a022e 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
@@ -88,6 +88,7 @@ public class Jcr {
 
     private int observationQueueLength = DEFAULT_OBSERVATION_QUEUE_LENGTH;
     private boolean fastQueryResultSize;
+    private boolean createSessionMBeans;
 
     private ContentRepository contentRepository;
     private Repository repository;
@@ -96,7 +97,7 @@ public class Jcr {
 
     public Jcr(Oak oak, boolean initialize) {
         this.oak = oak;
-
+        createSessionMBeans = true; // by default every (long-living) session will register an MBean
         if (initialize) {
             OakDefaultComponents defs = new OakDefaultComponents();
             with(defs.securityProvider());
@@ -294,6 +295,17 @@ public class Jcr {
         return this;
     }
 
+    /**
+     * Disables registration of MBeans for every open Session in the repository.
+     * This gets rid of some overhead for cases where MBeans are not leveraged.
+     * @return the Jcr object
+     */
+    @NotNull
+    public Jcr withoutSessionMBeans() {
+        createSessionMBeans = false;
+        return this;
+    }
+
     private void setUpOak() {
         // whiteboard
         if (whiteboard != null) {
@@ -387,7 +399,8 @@ public class Jcr {
                     securityProvider,
                     observationQueueLength,
                     commitRateLimiter,
-                    fastQueryResultSize);
+                    fastQueryResultSize,
+                    createSessionMBeans);
         }
         return repository;
     }
diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
index ca57299777..363c5ce3bf 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
@@ -107,6 +107,7 @@ public class RepositoryImpl implements JackrabbitRepository {
 
     protected final Whiteboard whiteboard;
     protected final boolean fastQueryResultSize;
+    private final boolean createSessionMBeans;
     private final GenericDescriptors descriptors;
     private final ContentRepository contentRepository;
     private final SecurityProvider securityProvider;
@@ -147,7 +148,7 @@ public class RepositoryImpl implements JackrabbitRepository {
                           int observationQueueLength,
                           CommitRateLimiter commitRateLimiter) {
         this(contentRepository, whiteboard, securityProvider, 
-                observationQueueLength, commitRateLimiter, false);
+                observationQueueLength, commitRateLimiter, false, true);
     }
     
     public RepositoryImpl(@NotNull ContentRepository contentRepository,
@@ -155,7 +156,8 @@ public class RepositoryImpl implements JackrabbitRepository {
                           @NotNull SecurityProvider securityProvider,
                           int observationQueueLength,
                           CommitRateLimiter commitRateLimiter,
-                          boolean fastQueryResultSize) {
+                          boolean fastQueryResultSize,
+                          boolean createSessionMBeans) {
         this.contentRepository = checkNotNull(contentRepository);
         this.whiteboard = checkNotNull(whiteboard);
         this.securityProvider = checkNotNull(securityProvider);
@@ -166,6 +168,7 @@ public class RepositoryImpl implements JackrabbitRepository {
         this.clock = new Clock.Fast(scheduledExecutor);
         this.gcMonitorRegistration = whiteboard.register(GCMonitor.class, gcMonitor, emptyMap());
         this.fastQueryResultSize = fastQueryResultSize;
+        this.createSessionMBeans = createSessionMBeans;
         this.mountInfoProvider = WhiteboardUtils.getService(whiteboard, MountInfoProvider.class);
         this.blobAccessProvider = WhiteboardUtils.getService(whiteboard, BlobAccessProvider.class);
         this.frozenNodeLogger = new FrozenNodeLogger(clock, whiteboard);
@@ -318,10 +321,11 @@ public class RepositoryImpl implements JackrabbitRepository {
         return new SessionDelegate(
                 contentSession, securityProvider, refreshStrategy,
                 threadSaveCount, statisticManager, clock) {
+            
             // Defer session MBean registration to avoid cluttering the
             // JMX name space with short lived sessions
-            RegistrationTask registrationTask = new RegistrationTask(getSessionStats(), whiteboard);
-            ScheduledFuture<?> scheduledTask = scheduledExecutor.schedule(registrationTask, 1, TimeUnit.MINUTES);
+            final RegistrationTask registrationTask = createSessionMBeans ? new RegistrationTask(getSessionStats(), whiteboard) : null;
+            final ScheduledFuture<?> scheduledTask = createSessionMBeans ? scheduledExecutor.schedule(registrationTask, 1, TimeUnit.MINUTES) : null;
 
             @Override
             protected void treeLookedUpByIdentifier(@NotNull Tree tree) {
@@ -331,9 +335,11 @@ public class RepositoryImpl implements JackrabbitRepository {
             @Override
             public void logout() {
                 refreshOnGC.close();
-                // Cancel session MBean registration
-                registrationTask.cancel();
-                scheduledTask.cancel(false);
+                if (registrationTask != null) {
+                    // Cancel session MBean registration
+                    registrationTask.cancel();
+                    scheduledTask.cancel(false);
+                }
                 super.logout();
             }
         };