OSGi How to create new instance in Vaadin 7

Peter Kriens of OSGi fame has provided an example of using Vaadin with OSGi.

Part of the code shown below creates new instances of a Vaadin application in V6.

Presumably, the ApplicationServlet should extend from VaadinServlet and a UIProvider should be used to create the instances, but how would this be coded in V7?

Regards
Paul Fraser

/**

  • A servlet that acts as the factory for new instances for Vaadin. The
  • servlet extends AbstractApplicationServlet as defined by Vaadin. For each
  • application, it will request a new instance. If this servlet is closed, all
  • created instances will be disposed.
    */
    class ApplicationServlet extends AbstractApplicationServlet {
    private static final long serialVersionUID = 1L;
final ComponentFactory factory;
final Map<ComponentInstance, Application> instances = new HashMap<ComponentInstance, Application>();
final AtomicBoolean open = new AtomicBoolean(true);

ApplicationServlet(ComponentFactory factory) {
  this.factory = factory;
}

@Override
protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
  return Application.class;
}

@SuppressWarnings("unchecked")
@Override
protected Application getNewApplication(HttpServletRequest request) throws ServletException {
  if (open.get()) {
    Hashtable<String, Object> ht = new Hashtable<String, Object>();
    for (Enumeration<String> e = request.getAttributeNames(); e.hasMoreElements();) {
      String key = e.nextElement();
      ht.put(key, request.getAttribute(key));
    }
    ComponentInstance instance = factory.newInstance(ht);
    synchronized (this) {
      Application app = (Application) instance.getInstance();
      instances.put(instance, app);

      return app;
    }
  } else
    throw new IllegalStateException("Application Servlet is closed! " + factory);
}

public void close() {
  if (open.getAndSet(false)) {
    for (Map.Entry<ComponentInstance, Application> instance : instances.entrySet()) {
      instance.getValue().close();
      instance.getKey().dispose();
    }
    instances.clear();
  }
}

}

Hi Paul,

Florian Pirchner is working on the lunifera.org project. A subproject is integrating vaadin 7 on osgi.

https://github.com/florianpirchner?tab=repositories

The lunifera-example repository includes interesting stuff.

Please let me know if you have any success.

Best regards,
Mario

Spot On, Mario,

Thanks very much, just the clues I need.

Regards
Paul

Hi, you can find informations here…


http://lunifera.wordpress.com/vaadin-7-osgi-bridge/

Will be released soon.

Best, Florian

Thanks for doing all the grunt work for Vaadin 7 support in OSGI.

We are about to migrate our Vaadin 6 + OSGI + Jetty application to Vaadin 7. What bug is the link you posted referencing?

We currently build Vaadin from source and it would be easy for us to make the needed modifications to Vaadin in the meantime while we wait for the main build to resolve the issue.

Hi,

well the bug is fixed now.
http://dev.vaadin.com/ticket/11691

Today i could build the P2 repo properly.

But today i got another not vaadin related. atmosphere 1.0.13 and jetty 8.1.10 are not combinable for new. Added details to the bug above.

Best Florian