aspose file tools*
The moose likes JSF and the fly likes Timer Best Practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Timer Best Practice" Watch "Timer Best Practice" New topic
Author

Timer Best Practice

Robe Eleckers
Greenhorn

Joined: Jul 08, 2009
Posts: 9
Hello all,

I have the following situation:

1. Stateful session bean (lets call this the StatusBean) loads data from a datasource and updates a UIComponent showing a textlabel.
2. I want to implement some kind of timer to check every X second / minutes for new data. If there is then I want to update the UIComponent.
3. I would like to have one single stateless (application or session scoped) bean (lets call this DataCheckBean) doing the polling and notify all active sessionbeans.

What I'm trying now is adding a TimerService to the DataCheckBean and on data change it will use JMS to notify the StatusBean. I have some doubts with this setup, would it be better to let every StatusBean do the polling itself, triggered based on javascript, or are there any other solutions?

Is this possible somehow? What's the best practice for this?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15639
    
  15

Um, you DO know that the UIComponent only exists while someone's actually doing an HTTP request/response, don't you? HTTP is not like client/server where the resources and connections exist all the time.


Customer surveys are for companies who didn't pay proper attention to begin with.
Robe Eleckers
Greenhorn

Joined: Jul 08, 2009
Posts: 9
Yes indeed, my bad. (normally not a webprogrammer). Then I have a very simple question perhaps. How to poll the StatusBean every x seconds from the client side? I want to check if the status changed via Ajax, if it did then I want to re-render the component. Can I do this using the f:ajax tag? If so how, I can only se events like mouseout in the f:ajax tag, is there some other way to achieve this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15639
    
  15

I haven't tried the new ajax tag specifically, but RichFaces has a polling control.

Basically, the function breaks down into 3 parts:

1. Sleep
2. Fire AJAX request and do partial page render using the response
3. Loop back to #1.

I don't know offhand if the sleep/loop part can be done on the AJAX component itself or if an external script is required, though.
Robe Eleckers
Greenhorn

Joined: Jul 08, 2009
Posts: 9
Thanks for your help.

We are actually using Trinidad, but I just checked and found Trinidad has a tr:poll tag which seems to be what I need. I will give this a try.
 
 
subject: Timer Best Practice
 
Similar Threads
Why EJBTimer service not supporting in stateful beans
Is javabean thread-safe
Syncronize AJAX requests: Client or Server Sync?
Long-running transactions
Thread Scheduler