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/10/11 06:26:08 UTC
[jackrabbit-oak] branch trunk updated: OAK-9959 allow to disable registering MBeans for every Session (#724)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 01a6709f76 OAK-9959 allow to disable registering MBeans for every Session (#724)
01a6709f76 is described below
commit 01a6709f76f65a5118ee18c8f5b194d29d1d60b9
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Oct 11 08:26:02 2022 +0200
OAK-9959 allow to disable registering MBeans for every Session (#724)
---
.../L4_CustomAccessControlManagementTest.java | 4 +++-
.../main/java/org/apache/jackrabbit/oak/jcr/Jcr.java | 18 ++++++++++++++++--
.../jackrabbit/oak/jcr/osgi/OsgiRepository.java | 2 +-
.../oak/jcr/repository/RepositoryImpl.java | 20 +++++++++++++-------
4 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L4_CustomAccessControlManagementTest.java b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L4_CustomAccessControlManagementTest.java
index 456b658978..4e1f265589 100644
--- a/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L4_CustomAccessControlManagementTest.java
+++ b/oak-exercise/src/test/java/org/apache/jackrabbit/oak/exercise/security/authorization/advanced/L4_CustomAccessControlManagementTest.java
@@ -282,7 +282,8 @@ public class L4_CustomAccessControlManagementTest extends AbstractSecurityTest {
getSecurityProvider(),
Jcr.DEFAULT_OBSERVATION_QUEUE_LENGTH,
null,
- false);
+ false,
+ true);
}
@@ -469,6 +470,7 @@ public class L4_CustomAccessControlManagementTest extends AbstractSecurityTest {
getSecurityProvider(),
Jcr.DEFAULT_OBSERVATION_QUEUE_LENGTH,
null,
+ false,
false);
Session adminSession = jcrRepository.login(getAdminCredentials(), null);
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..2781f4fdc3 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
@@ -30,6 +30,7 @@ import javax.jcr.Repository;
import org.apache.jackrabbit.oak.Oak;
import org.apache.jackrabbit.oak.Oak.OakDefaultComponents;
import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.jmx.SessionMBean;
import org.apache.jackrabbit.oak.jcr.repository.RepositoryImpl;
import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter;
@@ -88,6 +89,7 @@ public class Jcr {
private int observationQueueLength = DEFAULT_OBSERVATION_QUEUE_LENGTH;
private boolean fastQueryResultSize;
+ private boolean createSessionMBeans = true; // by default every (long-living) session will register an MBean
private ContentRepository contentRepository;
private Repository repository;
@@ -96,7 +98,6 @@ public class Jcr {
public Jcr(Oak oak, boolean initialize) {
this.oak = oak;
-
if (initialize) {
OakDefaultComponents defs = new OakDefaultComponents();
with(defs.securityProvider());
@@ -294,6 +295,18 @@ public class Jcr {
return this;
}
+ /**
+ * Disables registration of {@link SessionMBean} for every open Session in the repository.
+ * This gets rid of some overhead for cases where MBeans are not leveraged.
+ * @return the Jcr object
+ * @since 1.46
+ */
+ @NotNull
+ public Jcr withoutSessionMBeans() {
+ createSessionMBeans = false;
+ return this;
+ }
+
private void setUpOak() {
// whiteboard
if (whiteboard != null) {
@@ -387,7 +400,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/osgi/OsgiRepository.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/OsgiRepository.java
index 95d43f1b8b..6ae634db5d 100644
--- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/OsgiRepository.java
+++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/osgi/OsgiRepository.java
@@ -41,7 +41,7 @@ public class OsgiRepository extends RepositoryImpl {
CommitRateLimiter commitRateLimiter,
boolean fastQueryResultSize) {
super(repository, whiteboard, securityProvider, observationQueueLength,
- commitRateLimiter, fastQueryResultSize);
+ commitRateLimiter, fastQueryResultSize, true);
}
@Override
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();
}
};