Bug 42017 - InstanceAlreadyExistsException using MBean
Summary: InstanceAlreadyExistsException using MBean
Status: RESOLVED FIXED
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.2
Hardware: PC Windows 2000
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-02 03:06 UTC by Francesco Dalan
Modified: 2007-04-23 16:09 UTC (History)
0 users



Attachments
Adds a test before register a MBean (8.33 KB, patch)
2007-04-02 03:46 UTC, Francesco Dalan
Details | Diff
Adds a test before register a MBean (8.33 KB, patch)
2007-04-02 03:46 UTC, Francesco Dalan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francesco Dalan 2007-04-02 03:06:53 UTC
Hi, when I use the MBean architecture with mx4j implementation to manage the 
logging parameters, I have an InstanceAlreadyExistsException. This happen when 
the org.apache.log4j.jmx.AppenderDynamicMBean try to register a layout 
(registerLayoutMBean method) because do not check if the MBean is already 
registered. Here there is the code that I use

MBeanServer server = MBeanServerFactory.createMBeanServer();
HierarchyDynamicMBean hdm = new HierarchyDynamicMBean();
...
LoggerRepository r = LogManager.getLoggerRepository();
Enumeration enum = r.getCurrentLoggers();
Logger logger = null;
while (enum.hasMoreElements()) {
  logger = (Logger) enum.nextElement();
  ObjectName dummy = new ObjectName("log4j", "logger", logger.getName());
  if (!server.isRegistered(dummy))
    hdm.addLoggerMBean(logger.getName());
}

and the log4j.properties

# Console is set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d %-5p %c{1}.%M - %m%n

# FileConsole is set to be a FileAppender.
log4j.appender.FileConsole.File=\\wcubecoils.log
log4j.appender.FileConsole=org.apache.log4j.FileAppender
log4j.appender.FileConsole.layout=org.apache.log4j.PatternLayout
log4j.appender.FileConsole.layout.ConversionPattern=%d %-5p %c{1}.%M - %m%n

# the root logger
log4j.rootLogger=INFO, FileConsole

# wcube logging configuration...
log4j.logger.it.mbm.wcube.processmessage=TRACE, FileConsole
log4j.logger.it.mbm.wcube.mq.bo.action=TRACE, FileConsole
Comment 1 Francesco Dalan 2007-04-02 03:46:02 UTC
Created attachment 19866 [details]
Adds a test before register a MBean

The patch have been marked by the patch comment
Comment 2 Francesco Dalan 2007-04-02 03:46:31 UTC
Created attachment 19867 [details]
Adds a test before register a MBean

The patch have been marked by the patch comment
Comment 3 Paul Smith 2007-04-23 15:10:19 UTC
1.2.15 candidate
Comment 4 Paul Smith 2007-04-23 16:09:36 UTC
Done in revision 531643