1 2 Previous Next 19 Replies Latest reply on Feb 12, 2004 1:01 AM by stefano_fornari

    EJB startup service? (JBoss 3.2.0)

      I'm trying to put together an MBean to invoke an EJB operation as part of my ear's deployment process (from what I can tell, this is really the only way to accomplish this in JBoss.) In other words, a "startup" service. The MBean's start() method performs a JNDI lookup on the EJB and then calls a method on it. The problem I'm running into is that I can't seem to get the dependency ordering right. I have the MBean defined in jboss-app.xml. Here's what I've tried:

      1) Don't specify any dependencies in my MBean's service xml. When start() runs, I get
      javax.naming.NameNotFoundException: FooLocal not bound

      2) Specify a dependency on "jboss.j2ee:service=EJB,jndiName=FooLocal". When start() runs, the JNDI lookup now succeeds, but the EJB seems to be incompletely deployed. As soon as the EJB tries to invoke a finder, I get
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createBeanClassInstance(JDBCStoreManager.java:555)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createBeanClassInstance(CMPPersistenceManager.java:137)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createBeanClassInstance(CachedConnectionInterceptor.java:251)
      at org.jboss.ejb.EntityContainer.createBeanClassInstance(EntityContainer.java:226)
      ... (rest omitted)

      3) Specify a dependency on "jboss.management.local:J2EEApplication=foo.ear,J2EEServer=Local,j2eeType=EJBModule,name=foo.jar"
      This "feels" like the right solution to me, as I'm specifying a dependency on the entire EJB-jar getting deployed. However, when I do this, my start() method never gets invoked. It never gets a notification that this ObjectName has finished deploying, even tthough it appears in my JMX console.

      Any suggestions? I've scoured the JBoss book, its examples, and the forums. I found Scott's chap2/ex3 example, which follows my approach #2 as described above, but his startService() method doesn't actually invoke any methods on the EJB; let alone anything that touches CMP, so I imagine if I enhanced the example to try that, I would run into a similar problem. Thanks for any help!
      --Tim

        • 1. Re: EJB startup service? (JBoss 3.2.0)

          Post the log of the deployment with and
          without the mbean.

          The MBean's start should be after the EJB's
          start so the EJB should be working.
          Are you sure the EJB doesn't use another EJB
          or some other dependency that might not
          be satisfied yet?

          Regards,
          Adrian

          • 2. Re: EJB startup service? (JBoss 3.2.0)

            Thanks for the reply. In my MBean's service XML, I have the following dependency list:

            <depends-list>
            <depends-list-element>jboss.j2ee:service=EJB,jndiName=FooFacadeLocal</depends-list-element>
            <depends-list-element>jboss.j2ee:service=EJB,jndiName=FooRecordLocal</depends-list-element>
            </depends-list>

            where FooFacadeLocal is a session bean and FooRecordLocal is an entity bean whose home interface the session bean calls findAll() on.

            Here's the relevant section of the deployment log:

            2003-04-25 10:29:48,421 DEBUG [org.jboss.resource.connectionmanager.CachedConnectionInterceptor] start called in CachedConnectionInterceptor
            2003-04-25 10:29:48,421 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:jndiName=FooFacadeLocal,service=EJB dependent components: [ObjectName: com.fusura.services:service=StartupService,type=XMBean
            state: CREATED
            I Depend On: jboss.j2ee:service=EJB,jndiName=FooFacadeLocal
            jboss.j2ee:service=EJB,jndiName=FooRecordLocal

            Depends On Me: ]
            2003-04-25 10:29:48,421 DEBUG [org.jboss.system.ServiceController] starting service com.fusura.services:service=StartupService,type=XMBean
            2003-04-25 10:29:48,726 DEBUG [com.fusura.FooFacadeLocal] entering foo()
            2003-04-25 10:29:49,834 DEBUG [com.fusura.FooFacadeLocal] running findAll()
            java.lang.NullPointerException
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createBeanClassInstance(JDBCStoreManager.java:555)
            at org.jboss.ejb.plugins.CMPPersistenceManager.createBeanClassInstance(CMPPersistenceManager.java:137)
            ...

            So, the MBean is indeed starting after the ServiceController starts the EJBs. However, there appears to be something else in the deployment chain that's not ready yet, causing the findAll invocation to throw the NullPointerException. If I invoke my MBean's start() method from the JMX console later, after the ear has finished deploying, the findAll() runs fine with no NPE.

            • 3. Re: EJB startup service? (JBoss 3.2.0)

              This shows FooFacadeLocal is started,
              what about FooRecordLocal?

              Regards,
              Adrian

              • 4. Re: EJB startup service? (JBoss 3.2.0)

                Yes, that starts up earlier. Here's the relevant log section. Please ignore the timestamps, this is a new log. :)

                2003-04-25 12:38:16,349 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:jndiName=FooRecordLocal,service=EJB dependent components: [ObjectName: com.fusura.services:service=StartupService,type=XMBean
                state: CREATED
                I Depend On: jboss.j2ee:service=EJB,jndiName=FooFacadeLocal
                jboss.j2ee:service=EJB,jndiName=FooRecordLocal

                Depends On Me: ]
                2003-04-25 12:38:16,349 DEBUG [org.jboss.system.ServiceController] starting service com.fusura.services:service=StartupService,type=XMBean
                2003-04-25 12:38:16,349 DEBUG [org.jboss.system.ServiceController] waiting in start com.fusura.services:service=StartupService,type=XMBean on jboss.j2ee:service=EJB,jndiName=FooFacadeLocal

                • 5. Re: EJB startup service? (JBoss 3.2.0)

                  Ok, the good news is, I found a dependency that works. The bad news is, it only works once. :) I noticed one more notification event that gets fired off after the CMP stuff is done initializing. The ObjectName is:

                  jboss.j2ee:service=EjbModule,url=file%3a/usr/local/jboss-3.2.0/server/fusura/tmp/deploy/server/fusura/deploy/fusura.ear/36.fusura.ear-contents/fusura-object.jar

                  So, the bad news is, this name changes on every deploy. :) I guess it's the name of the ear file expanded out onto the file system. Is there any easy way to tell the deployer to use some kind of sane object name for this that I can rely on every time instead of some path in the tmp dir?

                  • 6. Re: EJB startup service? (JBoss 3.2.0)

                    I seem to have a working solution, although it's nowhere near as elegant as I had hoped. I removed the dependency declarations from my service XML. Then in my MBean's start() method, I manually added a notification listener for jboss.ejb:service=EJBDeployer. Finally, I actually perform my startup call to the EJB inside handleNotification(). I would still much prefer to handle this dependency declaratively, as I think the JBoss authors intended, rather than programatically. However, it seems that the fact that the EJBs are sending out notifications that they are started before they're actually ready to use, from a CMP perspective, prevents this. This seems like busted behavior to me. Does anyone have any further thoughts on this? Should I file a bug?

                    • 7. Re: EJB startup service? (JBoss 3.2.0)
                      davidjencks

                      I agree that the url component of an ejb module mbean's ObjectName should refer to the original top level package url rather than something resulting from unpacking it. I'll file a bug so I don't forget about it.

                      I wonder if we should think about a way to supply meaningful names when we deploy stuff to use in these object names: we'd default to the url if no name was supplied.

                      • 8. Re: EJB startup service? (JBoss 3.2.0)

                        Thanks David. What do you guys think about the fact that the individual EJBs send out dependency notifications before the CMP engine is initialized? Should this be filed as a separate bug?

                        • 9. Re: EJB startup service? (JBoss 3.2.0)

                          Thanks David. What do you guys think about the fact that the individual EJBs send out dependency notifications before the CMP engine is initialized? Should this be filed as a separate bug?

                          • 10. Re: EJB startup service? (JBoss 3.2.0)

                            Thanks David. What do you guys think about the fact that the individual EJBs send out dependency notifications before the CMP engine is initialized? Should this be filed as a separate bug?

                            • 11. Re: EJB startup service? (JBoss 3.2.0)

                              Thanks David. What do you guys think about the fact that the individual EJBs send out dependency notifications before the CMP engine is initialized? Should this be filed as a separate bug?

                              • 12. Re: EJB startup service? (JBoss 3.2.0)

                                By the way, these new forums are still damn buggy. :)

                                • 13. Re: EJB startup service? (JBoss 3.2.0)

                                  Can you post an example app that fails.
                                  I don't see why this doesn't work, I suspect
                                  there is another dependency you haven't identified?

                                  Regards,
                                  Adrian

                                  • 14. Re: EJB startup service? (JBoss 3.2.0)

                                    Don't have the time for a full-fledged example app right now, but if you slightly modify chap2/ex3 from the JBoss book to invoke some kind of CMP call like a finder from its startService() method, you should see the problem. I filed bug 729731 on this.

                                    1 2 Previous Next