Repository: zookeeper
Updated Branches:
  refs/heads/master 1c488cec0 -> 91c6cb253


ZOOKEEPER-2822: Wrong `ObjectName` about `MBeanServer` in JMX module

The wrong `ObjectName` about `MBeanServer` in JMX module, should 
`log4j:hierarchy=default` rather than `log4j:hiearchy=default`.

Author: asdf2014 <[email protected]>

Reviewers: [email protected]

Closes #294 from asdf2014/ZOOKEEPER-2822 and squashes the following commits:

294cf53ab [asdf2014] Using `System.getProperty` instead of `System.getenv` & 
doc this change
ed756a9b8 [asdf2014] Add `zookeeper.jmx.log4j.mbean`
82da83a71 [asdf2014] ZOOKEEPER-2822: Wrong `ObjectName` about `MBeanServer` in 
JMX module


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/91c6cb25
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/91c6cb25
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/91c6cb25

Branch: refs/heads/master
Commit: 91c6cb253c98a5c792314b1c7998ab5b939dddad
Parents: 1c488ce
Author: asdf2014 <[email protected]>
Authored: Tue Nov 27 09:57:53 2018 +0100
Committer: Andor Molnar <[email protected]>
Committed: Tue Nov 27 09:57:53 2018 +0100

----------------------------------------------------------------------
 zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md  | 5 ++++-
 .../src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java | 9 +++++----
 2 files changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/91c6cb25/zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md
----------------------------------------------------------------------
diff --git a/zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md 
b/zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md
index 5a6686f..34355b2 100644
--- a/zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md
+++ b/zookeeper-docs/src/main/resources/markdown/zookeeperJMX.md
@@ -84,7 +84,10 @@ interest is the ability to dynamically change the logging 
levels
 used by editing the appender and root thresholds. Log4j MBean
 registration can be disabled by passing
 _-Dzookeeper.jmx.log4j.disable=true_ to the JVM
-when starting ZooKeeper.
+when starting ZooKeeper. In addition, we can specify the name of
+the MBean with the _-Dzookeeper.jmx.log4j.mbean=log4j:hierarchy=default_
+option, in case we need to upgrade an integrated system
+using the old MBean name (`log4j:hiearchy = default`).
 
 <a name="ch_reference"></a>
 

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/91c6cb25/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
----------------------------------------------------------------------
diff --git 
a/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java 
b/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
index 43451b0..04b5bdd 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
@@ -33,13 +33,13 @@ import org.slf4j.LoggerFactory;
 public class ManagedUtil {
     private static final Logger LOG = 
LoggerFactory.getLogger(ManagedUtil.class);
 
-    private static final boolean isLog4jJmxEnabled() {
+    private static boolean isLog4jJmxEnabled() {
         boolean enabled = false;
 
         try {
             Class.forName("org.apache.log4j.spi.LoggerRepository");
 
-            if (Boolean.getBoolean("zookeeper.jmx.log4j.disable") == true) {
+            if (Boolean.getBoolean("zookeeper.jmx.log4j.disable")) {
                 LOG.info("Log4j found but jmx support is disabled.");
             } else {
                 enabled = true;
@@ -69,9 +69,10 @@ public class ManagedUtil {
             try {
                 // Create and Register the top level Log4J MBean
                 // org.apache.log4j.jmx.HierarchyDynamicMBean hdm = new 
org.apache.log4j.jmx.HierarchyDynamicMBean();
-                Object hdm = 
Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").getDeclaredConstructor().newInstance();
+                Object hdm = 
Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").getConstructor().newInstance();
 
-                ObjectName mbo = new ObjectName("log4j:hiearchy=default");
+                String mbean = System.getProperty("zookeeper.jmx.log4j.mbean", 
"log4j:hierarchy=default");
+                ObjectName mbo = new ObjectName(mbean);
                 mbs.registerMBean(hdm, mbo);
 
                 // Add the root logger to the Hierarchy MBean

Reply via email to