0 Replies Latest reply on May 6, 2015 8:38 AM by sridhar thiyagarajan

    How to implement MBean (that depends on singleton stateless local EJB) in Wildfly

    sridhar thiyagarajan Novice

      Hello.. I am  migrating an application from JBoss 6 AS to Wildfly AS 8.2.0. Application employs MBeans and it is used as follows:

       

      All the MBean implementation classes extend ServiceMBeanSupport and containing createService(), destroyService(), startService(), stopService() lifecycle methods.

       

      Type-1. MBean class extending ServiceMBeanSupport and containing createService(), destroyService(), startService(), stopService() lifecycle methods.

       

      Type-2. MBean implementation class depending on singleton stateless local EJB as mentioned below.

       

      @Singleton

      @Local(TestLocal.class)

      @Resource(name="TestLocal", mappedName="java:/ConnectionFactory")

      public class TestLocal {

           ....

           ....

      }

       

      Type-3. MBean class of type Type-1 depending on another MBean class which depends on singleton stateless local EJB.

       

       

      Assume there are three MBean implementation classes - A, B, C.

       

      A is of type Type-1. MBean class A is registered in jboss-service.xml.

       

      B is of type Type-2.

       

      I came across a web link http://codrspace.com/codertrader/making-an-mbean-ejb3-and-wildfly-compliant/ which explains about how to make an MBean EJB3 and Wildfly complaint. I am using this option for an MBean that depends on singleton stateless local EJB.

       

      MBean Class B depends on singleton stateless local EJB (say TestLocal) and I have modified the class B as per the web link as shown below.

       

      @Singleton

      @LocalBean

      @Startup

      @DependsOn({"TestLocal"})

      public class B {

       

          private ObjectName objectName = null;

          ...

          ...   

          @PostConstruct

          public void registerAsMBean() throws Exception {   

              startService();       

              try {

                 objectName = new ObjectName("test.classB:service=TestClassB" );

                 MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

                 mBeanServer.registerMBean( this, objectName );

              } catch ( Exception e ) {

                 throw new IllegalStateException( "Problem occurred while registering test.classB:service=TestClassB into JMX:" + e );

              }

          }

         

          @PreDestroy

          public void unRegisterAsMBean() throws Exception {   

              stopService();

              try {

                     ManagementFactory.getPlatformMBeanServer().unregisterMBean( this.objectName );

                     } catch ( Exception e ) {

                     throw new IllegalStateException( "Problem occurred while un-registering test.classB:service=TestClassB from JMX:" + e );

                     }

          }

       

          public void createService() throws Exception {

              ...

          }

         

          public void destroyService() throws Exception {

              ...

          }

         

          public void startService() throws Exception {

              ...

          }

       

          public void stopService() throws Exception {

              ...

          }   

      }

       

      Please note that I have defined public methods - createService(), startService(), destroyService(), stopService() in the above class B which is registered as MBean and found that they are exposed in the registered MBean in JMX console but they are not MBean life cycle methods.

       

      My first question is - Is the above MBean implementation (class B) right ?

       

      C is of type Type-3. So, how this MBean should be implemented ? Like the type Type-1 and registering it in jboss-service.xml with <depends>test.classB:service=TestClassB</depends>

      (I tried it seems it is not working. Any valuable comments are welcomed.)

       

                                                                            OR

       

      Should MBean C be implemented as class B and if yes, then how to make MBean C depend on MBean B ?

       

      Please let me know if I am not clear in explaining the problem. Please help me. Many thanks.