Taming Beastly Web Applications with Server-Side OSGi

31
Taming Beastly Web Applications with Server-Side OSGi Don Brown, Atlassian

description

Presentation given at OSDC Sydney 2008

Transcript of Taming Beastly Web Applications with Server-Side OSGi

Page 1: Taming Beastly Web Applications with Server-Side OSGi

Taming Beastly Web Applications with Server-Side OSGi

Don Brown, Atlassian

Page 2: Taming Beastly Web Applications with Server-Side OSGi

It starts so simple. . .

Page 3: Taming Beastly Web Applications with Server-Side OSGi

Then this happens. . .

IRC interface

PKI card authentication

Report builder

Microsoft Excel export and import

REST interfaceSOAP interface

50+ third-party libraries and frameworks

Thousands of classes

Slooow deployment

Page 4: Taming Beastly Web Applications with Server-Side OSGi

Solution: Plugins

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Plugin Framework

Page 5: Taming Beastly Web Applications with Server-Side OSGi

Anatomy of a PluginPlugin JAR

Resources (images, css, etc)

Java Classes Utility JARs

XML Descriptor

Page 6: Taming Beastly Web Applications with Server-Side OSGi

ls myplugin.jar

./com/myplugin/HelloWorld.class

./resources/logo.png

./META-INF/lib/util.jar

./plugin.xml

Page 7: Taming Beastly Web Applications with Server-Side OSGi

plugin.xml<plugin key=”my.plugin”> <plugin-info> <version>1.0</version> </plugin-info> <servlet key=”helloWorld” class=“com.myplugin.HelloWorld”> <url-pattern>/helloWorld</url-pattern> </servlet></plugin>

Page 8: Taming Beastly Web Applications with Server-Side OSGi

Not just any plugin framework . . .

. . . Now Open Source (BSD)

Page 9: Taming Beastly Web Applications with Server-Side OSGi

Right, but what does this have to do with OSGi?

Page 10: Taming Beastly Web Applications with Server-Side OSGi

What if your plugins need plugins?

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Plugin Framework

Page 11: Taming Beastly Web Applications with Server-Side OSGi

Want: inter-plugin communication

Users Reports Plugin

Report Plugin

Built-in Reports

Report Services

Report UI

Sales Reports Plugin

Usage Reports Plugin

Page 12: Taming Beastly Web Applications with Server-Side OSGi

Want: dynamic deployment

WEB-INF/lib

plugins

Page 13: Taming Beastly Web Applications with Server-Side OSGi

Want: application and plugin isolation

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Internal Services

External Services

Internal Resources

Page 14: Taming Beastly Web Applications with Server-Side OSGi

Want: application and plugin isolation

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Internal Services

External Services

Internal Resources

Page 15: Taming Beastly Web Applications with Server-Side OSGi

OSGi Basics

Dynamic module system for Java

Features:

• Service registry

• Lifecycle model

• Bundle dependency system

• Optional security layer

Page 16: Taming Beastly Web Applications with Server-Side OSGi

OSGi TermsBundle - Jar file with special OSGi entries in its

manifest and containing classes, resources, and other jars

Lifecycle - States a bundle goes through: uninstalled, installed, resolved, starting, stopping, active

Service - An object instance exposed under the one or more interfaces it implements and a map of properties

Page 17: Taming Beastly Web Applications with Server-Side OSGi

Bundle Manifest

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.Example

Bundle-Version: 1.0

Import-Package: org.bar;version="1.3.0”

Export-Package: org.foo.api

Bundle-ClassPath: .,META-INF/lib/foo.jar

Page 18: Taming Beastly Web Applications with Server-Side OSGi

Bundle Lifecycle

Page 19: Taming Beastly Web Applications with Server-Side OSGi

OSGi Services

Key: “com.foo.MyInterface”

Instance: com.foo.MyService

Properties:

name => foo

someProperty => someValue

Page 20: Taming Beastly Web Applications with Server-Side OSGi

What does that mean?

• Upgrade bundles (think super jars) at runtime

• Bundles can depend on other bundles at a service, package, or jar level

• Bundles can hide packages from other bundles and version exposed packages

Page 21: Taming Beastly Web Applications with Server-Side OSGi

So how does OSGi help us?

Page 22: Taming Beastly Web Applications with Server-Side OSGi
Page 23: Taming Beastly Web Applications with Server-Side OSGi

1. Ability for plugins to depend on each other

Plugins can generate their own OSGi headers or:

<plugin-info>

<bundle-instructions>

<Require-Bundle> org.otherPlugin;bundle-version="[3.2.0,4.0.0)</Require-Bundle>

<Import-Package> *,org.otherPlugin.api;version=”[3.2.0,4.0.0)” </Import-Package>

</bundle-instructions>

</plugin-info>

Page 24: Taming Beastly Web Applications with Server-Side OSGi

2. Ability for plugins to define extension points

1. Plugin A exposes its implementation:

<component key=“foo” public=“true” class=“org.bar.FooImpl” interface=“org.foo.Foo” />

2. Plugin B imports the service:

<component-import key=“foo” interface=“foo.Foo” />

Page 25: Taming Beastly Web Applications with Server-Side OSGi

3. Better insulate plugins from product changes

• Host applications can decide which versioned packages to expose to pluginsscanner.addPackageIncludes(Arrays.asList(“com.atlassian.*”, “org.apache.commons.*”));

• Host applications expose specific host components:<bean name="foo" class="com.atlassian. FooableBean" plugin:available="true" />

Or

@AvailableToPluginspublic class MyManager implements Manager {...}

Page 26: Taming Beastly Web Applications with Server-Side OSGi

Plugins 2

Page 27: Taming Beastly Web Applications with Server-Side OSGi

Why should you care?

Page 28: Taming Beastly Web Applications with Server-Side OSGi

Built for integration

Shipped today with Atlassian applications with different:

• Dependency injection libraries

• Web frameworks

• Persistence frameworks

Page 29: Taming Beastly Web Applications with Server-Side OSGi

On to the code . . .

Page 30: Taming Beastly Web Applications with Server-Side OSGi

Takeaway: Use plugins and OSGi to tame your

beastly apps