Taming Beastly Web Applications with Server-Side OSGi

Post on 19-May-2015

4.957 views 1 download

Tags:

description

Presentation given at OSDC Sydney 2008

Transcript of Taming Beastly Web Applications with Server-Side OSGi

Taming Beastly Web Applications with Server-Side OSGi

Don Brown, Atlassian

It starts so simple. . .

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

Solution: Plugins

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Plugin Framework

Anatomy of a PluginPlugin JAR

Resources (images, css, etc)

Java Classes Utility JARs

XML Descriptor

ls myplugin.jar

./com/myplugin/HelloWorld.class

./resources/logo.png

./META-INF/lib/util.jar

./plugin.xml

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>

Not just any plugin framework . . .

. . . Now Open Source (BSD)

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

What if your plugins need plugins?

Application

REST Plugin

Excel Plugin

IRC Plugin

SOAP Plugin

Report Plugin

PKI Auth Plugin

Plugin Framework

Want: inter-plugin communication

Users Reports Plugin

Report Plugin

Built-in Reports

Report Services

Report UI

Sales Reports Plugin

Usage Reports Plugin

Want: dynamic deployment

WEB-INF/lib

plugins

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

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

OSGi Basics

Dynamic module system for Java

Features:

• Service registry

• Lifecycle model

• Bundle dependency system

• Optional security layer

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

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

Bundle Lifecycle

OSGi Services

Key: “com.foo.MyInterface”

Instance: com.foo.MyService

Properties:

name => foo

someProperty => someValue

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

So how does OSGi help us?

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>

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” />

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 {...}

Plugins 2

Why should you care?

Built for integration

Shipped today with Atlassian applications with different:

• Dependency injection libraries

• Web frameworks

• Persistence frameworks

On to the code . . .

Takeaway: Use plugins and OSGi to tame your

beastly apps