2 Replies Latest reply on Jul 16, 2007 5:10 PM by Roberto Melo Cavalcante

    Asynchronous Problem

    Laurent Mallet Newbie

      Hello,

      I need an asynchronous process in my web application. So i use the @Asynchronous annotation
      to do the job but i need a mean to inform my Stateful EJB that the job is done.

      1. First, i use the @Observer and RaiseEvent.... Without sucess because of Asynchronous annotation

      2. Second, i use jms to send a message when the job is done but my MDB is stateless so no acess to
      my EJB stateful.

      3. Third, same technique but i send in the message My EJB Stateful (Sorry), but it crashed due to
      some transactions problems.

      So, is there a solution ? Use business context to save "job done" and use it in my EJB stateful
      to see that there is an event?

      Thanks for your help.



      Problem in the third scenario :

      11:59:30,749 ERROR [JmsServerSession] Unexpected error delivering message org.jboss.mq.SpyObjectMessage {
      Header {
      jmsDestination : TOPIC.refreshTopic
      jmsDeliveryMode : 2
      jmsExpiration : 0
      jmsPriority : 4
      jmsMessageID : ID:6-11838023706871
      jmsTimeStamp : 1183802370687
      jmsCorrelationID: null
      jmsReplyTo : null
      jmsType : null
      jmsRedelivered : false
      jmsProperties : {}
      jmsPropReadWrite: false
      msgReadOnly : true
      producerClientId: ID:6
      }
      }
      java.lang.ClassCastException: cannot assign instance of org.jboss.seam.intercept.ClientSideInterceptor to field org.jboss.seam.oxalya.carriocas.RefreshEvent.sessionVisuList of type org.jboss.seam.oxalya.carriocas.SessionVisuList in instance of org.jboss.seam.oxalya.carriocas.RefreshEvent
      at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2004)
      at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1184)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1914)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
      at org.jboss.mq.SpyObjectMessage.getObject(SpyObjectMessage.java:147)
      at org.jboss.seam.oxalya.carriocas.RefreshList.onMessage(RefreshList.java:33)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
      at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
      at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
      at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:116)
      at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
      at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:112)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
      at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
      at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
      at $Proxy202.onMessage(Unknown Source)
      at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:178)
      at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:891)
      at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
      at org.jboss.mq.SpySession.run(SpySession.java:323)
      at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:237)
      at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
      at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
      at java.lang.Thread.run(Thread.java:613)



        • 1. Re: Asynchronous Problem
          Gavin King Master

          1. use raiseAsynchronousEvent() instead of @Asynchronous in this case

          2. whynot? A Seam MDB can inject a stateful component. perhaps your problem is that you get the wrong instance, in which case you need to consider using a @Synchronized session scoped component

          3. No idea, never seen it

          • 2. Re: Asynchronous Problem
            Roberto Melo Cavalcante Newbie

            Hi,

            I'm using threads inside a stateless bean and I cannot persist anything without having that annoying message that states I can only use transaction manager inside a transactional context.
            I've tried to make a busy-wait on my stateless bean so I can assure my bean will be alive until the very moment my thread needs the entityManager but when the execution reaches the entityManeger.merge( object ) an exception is risen.
            The story:

            I have a jboss-4.0.5.GA with an upgrade on my original Javassist. Now I have javassist-3.4 due to issues with threads.
            My application needs to perform a fork in execution flow split in three parts. Both of them are created as threads and are observed in normal-fashion-way observer pattern, where the Stateless Bean is the observer.
            I have a hunch that my bean life-cycle ends before my first thread finishes, so the entityManager looses it transactional context.
            Can anybody point a blueprint for creating a structure to support such a business demand?

            Here some parts of my code so you can place yourself. This code comes with only one thread. The original one has three, all like this one.

            @TransactionManagement(TransactionManagementType.CONTAINER)
            public @Stateless(name = "TempoRealRN") class TempoRealRNBean extends IntegratorCommonBehavior implements TempoRealRN, Observer {

            @EJB(beanName = "GenericoDAO")
            GenericoDAO genericoDAO;

            @PersistenceContext private EntityManager entityManager;

            private static final Log log = LogFactory.getLog(TempoRealRNBean.class);

            ...
            public void processar(CommonController controladorComum) throws IntegratorException {

            super.setEntityManager(this.entityManager);

            tCorFrente = new ThreadCorFrente(controladorComum, this, log, dto, nomeThreadFrente, grupoFrente);
            tCorFrente.addObserver(this);
            tCorFrente.start();
            }// ends of: public void processar(...) ....

            /*
            * receives notification from thread state change and executes the proper action to acomplish bussiness rule goals.
            *
            */
            public void update(Object o) {

            //perform some state tests

            //then try to persist.
            //at this point an exception is risen
            this.entityManager.merge( object );
            }



            }//ends public void update(Object o)

            }//ends class

            The exception risen is:
            --------------------------
            17:01:47,480 ERROR [STDERR] Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
            17:01:47,480 ERROR [STDERR] at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:150)
            17:01:47,480 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:180)
            17:01:47,480 ERROR [STDERR] at wm.integrator.negocio.temporeal.impl.TempoRealRNBean.persistirFrente(TempoRealRNBean.java:485)

            It would be great if some good soul could enlight me regarding on how to use the proper pattern for observing threads and how I can make this persistence work.
            Thank you all just for being patient enough to read this extensive post.
            I apologize myself for any English grammar misuse or misspell as English is not my 1st language. I'm from Brazil.