I am successfully using ICEPush to push changes to my UI.
Say I have a method called showMessage(…), sometimes it might be called during a user request cycle, and therefor the update will reach the UI without a push, but if it is called by an external thread, push will need to be called.
Is there a way of telling if the current call was instigated from the vaadin UI in order that I can write some code to automatically call push if one is required?
So far I have found that the vaadin threads are in my web server threadpool and I can use this to tell ‘vaadin’ threads from external threads, but this is a platorm-depedant solution. A vaadin-centric approach would be excellent.
I would manage this by implementiung HttpServletRequestListener on your Vaadin Application class; the onRequestStart and onRequestEnd methods will be called for every user initiated HTTP Request received by Vaadin. I’d then set and unset a boolean in a ThreadLocal - that way any thread could then find out whether the current invocation was started by a request from the user.
I like Charles’ solution, but I don’t think you even need to go that far. If the call comes from the user, then it would be through some handler like a button click listener, and so you’re in control of the code that’s calling showMessage().
So you could add a param to showMessage, e.g. ‘boolean push’, and have a button click listener call
showMessage(..., false);
…and change your existing method to bounce the call to:
showMessage(..., true);
The (now private) showMessage method could then push the info if needed. That help?
Cheers,
Bobby
p.s. When I start using ICEPush, I’m glad enough other people are that I can get my questions answered.