[jboss-user] [JBoss Seam] - @Asynchronous @Observer - Poll & raising

pdepaepe do-not-reply at jboss.com
Wed Jul 4 08:43:28 EDT 2007


Hello,

How raising an Event from an Asynchronous method?
Basically:

newSessionBean.java

  | ...
  |    public String step1()
  |    {
  |         sessionVisu = new SessionVisu(sessionVisu, user);
  |         sessionVisu.setStatus("description");
  |         computeHandler.processGetComputes(sessionVisu);
  |         return "/sessions.xhtml";
  |    }
  | ...
  | 

ComputeHandlerBean.java

   
  | ...
  | @Asynchronous
  | public void processGetComputes(SessionVisu sessionVisu){
  |         try {SECONDS.sleep(30);}
  |         catch(InterruptedException ignore){}
  |         sessionVisu = entityManager.merge(sessionVisu);
  |         sessionVisu.setStatus("compute");
  |         entityManager.persist(sessionVisu);
  |         events.raiseTransactionSuccessEvent("flushComputeSessionVisus");
  |    }
  | ...
  | 

SessionVisuListBean.java

 
  | ...   
  |     @Factory
  |     @Observer("flushComputeSessionVisus")
  |     public void getComputeSessionVisus()
  |     {
  |         computeSessionVisus = entityManager.createQuery("select s from SessionVisu s where s.user.username = :username and s.status = :status")
  |                 .setParameter("username", user.getUsername())
  |                 .setParameter("status", "compute")
  |                 .getResultList();
  |     }
  | ...
  | 

The idea is to have a portlet "polled" by Ajax4jsf.
I used in my componentd.xml

   <framework:entity-query name="sessionVisuCompute">
  |         <framework:ejbql>from SessionVisu s</framework:ejbql>
  |         <framework:restrictions>
  |                 <value>user_id = #{userComp.id}</value>
  |                 <value>status = #{sessComp.status}</value>
  |         </framework:restrictions>
  |    </framework:entity-query>
  | 
  |    <component name="userComp" class="User">
  |         <property name="id">#{user.id}</property>
  |    </component>
  |    <component name="sessComp" class="SessionVisu">
  |         <property name="status">compute</property>
  |    </component>

But i really wish to use the event/observer mechanism.

Any idea?

Thank you

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4060435#4060435

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4060435



More information about the jboss-user mailing list