Dynamic and modular Web Applications with Equinox and Vaadin

29
Dynamic modular Web applications with Equinox and Vaadin Kai Tödter Siemens Corporate Technology

description

This presentation introduces a little demo application that uses OSGi (Equixox) on the server. The demo uses Vaadin as UI technology and shows how you can create dynamicly changing UIs within a server-side OSGi Web application.

Transcript of Dynamic and modular Web Applications with Equinox and Vaadin

Page 1: Dynamic and modular Web Applications with Equinox and Vaadin

Dynamic modular Web applications

with Equinox and Vaadin

Kai Tödter Siemens Corporate Technology

Page 2: Dynamic and modular Web Applications with Equinox and Vaadin

Who am I?

Software Architect/Engineer at Siemens Corporate Technology

Eclipse RCP expert and OSGi enthusiast

Open Source advocate

Committer at e4 and Platform UI

E-mail: [email protected]

Twitter: twitter.com/kaitoedter

Blog: toedter.com/blog

5/9/2011 2 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

Page 3: Dynamic and modular Web Applications with Equinox and Vaadin

Outline

Demo

Server-side OSGi

Vaadin

Whiteboard Pattern

OSGi Declarative Services (DS)

Code deep dive

Discussion

5/9/2011 3 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

Page 4: Dynamic and modular Web Applications with Equinox and Vaadin

Demo

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 4

Page 5: Dynamic and modular Web Applications with Equinox and Vaadin

Download & Blog

You can download the demo projects (6,8 MB, including the target platform) at http://www.toedter.com/download/vaadin/osgi-vaadin-demo.zip

See also my blog “Dynamic modular Web Applications with Vaadin and OSGi” http://www.toedter.com/blog/?p=412

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 5

Page 6: Dynamic and modular Web Applications with Equinox and Vaadin

Server-side OSGi

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 6

Picture from http://www.sxc.hu/photo/1043923

Page 7: Dynamic and modular Web Applications with Equinox and Vaadin

Server-side OSGi

For this demo I use Equinox as OSGi container

To run server-side Equinox there’s 2 choices:

Embed Equinox in a servlet container

Embed a HTTP server in Equinox

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 7

Page 8: Dynamic and modular Web Applications with Equinox and Vaadin

Embed Equinox in a Servlet Container

Needed bundles:

org.eclipse.equinox.servletbridge

org.eclipse.equinox.servletbridge.http

org.eclipse.equinox.http.servlet

[optional] org.eclipse.equinox.http.registry

See http://www.eclipse.org/equinox/server/ http_in_container.php

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 8

Page 9: Dynamic and modular Web Applications with Equinox and Vaadin

Embed Jetty in Equinox

Needed bundles:

org.eclipse.equinox.http.jetty

org.eclipse.equinox.http.servlet

org.mortbay.jetty

org.apache.commons.logging

javax.servlet

[optional] org.eclipse.equinox.http.registry

See http://www.eclipse.org/equinox/server/ http_in_equinox.php

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 9

Page 10: Dynamic and modular Web Applications with Equinox and Vaadin

Hello, JAX! OSGi Servlet Demo

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 10

Picture by Office Online, iStockPhoto http://office.microsoft.com/en-us/images/results.aspx?qu=world#ai:MP900444203|

Page 11: Dynamic and modular Web Applications with Equinox and Vaadin

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 11

Page 12: Dynamic and modular Web Applications with Equinox and Vaadin

What is Vaadin?

Server-based RIA Framework

Uses Google Web Toolkit (GWT) as rendering engine

Pure Java, no JavaScript, no configuration

Rich widget set

Out of the box OSGi support

Only one JAR file, already an OSGi bundle

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 12

Page 13: Dynamic and modular Web Applications with Equinox and Vaadin

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 13

Demo

Page 14: Dynamic and modular Web Applications with Equinox and Vaadin

The Whiteboard Pattern

Problem: Often a service provides an implementation of the publisher/subscriber design pattern and provides methods to register listeners for notifications

The OSGi service model provides a service registry with these notification mechanisms already!

So: Don’t get a service and register as listener

Be a service yourself and register with the OSGi service registry!

14

Page 15: Dynamic and modular Web Applications with Equinox and Vaadin

