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