5 Replies Latest reply on Jul 5, 2007 12:29 PM by Fredrik Johansson

    2.0 and JMX

    Fredrik Johansson Newbie

      I'm using 2.0 in a standalone application. When using 1.4 I got the JBoss Cache registered to JMX by default (I think). Now when we are testing out 2.0, it doesn't seem to get registered to JMX anymore.

      However, registering the cache manually works perfectly fine:

      CacheImpl cache = createCache();
      MBeanServer mbs = getMBeanServer();
      mbs.registerMBean(cache.getCacheMBeanInterface(), monitorName);

      Is this the new preferred way of registering a cache to JMX or are you planning a more automated way? Using the method above also means we have to reference CacheImpl (and not just Cache).

      Also, while I'm at it, I realize that the MBean interface is work-in-progress since it is still missing out on a lot of information if you compare it to 1.4. However, I would vote for adding the getMembers() so we can easily inspect the members of a distributed cache via JConsole (or any other JMX tool).

        • 1. Re: 2.0 and JMX
          Brian Stansberry Master

          In JBC 2.0, the cache no longer self registers; you have to do it manually. Basically, we recognized that JMX integration is really not a core function of the cache, and 1) should be done by external code that understands the JMX environment, and 2) should be extracted into a separate class.

          What you should do is:

          Cache cache = createCache();
          MBeanServer mbs = getMBeanServer();
          mbs.registerMBean(new org.jboss.cache.jmx.CacheJmxWrapper(cache), monitorName);

          CacheJmxWrapper exposes a property "registerInterceptors", which defaults to true. When you register the wrapper in JMX, it gets a callback from JMX (via MBeanNotification interface) and if registerInterceptors=true it will register mbeans for all the interceptors.

          I haven't looked at this for a while, and it may not work yet, but you can also try this semi-hacky trick:

          Cache cache = createCache();
          MBeanServer mbs = getMBeanServer();
          mbs.registerMBean(new org.jboss.cache.jmx.CacheLegacyJmxWrapper(cache), monitorName);

          (note use of CacheLegacyJmxWrapper).

          CacheLegacyJmxWrapper actually exposes via JMX getters for a lot of the configuration options.

          I'll defer to Manik as to whether he wants to expose getMembers().

          • 2. Re: 2.0 and JMX
            Nolan Johnson Newbie

            A couple of things:

            It would be a good idea if this were documented. The 2.0 documentation still implies that no registration is necessary for JMX.

            Second, anybody have quick hints (or links) for a JMX newbie? I'm not really interested in learning so much about it right now - I just want to be able to use jconsole to check the state of jbosscache 2.0 in a standalone app.... Particularly, in the code snippets in the thread, I don't know how to get the mbean server or what the monitor name should be (I've figured out that there's an MBeanServerFactory and I can create or get an mbean server from that, I'm not sure whether I should create one or get one, and how the names relate).


            • 3. Re: 2.0 and JMX
              Nolan Johnson Newbie

              To answer my own question, this seems to work:

              _cache = createCache();
               ArrayList mbServers = MBeanServerFactory.findMBeanServer( null );
               if (mbServers.size() > 0)
               MBeanServer mbs = (MBeanServer) mbServers.get( 0 );
               mbs.registerMBean( new org.jboss.cache.jmx.CacheJmxWrapper( _cache ),
               new ObjectName( JmxUtil.getDefaultCacheObjectName( _cache ) ) );

              • 4. Re: 2.0 and JMX
                Brian Stansberry Master

                Yes, what you are doing is correct.

                You're right about the docs. This whole area of the docs was completely rewritten for 2.0.0.CR3, which should be out within a couple days.

                • 5. Re: 2.0 and JMX
                  Fredrik Johansson Newbie

                  I omitted the getMbeanServer() since it is environment dependent. A oneliner approach to getting the default server is like this:

                  private MBeanServer getMBeanServer() {
                   return ManagementFactory.getPlatformMBeanServer();