0 Replies Latest reply on Aug 2, 2012 10:02 AM by jose.a.g.g

    MBean Service dependencies does not work!!

    jose.a.g.g Newbie

      Hello everyone.

       

      I started to work with JBoss 7.1.1.Final recently (migration from 4.2.1.GA) and maybe it is a simple problem,

      but i can not find the solution.

       

      I'm working in a simple test deployment to check how to start a MBean service after a EJB in JBoss AS 7.1.1.Final,

      and I dont find the way to set the order of loading the different components.

       

      To introduce, I'm going to describe the structure of my ear:

       

      test.ear

      |

      |-- lib

      |    |-- log4j-1.2.16.jar

      |

      |-- META-INF

      |    |-- application.xml

      |    |-- jboss-app.xml

      |    |-- jboss-deployment-structure.xml

      |    |-- MANIFEST.MF

      |

      |-- test-core.jar

      |-- test-ejb.jar

      |-- test-service.jar

      |-- test-sar.sar

            |-- META-INF

                  |-- jboss-service.xml

                 

      NOTE: All the jars and the sar contains an empty file beans.xml inside the META-INF directory.

       

      test-core.jar contains the necessary code to manage the JBoss cluster. There is a principal class (ClusterManager) that injects:

      @Resource(lookup = "java:jboss/infinispan/container/cluster"). This class is annotated with @javax.annotation.ManagedBean and @javax.inject.Singleton.

       

      test-ejb.jar contains a simple class that represents a EJB with the next code:

       

      @javax.ejb.Startup
      @javax.ejb.Singleton
      public class InitializationEJB {
      
          @Inject
          @Default
          ClusterManager clusterManager;
      
          @PostConstruct
          public void init() {
              System.out.println("The ClusterManager has been injected: " + clusterManager.getMasterNodeName());
          }
          
      }
      

       

      test-service.jar contains a simple MBean (and its interface) how this:

       

      @javax.annotation.ManagedBean
      @javax.inject.Singleton
      public class StartInitializationService implements StartInitializationServiceMBean {
      
          @Inject
          @Default
          ClusterManager clusterManager;
          
          public void start() {
      
              String result = null;
              
              if (clusterManager==null) {
                  result = "StartInitializationServiceMBean: The ClusterManager has not been injected.";
              } else {
                  result = "StartInitializationServiceMBean: The ClusterManager has been injected";
              }
              
              result += "\n";
              
              // IMPORTANT: When the EJB initializes the ClusterManagager, it saves a reference internally
              // to get it with the getInstance() method.
              ClusterManager cm = ClusterManager.getInstance();
              if (cm == null) {
                  result += "StartInitializationServiceMBean: ClusterManager does not works with getInstance() method.";
              } else {
                  result += "StartInitializationServiceMBean: ClusterManager works with getInstance method!! MasterNodeName = " + cm.getMasterNodeName();
                  System.out.println(result);
              }
              
              System.out.println(result);
              
              return result;
          
          }
          
          public void stop() {
              
          }
          
      }
      

       

       

      The content of my "application.xml" in the EAR:

       

      <application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   version="6"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
          <display-name>test</display-name>
          <initialize-in-order>true</initialize-in-order>
          <module id="test-core">
              <java>test-core.jar</java>
          </module>
          <module id="test-ejb">
              <ejb>test-ejb.jar</ejb>
          </module>
          <module id="test-service">
              <java>test-service.jar</java>
          </module>
      </application>
      

       

      the content of my "jboss-app.xml" in the EAR:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-app xmlns="http://www.jboss.com/xml/ns/javaee"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-app_7_0.xsd"
                   version="7.0">
        <loader-repository>test.test:loader=test.ear<loader-repository-config>java2ParentDelegation=true</loader-repository-config>
        </loader-repository>
        <module>
          <service>test-sar.sar</service>
        </module>
      </jboss-app>
      

       

      and the content of my "jboss-service.xml" inside the sar:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <server xmlns="urn:jboss:service:7.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
           <mbean code="test.service.StartInitializationService" name="TestServices:service=StartInitializationService">
               <depends>jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB</depends>
           </mbean>
      </server>
      

       

       

      Test 1: Deploy the EJB:

      If I deploy the ear without the sar, then the JBoss starts without errors and the EJB is deployed correctly.

      Using the Java Monitoring and Management Console I can see the object name of the EJB:

      jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB

      and in the console I can see the message that verifies the ClusterManager has been injected.

       

      Test 2: Deploy EJB with SAR

      I add the dependency in the sar to the EJB, and take this error:

       

      JBAS014775:    New missing/unsatisfied dependencies:

            service jboss.mbean.service."jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB".create (missing) dependents: [service jboss.mbean.service.TestServices:service=StartInitializationService.create]

            service jboss.mbean.service."jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB".start (missing) dependents: [service jboss.mbean.service.TestServices:service=StartInitializationService.start]

           

      Test 3: Deploy EJB with SAR but without the depends:

      Removing the <depends> line of the sar, JBoss starts without problems and the MBean StartInitializationService is initialized.

      But the problem is that the MBean starts BEFORE the EJB was fully initialized (in this example does not occur because the load is small and

      starts at the same time, but if the EJB take a bit more time this would happen).

      Then, I can see in the console how the MBean starts before the EJB ends, and the ClusterManager is not yet initialized. Later, appears the message

      of the EJB starting the ClusterManager.

       

      Anyway, in all cases, the Inject in the MBean is null.

      If that inject loaded the ClusterManager, the EJB would no longer needed, but always is null. ¿is not possible to inject in a MBean indicated in the jboss-service.xml?

      I searched through many forums and community, but I find nothing that can fix this.

       

      Any ideas?

       

      Thanks in advance.