Example: The Listener Pattern

Clients use ApplicationService to register view and action contributions

Client is responsible for handling dynamic behavior

15

Page 16: Dynamic and modular Web Applications with Equinox and Vaadin

Example: The Whiteboard Pattern

Clients register view and action contributions as services

Application manager is responsible for handling dynamic behavior

16

Page 17: Dynamic and modular Web Applications with Equinox and Vaadin

The Action and View contribution managers are NOT services

Instead, they are wrapped in a OSGi Declarative Services (DS) component

All action and view contributions are OSGi services and implement

IActionContribution

IViewContribution

Whiteboard Pattern in Vaadin Demo

17

Page 18: Dynamic and modular Web Applications with Equinox and Vaadin

OSGi Declarative Services

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 18

Component Instance

Component Description

Active Bundle

Component

Component Instance

Component Description

Active Bundle

Component Service

reference

provide

Page 19: Dynamic and modular Web Applications with Equinox and Vaadin

Life Cycle

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 19

Component

DS-powered Bundle

Component Component

Service Component Runtime (SCR)

create

Page 20: Dynamic and modular Web Applications with Equinox and Vaadin

Declaring a Component

Specify component description(s) via Service-Component manifest header

Specify the implementation class

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 20

Service-Component: OSGI-INF/treeView.xml

<component xmlns="http://www.osgi.org/xmlns/scr/v1.1.0">

<implementation class="...TreeView"/>

</component>

Page 21: Dynamic and modular Web Applications with Equinox and Vaadin

Providing a Service

Specify each service interface

By default components providing a service are created on demand (lazy)

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 21

<service>

<provide interface="...IViewContribution"/>

<provide interface="...IActionContribution"/>

</service>

Page 22: Dynamic and modular Web Applications with Equinox and Vaadin

Referencing Services

Specify the service interface

Specify bind and unbind methods

Specify the cardinality

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 22

<reference interface="...IPersonManager"

bind="setPersonManager"

unbind="removePersonManager"

cardinality="1..1"/>

Page 23: Dynamic and modular Web Applications with Equinox and Vaadin

Further Reading

Chris Brind: In Bed with Vaadin and OSGi http://www.perplentropy.com/2010/02/in-bed-with-

vaadin-and-osgi.html I use Chris’ bundles in this demo

Neil Bartlett: Vaadin OSGi bridge at GitHub https://github.com/njbartlett/VaadinOSGi

Petter Holmström: Creating a Modular Vaadin Application with OSGi http://vaadin.com/wiki/-

/wiki/Main/Creating%20a%20Modular%20Vaadin%20Application%20with%20OSGi

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 23

Page 24: Dynamic and modular Web Applications with Equinox and Vaadin

Putting it all together…

Main demo application is a DS component

factory='vaadin.app' => used Chris Brind’s implementation

0..n service references to

IViewContribution

IActionContribution

Source code will be shown soon…

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 24

Page 25: Dynamic and modular Web Applications with Equinox and Vaadin

Resources, Images and Themes

Resources (e.g. images) have to be put in a fragment with the com.vaadin bundle as host

See project com.siemens.ct.osgi.vaadin.pm.theme

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 25

Page 26: Dynamic and modular Web Applications with Equinox and Vaadin

Code Deep Dive

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 26

Picture from http://www.sxc.hu/photo/1159613

Page 27: Dynamic and modular Web Applications with Equinox and Vaadin

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 27

Picture from http://www.sxc.hu/photo/922004

Page 28: Dynamic and modular Web Applications with Equinox and Vaadin

License

This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License

See http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en_US

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 28

Page 29: Dynamic and modular Web Applications with Equinox and Vaadin

Picture Index

Slide „Server-side OSGi“: http://www.sxc.hu/photo/1043923

Slide „Hello JAX!“: http://office.microsoft.com/en-us/images/results.aspx?qu=world#ai:MP900444203|

Slide „Reindeer“ Animation: http://www.sxc.hu/photo/1138596

Slide „Code Browsing“: http://www.sxc.hu/photo/1159613

Slide “Discussion”: http://www.sxc.hu/photo/922004

5/9/2011 © Kai Tödter and others, Licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 29

Many thanks to the authors of the following pictures: