Having bean using CDI beans (with Myfaces CODI) in place of JSF managed beans for some time I've been going through some tutorials to get a better understanding of what I can really do with this technology. The most obvious potential for exploitation is the CDI event model but I don't have a lot of inspiration for what I can use it for.
I have a page counter mechanism which maintains a persistent record of page accesses without accessing the database on the critical path, i.e. slowing down the page load time. This works by incrementing an AtomicInteger in a ConcurrentHashMap accessed by an AtomicReference, with the data stored in a singleton EJB. Then an EJB timer periodically "grabs" the map, replacing it with a new one, and adds the new hits to the appropriate database record. A PreDestroy listener saves any non-persisted updates on app server shutdown.
I thought that on page load I could just fire a "page access" event with an application scoped CDI bean observing it and doing the back end processing, but this falls short of the existing design in a few ways:
at present the updates are batched up, the timer method runs only every few minutes.
while the existing design will lose data if there's a server power failure this is not desirable but acceptable, but it's reasonably reliable in that it handles graceful shutdowns.
I need a better understanding of what happens to queued CDI events in the event of, say a server shutdown and I will go through the spec to figure this out.
Whilst I'd appreciate any feedback on the above idea what I'm really interested in is being inspired by any interesting scenarios where you use CDI events in a JSF application, anyone care to share their experiences?
Thanks.