4 Replies Latest reply on Mar 3, 2009 10:24 AM by arulasha

    HAServiceMBeanSupport subclasses could not get the HAPartiti

      In our application, we have created couple of Mbeans by extending the HAServiceMBeanSupport and registratered dynamically through Mbean server. This was working till last Jboss AS 5 CR2. It seems after Jboss AS 5.0.0 GA release, got the below exception while the mbean trying to send the notification.

      Code from class HAServiceImpl ...

      protected void callAsyncMethodOnPartition(String methodName, Object[] args, Class<?>[] types) throws Exception
      {
      this.partition.callAsynchMethodOnCluster(this.name, methodName, args, types, true);
      }

      It seems the partition object is null. Not sure , how to get the reference or it will be injected dynamically.

      Exception:
      02 Mar 2009 05:07:47,875 WARN [main] [com.elementk.service.cache.jboss.SimpleLmnkCache] handleNotification( javax.management.AttributeChangeNotification[source=lmnk.cache:service=CacheManager,name=BrandBroker.localesForBrand][type=jmx.attribute.change][message=SimpleLmnkCache starting] ) failed
      java.lang.NullPointerException
      at org.jboss.ha.framework.server.HAServiceImpl.callAsyncMethodOnPartition(HAServiceImpl.java:215)
      at org.jboss.ha.framework.server.HAServiceImpl.handleEvent(HAServiceImpl.java:148)
      at org.jboss.ha.jmx.AbstractHAServiceMBeanSupport.handleEvent(AbstractHAServiceMBeanSupport.java:373)
      at org.jboss.ha.jmx.AbstractHAServiceMBeanSupport.sendNotificationRemote(AbstractHAServiceMBeanSupport.java:352)
      at org.jboss.ha.jmx.AbstractHAServiceMBeanSupport.sendNotification(AbstractHAServiceMBeanSupport.java:325)
      at org.jboss.system.ServiceMBeanSupport.sendStateChangeNotification(ServiceMBeanSupport.java:616)
      at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:371)
      at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:269)
      at com.elementk.service.cache.jboss.SimpleLmnkManager.registerCacheMBean(SimpleLmnkManager.java:83)
      at com.elementk.service.cache.jboss.SimpleLmnkManager.createCache(SimpleLmnkManager.java:61)
      at com.elementk.service.cache.CacheManagerInvalidatorSupport.createCache(CacheManagerInvalidatorSupport.java:55)
      at com.elementk.service.cache.CacheStartup.startClass(CacheStartup.java:37)
      at com.elementk.util.servlet.StartupServlet.launchStartupClass(StartupServlet.java:132)
      at com.elementk.util.servlet.StartupServlet.init(StartupServlet.java:84)

      I have looked into the Jboss forum and source code for other similar issues. But have not got information to resolve this issue.

      Any help on this very appreciated.

      Thanks
      Arul Kumar

        • 1. Re: HAServiceMBeanSupport subclasses could not get the HAPar
          brian.stansberry

          How is your service being "registered dynamically through the mbean server"? Is it an mbean in a -service.xml or a pojo in a -jboss-beans.xml? If so please post the -service.xml or -jboss-beans.xml. Or are you doing it programatically? If so please post the code that instantiates and registers the service.

          • 2. Re: HAServiceMBeanSupport subclasses could not get the HAPar

            I am doing it programmetically

            Below code creates and registers

            private static void registerCacheMBean(String cacheName, SimpleLmnkCache i) {
            
             // Try to register the Invalidator as an MBean
             MBeanServer server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next();
             try
             {
             Object mbean = MBeanUtil.createMBeanForPojo(i);
             ObjectName cacheMxName = new ObjectName("lmnk.cache:service=CacheManager,name="+cacheName);
             if(server.isRegistered(cacheMxName)) {
             try {
             i.stop();
             server.unregisterMBean(cacheMxName);
             }
             catch(Throwable t) {
             log.warn("Failed to unregister existing MX bean", t);
             }
             }
             server.registerMBean(mbean, cacheMxName);
             i.start();
             }
             catch(Throwable t) {
             log.debug("Failed to register invalidator as mbean", t);
             }
             }
            


            In MbeanUtil class we have the below code to create XMBean instance

            public static Object createMBeanForPojo(Object pojo) throws NotCompliantMBeanException, MBeanException {
             return new XMBean(pojo, XMBeanConstants.STANDARD_INTERFACE);
             }


            Thanks
            Arul Kumar

            • 3. Re: HAServiceMBeanSupport subclasses could not get the HAPar
              brian.stansberry

              Ok, so the HAPartition needs to be injected into your SimpleLmnkCache by whatever code constructs and configures that object. That would be via SimpleLmnkCache.setHAPartition(HAPartition partition).

              How the code that calls that setter gets the HAPartition ref is up to you. Best way is to dependency inject it; e.g. into an mbean service in a -service.xml:

              <attribute name="HAPartition"><inject bean="HAPartition"/></attribute>


              or into a pojo service in a -jboss-beans.xml:

              <property name="HAPartition"><inject bean="HAPartition"/></property>


              Less recommended is to use a service locator the AS provides (org.jboss.ha.framework.server.HAPartitionLocator):

              HAPartitionLocator locator = HAPartitionLocator.getHAPartitionLocator();
              HAPartition partition = locator.getHAPartition(partitionName, null);


              Less recommended because this doesn't establish a dependency between your service and the HAPartition, so it's possible your service could start first.

              How you get the value for "partitionName" is up to you: dependency inject it or use System.getProperty("jboss.partition.name", "DefaultPartition")

              TBH, I don't see what could have changed in this area that would cause something that was working in CR2 to not work in GA.

              • 4. Re: HAServiceMBeanSupport subclasses could not get the HAPar

                Thank you so much for your quick response.

                I will try to look back to see how it got worked with JBoss CR2.

                Arul Kumar