diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-05-29 23:04:44 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-05-29 23:05:46 +0200 |
commit | 089eacb273e98b659d4f2c15721c1524e084ae07 (patch) | |
tree | 66bbe4feb61bfea1673ec882e77e60cb82f623ff /org.eclipse.jgit | |
parent | c6213ad33a36c726c8b3f0bc7284e9cbfffed84b (diff) | |
download | jgit-089eacb273e98b659d4f2c15721c1524e084ae07.tar.gz jgit-089eacb273e98b659d4f2c15721c1524e084ae07.zip |
WindowCache: conditional JMX setup
Make it possible to programmatically suppress the JMX bean
registration. In EGit it is not needed but can be rather costly
because it occurs during plug-in activation and accesses the
git user config.
Bug: 563740
Change-Id: I07ef7ae2f0208d177d2a03862846a8efe0191956
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java | 4 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java | 36 |
2 files changed, 39 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java index 852302f00c..80c8e10dec 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java @@ -470,7 +470,9 @@ public class WindowCache { mbean = new StatsRecorderImpl(); statsRecorder = mbean; - Monitoring.registerMBean(mbean, "block_cache"); //$NON-NLS-1$ + if (cfg.getExposeStatsViaJmx()) { + Monitoring.registerMBean(mbean, "block_cache"); //$NON-NLS-1$ + } if (maxFiles < 1) throw new IllegalArgumentException(JGitText.get().openFilesMustBeAtLeast1); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java index 221353a91b..a12f652598 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java @@ -47,6 +47,8 @@ public class WindowCacheConfig { private int streamFileThreshold; + private boolean exposeStats; + /** * Create a default configuration. */ @@ -58,6 +60,7 @@ public class WindowCacheConfig { packedGitMMAP = false; deltaBaseCacheLimit = 10 * MB; streamFileThreshold = PackConfig.DEFAULT_BIG_FILE_THRESHOLD; + exposeStats = true; } /** @@ -220,6 +223,39 @@ public class WindowCacheConfig { } /** + * Tell whether the statistics JMX bean should be automatically registered. + * <p> + * Registration of that bean via JMX is additionally subject to a boolean + * JGit-specific user config "jmx.WindowCacheStats". The bean will be + * registered only if this user config is {@code true} <em>and</em> + * {@code getExposeStatsViaJmx() == true}. + * </p> + * <p> + * By default, this returns {@code true} unless changed via + * {@link #setExposeStatsViaJmx(boolean)}. + * + * @return whether to expose WindowCacheStats statistics via JMX upon + * {@link #install()} + * @since 5.8 + */ + public boolean getExposeStatsViaJmx() { + return exposeStats; + } + + /** + * Defines whether the statistics JMX MBean should be automatically set up. + * (By default {@code true}.) If set to {@code false}, the JMX monitoring + * bean is not registered. + * + * @param expose + * whether to register the JMX Bean + * @since 5.8 + */ + public void setExposeStatsViaJmx(boolean expose) { + exposeStats = expose; + } + + /** * Update properties by setting fields from the configuration. * <p> * If a property is not defined in the configuration, then it is left |