OSGi: calling all ui "detached" methods when servlet is destroyed

Hello all,

I’l trying to integrate Vaadin 7 with OSGi and HttpService. Works almost fine, but I still have a problem with the clean-up when uninstalling an application from the framework:
I would like to properly close all active sessions when the Vaadin servlet is destroyed, calling the “detached” method of all active UIs.

With Vaadin 6, I just needed to keep track of applications so I could close all active ones at servlet destroy time.

But some major changes in Vaadin 7 make this approach a little more tricky:
When closing a session or a UI in a background thread, the detach operation is postponed until the next request.
Since there is no more request after the servlet have been destroyed, nothing will ever be detached.

My first thought was to call the “detached” method myself on all UIs from all active sessions.
But that means I should ensure all current objects (the ones using the thread-local pattern) are properly set. Seems VaadinServlet, VaadinService and VaadinSession classes have static setters, but I don’t find any for the Page class.
Also, maybe there are some request listeners to call in case there are some custom classes using the thread-local pattern.

So my questions are:

  • Is there a proper way to close everything outside of a client request?
  • If not, is there a way to “fake” a client request, so detach events are sent when closing active sessions?
  • If not, is there a way to set the current Page object?

Thanks.