Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-2822: Wrong ObjectName about MBeanServer in JMX module #294

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,13 +33,13 @@
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;
Expand Down Expand Up @@ -69,9 +69,13 @@ public static void registerLog4jMBeans() throws JMException {
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.getenv("zookeeper.jmx.log4j.mbean");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use System.getProperty(name,defaultvalue)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would go for a system property

FYI, System.getenv() is for Operating System environment variables, whereas System.getProperty() is for JVM arguments which are passed as -DpropName=value to Java application launcher.

So, maybe use getenv() would be more reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know in ZK it is common to use System Properties and not environment variables.

I think that the launcher for the server process is setting as system property every configuration parameter.

Do you have any example of usages of getEnv in ZooKeeper ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eolivelli Okay, I will modify it.

if (mbean == null || mbean.trim().length() == 0) {
mbean = "log4j:hierarchy=default";
}
ObjectName mbo = new ObjectName(mbean);
mbs.registerMBean(hdm, mbo);

// Add the root logger to the Hierarchy MBean
Expand Down