Bug 30055 - Problem with registering Appenders with the same name in the LoggerDynamicMBean
Summary: Problem with registering Appenders with the same name in the LoggerDynamicMBean
Status: NEW
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC All
: P3 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-12 15:51 UTC by noga
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description noga 2004-07-12 15:51:23 UTC
I'm creating a management system that includes using MBeans to manage the 
logger module. 

the logger is configured in an xml file and includes some appenders and some 
loggers that use these appenders.  loggers may use the same appenders. the 
appenders' name is used to compose it's ObjectName when registering it as an 
AppenderDynamicMBean. therefore, if 2 loggers use the same appender, they will 
both try to register them in the MBeanServer. as soon as the first request is 
made, all others will fail -due to the duplication of the ObjectName assigned 
for the MBean. and the problem occurs in the following code in 
LoggerDynamicMBean.java:

  void registerAppenderMBean(Appender appender) {
    String name = appender.getName();
    cat.debug("Adding AppenderMBean for appender named "+name);
    ObjectName objectName = null;
    try {
      AppenderDynamicMBean appenderMBean = new AppenderDynamicMBean(appender);
      objectName = new ObjectName("log4j", "appender", name);
      server.registerMBean(appenderMBean, objectName);

      dAttributes.add(new MBeanAttributeInfo("appender="+name,
					     "javax.management.ObjectName",
					     "The "+name+" appender.",
					     true,
					     true,
					     false));

    } catch(Exception e) {
      cat.error("Could not add appenderMBean for ["+name+"].", e);
    }
  }

The part when the second logger tries to register the appender, 
an "InstanceAlreadyExistsException" is thrown (which is ok) however the 
following line is not executed (which is not ok!). and the appender is never 
registered as the MBean's attribute!

I would suggest catch the "InstanceAlreadyExistsException" separately and when 
it is being caught - to still add the appender as the attribute of the 
LoggerDynamicMBean - that fact that it already exists on the MBeanServer does 
not mean it should not be registered as an attribute of the LoggerDynamicMBean.