5 Replies Latest reply on Mar 12, 2007 12:10 PM by Brian Stansberry

    JBCACHE-1001 Discussion Thread

    Brian Stansberry Master

      Discussion related to http://jira.jboss.com/jira/browse/JBCACHE-1001.

      "Galder Zamarreno" wrote:

      Brian,

      Indeed, Hibernate create the cache instances themselves:

      OptimisticTreeCacheProvider:
      ....
      cache = new org.jboss.cache.TreeCache();
      PropertyConfigurator config = new PropertyConfigurator();
      config.configure( cache, resource );
      TransactionManagerLookup transactionManagerLookup =
      ....

      so they should call startService()/stopService()

      However, if they do this, they've never gonna get this cache
      registered in MBeanServer, even if it runs inside AS.

      I guess it would then be customer's responsability to make
      sure that the cache config file ends in *-service.xml and they
      make use of:

      <property name="cache.provider_configuration_file_resource_path">hb-cache-service.xml</property>

      The downside of all this is that, in my standalone example, I
      would need to code myself the registration of this cache into the an
      MBeanServer so that later I can use JConsole to inspect it, correct?


      In 1.4.x, the cache registers itself and its interceptors in JMX. (In 2.0 you need to use a wrapper class if you want that; something we need to make sure works right with Hibernate.)

      This is why the reported error was javax.management.InstanceNotFoundException. If the cache hadn't been registered in JMX and you called stop(), it would have worked. That's why you needed to use -Dcom.sun.management.jmxremote to see the failure.

      Probably in 1.4.x, JBC should override create/start/stop/destroy such that they don't invoke on the ServiceController if it isn't present. One possible way to do that:

      private boolean useServiceController = false;
      
      public void postRegister(Boolean registrationDone)
      {
       super.postRegister(registrationDone);
      
       if (registrationDone.booleanValue())
       {
       // Confirm that the ServiceController is registered; if not, don't
       // use the superclass lifecycle methods
       try
       {
       server.getMBeanInfo(ServiceController.OBJECT_NAME);
       useServiceController = true;
       }
       catch (Throwable t)
       {
       useServiceController = false;
       }
       }
      }
      
      public void create() throws Exception
      {
       if (useServiceController)
       {
       super.create();
       }
       else
       {
       createService();
       }
      }
      
      ... repeat for start()/stop()/destroy()