3 Replies Latest reply on Jan 27, 2006 12:26 PM by adrian.brock

    MDB invoked before dependant entity beans have been fully de

    drdm7321

      I have an MDB that is deployed in the same ear as a couple of entity beans it utilises. Unfortunately, when the MDB's message queue contains messages at deployment time, the MDB's onMessage() method is invoked before the entity beans it uses have been fully deployed (more precisely, before the entity beans' local home interfaces have been bound to their respective names in JNDI).

      Can anyone help me indicate to JBoss that the MDB should not be invoked until all its resources have been fully deployed and configured?

      Thanks,

      Damian Morris

        • 1. Re: MDB invoked before dependant entity beans have been full
          drdm7321

          More info:

          I've added tags for the entity beans my MDB depends on; JBoss now waits until the required local homes have been bound in JNDI before creating instances of my MDB and processing its queue. However, my MDB still fails, and it's still invoked before it's possible to use the dependant local homes' findByPrimaryKey() method to retrieve a bean instance, as I get an NPE in org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createBeanClassInstance():

          2004-03-24 09:14:00,642 ERROR [Thread Pool Worker-0] org.jboss.logging.Logger.error() - TransactionRolledbackLocalException, causedBy:
          java.lang.NullPointerException
           at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createBeanClassInstance(JDBCStoreManager.java:513)
           at org.jboss.ejb.plugins.CMPPersistenceManager.createBeanClassInstance(CMPPersistenceManager.java:165)
           at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createBeanClassInstance(CachedConnectionInterceptor.java:251)
           at org.jboss.ejb.EntityContainer.createBeanClassInstance(EntityContainer.java:294)
           at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:209)
           at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:76)
           at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
           at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
           at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:111)
           at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
           at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
           at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
           at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
           at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
           at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(BaseLocalContainerInvoker.java:230)
           at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
           at $Proxy107.findByPrimaryKey(Unknown Source)
           at com.moso.lis.ejb.message.update.UpdateNotificationMessageDrivenBean.setMessageDrivenContext(UpdateNotificationMessageDrivenBean.java:96)
           at org.jboss.ejb.MessageDrivenEnterpriseContext.<init>(MessageDrivenEnterpriseContext.java:61)
           at org.jboss.ejb.plugins.MessageDrivenInstancePool.create(MessageDrivenInstancePool.java:62)
           at org.jboss.ejb.plugins.AbstractInstancePool.get(AbstractInstancePool.java:209)
           at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:74)
           at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
           at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
           at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
           at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:100)
           at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
           at org.jboss.ejb.MessageDrivenContainer.invoke(MessageDrivenContainer.java:302)
           at org.jboss.ejb.plugins.jms.JMSContainerInvoker.invoke(JMSContainerInvoker.java:962)
           at org.jboss.ejb.plugins.jms.JMSContainerInvoker$MessageListenerImpl.onMessage(JMSContainerInvoker.java:1038)
           at org.jboss.jms.asf.StdServerSession.onMessage(StdServerSession.java:238)
           at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:603)
           at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:417)
           at org.jboss.mq.SpySession.run(SpySession.java:259)
           at org.jboss.jms.asf.StdServerSession.run(StdServerSession.java:177)
           at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:642)
           at java.lang.Thread.run(Thread.java:534)



          This is my MDB's config, in jboss.xml:

          <message-driven>
           <ejb-name>UpdateNotificationEJB</ejb-name>
           <configuration-name>Singleton Message Driven Bean</configuration-name>
           <destination-jndi-name>LISEJBUpdateNotifications</destination-jndi-name>
           <mdb-user>UpdateNotificationEJB</mdb-user>
           <mdb-passwd></mdb-passwd>
           <resource-ref>
           <res-ref-name>jms/QueueConnectionFactory</res-ref-name>
           <jndi-name>ConnectionFactory</jndi-name>
           </resource-ref>
           <resource-ref>
           <res-ref-name>jms/TopicConnectionFactory</res-ref-name>
           <jndi-name>ConnectionFactory</jndi-name>
           </resource-ref>
           <depends>jboss.j2ee:service=EJB,jndiName=local/IDEJB</depends>
           <depends>jboss.j2ee:service=EJB,jndiName=local/UpdateEJB</depends>
          </message-driven>


          I'm currently using JBoss 3.0.2. Again, if the queue is empty at deploy time, any new messages added after deployment of my EAR is complete will be successfully processed.

          Any help would be much appreciated.

          Regards,

          Damian

          • 2. Re: MDB invoked before dependant entity beans have been full
            russ396

            I am running 3.0.7 and have 30 Entity Beans and 8 or so MDBs. What I have done is put a Thread.sleep(5000) in my MDB's before they call a generic ping on the session beans. The ping forces the session beans to start which also starts a bunch of my logic that calls entity beans. If the beans are not ready then I get the same error. Note that you make need a longer sleep time if you have more entity, session and mdbs. Below is the meat of making the MDB wait:

            public void startService() throws Exception {
            new UpdateThread().start();
            setUpReceiver();
            }

            private class UpdateThread extends Thread {
            private final static int sleepTime = 5000;
            public UpdateThread() {
            this.setPriority(Thread.MIN_PRIORITY);
            }
            public void run() {
            try {
            this.sleep(sleepTime);
            } catch (java.lang.InterruptedException e) {
            //e.printStackTrace();
            }
            try {
            touchStateDBSession();
            } catch(Exception e) {
            System.out.println("StateDBCleanService.UpdateThread.run() - Error="+e.getMessage());
            }
            }
            }

            private void touchStateDBSession() {
            InitialContext lContext = null;
            StateDBSessionHome stateDBSessionHome = null;
            StateDBSession stateDBSession = null;
            try {
            lContext = new InitialContext();
            stateDBSessionHome = (StateDBSessionHome) lContext.lookup("ejb/StateDBSession");
            stateDBSession = (StateDBSession)stateDBSessionHome.create();
            stateDBSession.ping();
            } catch(Exception fe) {
            fe.printStackTrace();
            } finally {
            if(stateDBSession!=null) {
            try {
            stateDBSession.remove();
            } catch(Exception e) { }
            stateDBSession = null;
            }
            stateDBSessionHome = null;
            if(lContext!=null) {
            try {
            lContext.close();
            } catch(Exception e) { }
            lContext = null;
            }
            }
            }

            • 3. Re: MDB invoked before dependant entity beans have been full