I have a jsf view which shows some data from a managed-bean (viewscope) in a table, that is retrieved remotely.
Currently the data is updated via polling from the client-view using primefaces poll component.
This is not sufficient enough, since to much traffic is sent to client and now that primefaces supports server-push I only want to reload the data and push it to the client-view if data has been changed.
This should be realized via polling from the web-tier to application tier calling a method like hasChanged(...)
. If data is changed the web-tier pushes a notification to client to reload data.
Current client poll
client >> web-tier >> app-tier
client asks web-tier via ajax for data which again asks app-tier for data and updates view
Wished web-tier poll and push
client << web-tier >> app-tier
web-tier polls app-tier if data has changed and reloads on behalf and informs (pushes) client to update view
Approaches:
What is the best approach to realize the polling at the managed-bean in the web-tier?
- TimerTask in the managed-bean
Spawning threads in a JSF managed bean for scheduled tasks using a timer - Additional EJB with Schedule annotation
- Additional EJB with TimerService
- other?
Edit:
Architecture: (3-tier)
- Server1: database
- Server2: app-tier (EAR with Remote EJB + Hibernate)
- Server3: web-tier (WAR with JSF 2.0 + Primefaces 3.4)
- Client: Browser