0 Replies Latest reply on Jul 23, 2008 9:29 AM by Robert Buck

    Use the correct MBeanServer if multiple MBeanServers are pre

    Robert Buck Newbie

      The prior bug did not fix the issue of running the cache under jboss when the following options are present:

      set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote

      The code is presently as follows (which is incorrect, by the way):

      158 if(servers == null || servers.size() == 0)
      159 throw new Exception("TreeCacheView.init(): no MBeanServers found");
      160 srv=(MBeanServer)servers.get(0);
      161 log.info("init(): found MBeanServer " + srv);
      162 cache=(TreeCacheMBean)MBeanProxyExt.create(
       TreeCacheMBean.class, cache_service, srv);

      TreeCacheView fails to deploy because it is using the wrong MBeanServer. Rather than doing the above, you should either do something like:

       import org.jboss.mx.util.MBeanServerLocator;
       // find the local MBeanServer
       MBeanServer server = MBeanServerLocator.locateJBoss();

      , or you should do something like this:

      public static MBeanServer getDefaultMBeanServer() {
       return findMBeanServer("jboss");
       private static MBeanServer findMBeanServer(String agentId) {
       List servers = MBeanServerFactory.findMBeanServer(null);
       if (servers != null && servers.size() > 0) {
       for (Object object : servers) {
       MBeanServer server = (MBeanServer) object;
       if (server.getDefaultDomain().equals(agentId)) {
       return server;
       return null;

      The reason is because with Java 5, when the "-Dcom.sun.management.jmxremote" switch is turned on, the default platform MBeanServer is the zeroth instance rather than "jboss".



      To test, deploy the tree cache view, and start JBoss with the JAVA_OPTS mentioned above.