Announcement Announcement Module
Collapse
No announcement yet.
Trouble with Spring JMX with JBoss 4.0.3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with Spring JMX with JBoss 4.0.3

    I'm trying to get my application's Spring-exported JMX beans to show up in both jconsole and in the JBoss JMX console under Java 1.5. To that end, I've configured JBoss to use the platform MBeanServer, as described here

    http://wiki.jboss.org/wiki/Wiki.jsp?...eansInJConsole

    After doing this and starting up JBoss, as JBoss is starting up if I attach to the MBeanServer using jconsole, I see all the standard Java MBeans loaded, as well as JBoss MBeans load. When Spring finally exports my application's MBeans, however, all MBeans disappear from jconsole _except_ my application's MBeans and one named JMImplementation:name=MBeanServerDelegate. The same beans are also what show up in JBoss's web /jmx-console.

    If I don't configure JBoss to use the platform MBeanServer, but leave the -Dcom.sun.management.jmxremote flag for the JVM, then the Spring-exported beans show up in jconsole only, and all the JBoss beans show up in the /jmx-console only.

    If I don't have the -Dcom.sun.management.jmxremote configured at all for JBoss, then the Spring-exported beans and all the JBoss beans show up together in the /jmx-console.

    What I'd really like is for all beans to show up using jconsole as well as the /jmx-console. Anybody have any luck with this?

  • #2
    Funny I am working on the same problem on the same day.
    I have a Spring application where there is a org.springframework.jmx.access.MBeanProxyFactoryBe an pointing to one of Jboss's Mbeans.

    Everything worked great up until I put -D com.sun.management.jmxremote in the Jboss startup script to be able to use jconsole. At this point, application fails to deploy with the javax.management.InstanceNotFoundException basically telling me that MBean in question is not found.

    Prior in the log there is the following (bean name obscured):
    16:37:26,952 INFO [DefaultListableBeanFactory] Creating shared instance of singleton bean '..MBean'
    16:37:26,972 WARN [JmxUtils] Found more than one MBeanServer instance. Returning first from list.

    This leads me to believe that Mbean server deployed by jconsole interferes with Jboss mbean server.

    Is there a way to tell Spring which Mbean server to use? Any other suggestions?

    Comment


    • #3
      What's your configuration? JmxUtils has a method for searching an mbean server with a given agentId - you can use that yourself to give the exporter the approapriate server using the factory support inside the XML app context.

      Comment


      • #4
        I found the problem for me, it had to do with two MBeanServer's being created. I had a class that contained

        Code:
        private final MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer("system-tool");
        which caused two instances of JBoss's org.jboss.system.server.jmx.LazyMBeanServer to be created. When I removed the code that created the system-tool MBeanServer, the problem went away and all JBoss beans, JDK beans, and my application beans show up in JConsole as well as /jmx-console.

        This must be more of an issue with JBoss's code, not Spring's.

        Comment


        • #5
          This must be more of an issue with JBoss's code, not Spring's.
          Is there a rule saying that only one MBeanServer can be created? -- I don't think so.

          Given that the entire JBoss architecture is based around JMX, and they were the first to do this, I'd expect they know what they're doing when it comes to JMX.

          I think what costin said is more along the right track.

          Comment


          • #6
            Originally posted by gmatthews
            Is there a rule saying that only one MBeanServer can be created? -- I don't think so.
            Nor did I suggest that. I'm merely saying that the way JBoss 4.0.3 integrates the JDK 1.5 platform MBeanServer with it's own implementation has some twists that I need to work around.

            Originally posted by gmatthews
            I think what costin said is more along the right track.
            I haven't found the way to get the JBoss MBeanServer instance's agentId to pass this to Spring (but I haven't looked thoroughly) so I can't say if that does anything to work around the problem or not. If you know an easy way to get the agentId, I'd be happy to try it out.

            Comment


            • #7
              I think this thread may need to be turned into a Jira request.

              The 3 complicating factors are that:

              1. You may or may not be using java5, and have used the flag to cause the VM to start an MBeanServer

              2. You may or may not be using an appserver or other container that starts it's own MBeanServer

              3. There may be multiple MBeanServers

              I haven't looked that thoroughly either, but there's a public void setServer(MBeanServer server) method in org.springframework.jmx.export.MBeanExporter

              If no magic Spring class exists, would it be possible to create your own factory to supply an MBeanServer, based on querying whatever environment you know you'll be running in?

              Comment


              • #8
                What about using setServer along with JMXUtils.locateMBeanServer; smth like (from the tip of my head):

                Code:
                <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
                        lazy-init="false">
                    <property name="server">
                      <bean class="org.springframework.jmx.JmxUtils" factory-method="locateMBeanServer">
                         <constructor-arg value="myJmxMBeanServerName"/>
                      </bean>
                    </property>
                </bean>

                Comment


                • #9
                  Originally posted by costin
                  What about using setServer along with JMXUtils.locateMBeanServer; smth like (from the tip of my head):

                  Code:
                  <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
                          lazy-init="false">
                      <property name="server">
                        <bean class="org.springframework.jmx.JmxUtils" factory-method="locateMBeanServer">
                           <constructor-arg value="myJmxMBeanServerName"/>
                        </bean>
                      </property>
                  </bean>
                  The trouble is I don't know a way to find out JBoss' agentId. I think the issues still comes back to the way JBoss integrates into the Java 5 platform MBeanServer. Since to do this you have to use JBoss's MBeanServerBuilder (i.e. -Djavax.management.builder.initial=org.jboss.system .server.jmx.MBeanServerBuilderImpl), and then creating servers with MBeanServerFactory.createMBeanServer("foo") creates multiple instances of JBoss' LazyMBeanServer, which JBoss doesn't seem to deal well with.

                  In the end, I'm just looking for an existing MBeanServer and using that if it exists. That solves the issue.

                  Comment


                  • #10
                    You can take a look at the code inside JmxUtils to see how to list the mbean servers in the current jvm. The MBeanServerBuilder from JBoss most probably does decoration - you can find more about this in the JMX and MX4J documentation.

                    Comment


                    • #11
                      Locate jboss mbeanserver

                      Originally posted by costin
                      What about using setServer along with JMXUtils.locateMBeanServer; smth like (from the tip of my head):

                      Code:
                      <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
                              lazy-init="false">
                          <property name="server">
                            <bean class="org.springframework.jmx.JmxUtils" factory-method="locateMBeanServer">
                               <constructor-arg value="myJmxMBeanServerName"/>
                            </bean>
                          </property>
                      </bean>
                      You can also use a locator from JBoss:

                      Code:
                      <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"
                              lazy-init="false">
                          <property name="server">
                            <bean class="org.jboss.mx.util.MBeanServerLocator" factory-method="locateJBoss"/>
                          </property>
                      </bean>
                      http://wiki.jboss.org/wiki/Wiki.jsp?...indMBeanServer

                      Comment


                      • #12
                        I certainly don't think there is a bug in either codebase related to this. Its simply a case of one set of objects being registed in one MBeanServer and another set inside a second MBeanServer. Spring will try to locate the running MBeanServer but it can only guess at the first MBeanServer it encounters unless you specify an agentId.

                        Look at MBeanServerFactoryBean for more information on configuring lookup.

                        Comment

                        Working...
                        X