2 Replies Latest reply on Mar 4, 2011 10:23 PM by tarundeep_singh

    exception from CacheJmxWrapperMBean.getCache()

    szerintedmi

      I'm trying to reach the same cache (3.2.5.GA) from two different webapps running on the same Tomcat.

       

      The first time it starts I'm registering with the following code:

      {code}

      Cache jbossCache = new DefaultCacheFactory().createCache(configFile);
      CacheJmxWrapperMBean cacheJmxWrapper = new CacheJmxWrapper(jbossCache);


      ObjectInstance oi = mBeanServer.registerMBean(cacheJmxWrapper, on);

      // tryied this way too:

      //JmxRegistrationManager jmxRegManager = new  JmxRegistrationManager(mBeanServer, jbossCache, on);
      //jmxRegManager.registerAllMBeans();

                     
      log.info("Cache started. MBean objName: " + oi.getObjectName());

      {code}

       

      I try to get a reference through JMX with this code:

      {code}

      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();


      cacheJmxWrapper =
                              (CacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, on,
                              CacheJmxWrapperMBean.class, false);


      Object o;   // just to show the issue
      o = cacheJmxWrapper.getCache();

      {code}

       

      I receive the following exception from the last line:

      {code}

      java.lang.ClassCastException: org.jboss.cache.invocation.CacheInvocationDelegate cannot be cast to org.jboss.cache.Cache
              at $Proxy17.getCache(Unknown Source)

      {code}

      I tried several different methods to register/get reference.

      Am I missing a point or is it a bug?

       

      As I read JNDI would be a workaround but can't find proper description how to setup (and setting on production server would be a bit complicated because of restricted access).

      Is there any other way to reach the same cache from different webapps?

        • 1. Re: exception from CacheJmxWrapperMBean.getCache()
          galder.zamarreno

          Did you follow these steps? http://docs.jboss.org/jbosscache/3.0.3.GA/userguide_en/html/deployment.html#jmx.registration

           

          They're slightly different to what you're doing.

          • 2. exception from CacheJmxWrapperMBean.getCache()
            tarundeep_singh

            Hi Peter,

            Good Morning.

             

            I was struggling with this issue until yesterday. Saw your post, took some help from it. And then I faced the same problem as you did. I actually also got lucky to resolve this issue.

            This is a two step process:

            1. The call to cacheJmxWrapper.getCache() will be actually returning cacheJmxWrapper.getCache() an instance of org.jboss.cache.invocation.CacheInvocationDelegate. Therefore, the type casting needs to be corrected here.

            • java.lang.ClassCastException: org.jboss.cache.invocation.CacheInvocationDelegate cannot be cast to org.jboss.cache.Cache

                    at $Proxy17.getCache(Unknown Source)

                      This actually happenned since my both applications were using there own set of JBoss Cache related jars. And since different instances of class loaders were loading these jars, these class cast exception took place. Resolution to this was to take these Jboss cache related jars from each of the applications and store them inside the application servers instance.

             

            The issue got resolved and a single instance of Jboss cache was accessible for both the applications.

             

            This also answers that this is not a defect in JBoss Cache.

             

            Thank you.

            Enjoy.