• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer Best Practice

 
Robe Eleckers
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robe Eleckers
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic