Hi all, I am currently working on an application in which a user periodically makes a request to the server to check a flag indicating whether an external event has occurrred. I would like to (when the event does occur) to grab the user's HttpSession and set a flag, so the servlet can simply check for the value there. The deprecated HttpSessionContext Interface was good for this, as I could get a list of session id's and get a reference to the actual session I wanted. Now that is no more. Has anyone been successful in solving a similar problem? The SessionBindinglistener interface does not seem to give me what I need, as I need to get the session reference when an external event takes place. Any thoughts appreciated.
You might try solving this the other way around. Use an application-scoped FooBar object that represents whatever needs to be watched. This object would be the observable in the Observer pattern, and java.util.Observable might be a suitable class to use. Each client that needs to be alerted gets a session-scoped FooBarBean (implements Observer) that registers as an observer with FooBar (Observable.addObserver()). When FooBar updates, it notifies the observers and each observer gets its chance to sniff out what's changed and set whatever flags are necessary. If it's events rather than updates you're watching for, use java.util.EventListener and java.util.EventObject. The javax.swing.event.EventListenerList support class can be helpful here (G-d only knows why this class is not part of java.util, there's nothing Swing-specific about it). Same idea. - Peter