Application instance from servlet


I have a web service that needs to get access to my vaadin application instance.

I got it to work by using:

                    WebApplicationContext context = (WebApplicationContext) req.getSession(false).getValue("com.vaadin.terminal.gwt.server.WebApplicationContext");
                    Iterator it = (MyApplication) context.getApplications().iterator();
                    if( it.hasNext()) {
                        MyApplication a = (MyApplication);

I’m guessing there may be a better way. Any help would be greatly appreciated.




I guess there is not easier ways to access your application’s instance from another servlet. Remember that, if you access the application from another thread, any updates will not be reflected before any user interaction has happened in the browser (causing the “Vaadin”-thread to check for updates at the server side). Furthermore, accessing the application from another thread like this may cause syncrhonization problems. Also remember, that for each new servlet session, there will be another application, so assuming that the first application is “the one” application, is not an appropriate check.

Instead of trying to do so, it might be a good idea to use e.g. some message passing system and have the applications register and unregister to receive messages from the other service.

this thread
for ways to make the updates visible (push or pull).

… so you need to synchronize access to the Application instance being updated.

Assuming they are sessions of a Vaadin servlet. It is also possible to do the access via the session in a non-Vaadin servlet.