浏览代码

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 <benedictjin2016@gmail.com>

Reviewers: andor@apache.org

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
asdf2014 6 年之前
父节点
当前提交
91c6cb253c

+ 4 - 1
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
 used by editing the appender and root thresholds. Log4j MBean
 registration can be disabled by passing
 registration can be disabled by passing
 _-Dzookeeper.jmx.log4j.disable=true_ to the JVM
 _-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>
 <a name="ch_reference"></a>
 
 

+ 5 - 4
zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java

@@ -33,13 +33,13 @@ import org.slf4j.LoggerFactory;
 public class ManagedUtil {
 public class ManagedUtil {
     private static final Logger LOG = LoggerFactory.getLogger(ManagedUtil.class);
     private static final Logger LOG = LoggerFactory.getLogger(ManagedUtil.class);
 
 
-    private static final boolean isLog4jJmxEnabled() {
+    private static boolean isLog4jJmxEnabled() {
         boolean enabled = false;
         boolean enabled = false;
 
 
         try {
         try {
             Class.forName("org.apache.log4j.spi.LoggerRepository");
             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.");
                 LOG.info("Log4j found but jmx support is disabled.");
             } else {
             } else {
                 enabled = true;
                 enabled = true;
@@ -69,9 +69,10 @@ public class ManagedUtil {
             try {
             try {
                 // Create and Register the top level Log4J MBean
                 // Create and Register the top level Log4J MBean
                 // org.apache.log4j.jmx.HierarchyDynamicMBean hdm = new org.apache.log4j.jmx.HierarchyDynamicMBean();
                 // 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);
                 mbs.registerMBean(hdm, mbo);
 
 
                 // Add the root logger to the Hierarchy MBean
                 // Add the root logger to the Hierarchy MBean