Announcement Announcement Module
Collapse
No announcement yet.
Registering JMX Beans on the same JVM Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Registering JMX Beans on the same JVM

    Hi Guys,

    I have come across a strange error today. I am using a Spring JMX bean to change logging level at runtime. Now this is as part of my framework code which each application will share rather than having each application to write their own JMX beans Now I had to give a constant name to my JMX Bean as shown below.

    @ManagedResource(objectName="bean:name=JJSSLF4JLog gerLevelChanger", description="Changes Logging Levels")
    public class JJSSLF4JLoggerLevelChanger {

    But the problem is if I deploy two applications using my framework code on the same JVM, Spring throws below exception.

    [09/10/08 11:47:04:841 BST] 00000013 SystemOut O ERROR JJS: ORB.thread.pool : 1 Context initialization failed from: org.springframework.web.context.ContextLoader
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'beanExporter' defined in URL
    Invocation of init method failed; nested exception is org.springframework.jmx.export.UnableToRegisterMBe anException: Unable to register MBean [com.johnlewis.jjs2.common.logging.jmx.JJSSLF4JLogg erLevelChanger@8de08de] with key 'bean:name=JJSSLF4JLoggerLevelChanger'; nested exception is javax.management.InstanceAlreadyExistsException: WebSphere:cell=cs-dikkgtd6xNode02Cell,name=cs-dikkgtd6xNode02Cell,type=JJSSLF4JLoggerLevelChange r,node=cs-dikkgtd6xNode02,process=server1
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1362)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Access Controller.java:192)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:413)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:735)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:369)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:251) ....more

    at Caused by:

    org.springframework.jmx.export.UnableToRegisterMBe anException: Unable to register MBean [com.johnlewis.jjs2.common.logging.jmx.JJSSLF4JLogg erLevelChanger@8de08de] with key 'bean:name=JJSSLF4JLoggerLevelChanger'; nested exception is javax.management.InstanceAlreadyExistsException: WebSphere:cell=cs-dikkgtd6xNode02Cell,name=cs-dikkgtd6xNode02Cell,type=JJSSLF4JLoggerLevelChange r,node=cs-dikkgtd6xNode02,process=server1
    at org.springframework.jmx.export.MBeanExporter.regis terBeanNameOrInstance(MBeanExporter.java:604)
    at org.springframework.jmx.export.MBeanExporter.regis terBeans(MBeanExporter.java:511)
    at org.springframework.jmx.export.MBeanExporter.after PropertiesSet(MBeanExporter.java:402)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1390)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1359)
    ... 70 more
    Caused by:
    javax.management.InstanceAlreadyExistsException: WebSphere:cell=cs-dikkgtd6xNode02Cell,name=cs-dikkgtd6xNode02Cell,type=JJSSLF4JLoggerLevelChange r,node=cs-dikkgtd6xNode02,process=server1
    at com.sun.jmx.mbeanserver.RepositorySupport.addMBean (RepositorySupport.java:470)
    at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.internal_addObject(DefaultMBeanServerIntercept or.java:1428)
    at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.registerObject(DefaultMBeanServerInterceptor.j ava:954)
    at com.sun.jmx.interceptor.DefaultMBeanServerIntercep tor.registerMBean(DefaultMBeanServerInterceptor.ja va:355)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBe an(JmxMBeanServer.java:515)
    at com.ibm.ws.management.PlatformMBeanServer.register MBean(PlatformMBeanServer.java:472)
    at org.springframework.jmx.support.MBeanRegistrationS upport.doRegister(MBeanRegistrationSupport.java:16 2)
    at org.springframework.jmx.export.MBeanExporter.regis terBeanInstance(MBeanExporter.java:677)
    at org.springframework.jmx.export.MBeanExporter.regis terBeanNameOrInstance(MBeanExporter.java:594)
    ... 74 more
    The error makes sense but can you advise if there is any solution around this problem... does this mean I can not make this JMX part of the my framework code and each application would need to have their own JMX Beans.

    Looking for a positive answer.

    Cheers,
    Sanjay Patil

  • #2
    Try with registration behavior setting to REGISTRATION_IGNORE_EXISTING. See org.springframework.jmx.support.MBeanRegistrationS upport. Also maybe you can implements your own ObjectNamingStrategy to have differente objectName depending the application you you.
    Last edited by jmiddleton; Nov 16th, 2008, 12:52 PM.

    Comment

    Working...
    X