Building Server Platform with OSGi and...

33
Building Server Platform with OSGi and Equinox Rob Harrop Principal Software Engineer SpringSource [email protected]

Transcript of Building Server Platform with OSGi and...

Page 1: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Building Server Platform with OSGi and Equinox

Rob HarropPrincipal Software [email protected]

Page 2: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Who am I?

Lead Engineer of SpringSource dm Server

Author of Pro Spring

JMX Expert Group member

Page 3: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Agenda

Benefits of OSGi

System Partitioning

Managing Dependencies

Extending Equinox

Handling Concurrency

Q&A

Page 4: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Benefits of OSGi

Page 5: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

System Partitioning

Manage complexity

Handle large teams

Mitigate risk

Deal with change

Deal with large codebase

Page 6: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Dependency Management

Handle third-party dependencies

Embody dependencies in design and code

Manage different dependency versions

Page 7: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Dynamism

Support evolving runtime environment

Handle failure gracefully

Hot-deployment built-in

Page 8: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

System Partitioning

Page 9: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Start Simple – Logical Model

Page 10: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Extract Modules as Needed

Page 11: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Reasons for Extraction

Area of risk

Area of change

Area of complexity

Area of work assignment

Unit of maintenance

Code explosion

Page 12: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Fold Modules Together as Needed

Page 13: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Reasons for Folding

Risk removal

Code shrinking

Team changes

Complexity addressed

Incorrect boundaries

Page 14: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

DEMO: Tooling

Page 15: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Managing Dependencies

Page 16: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Package Dependencies

Page 17: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Bundle Dependencies

Page 18: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Versioning Dependencies

Page 19: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Service Dependencies

Page 20: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

EXAMPLE: GreenPages

Page 21: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Build-time vs. run-time dependencies

Artifact-first• Build tooling defines classpath

• Manifest is generated

Manifest-first• Manifest is hand-written

• Classpath is derived from Manifest

Page 22: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

DEMO: Tooling

Page 23: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Extending Equinox

Page 24: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Extension Hook Architecture

Page 25: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Hook Options

AdaptorHook

BundleWatcher

ClassloadingHook

ClassloadingStatsHook

ClassloadingDelegateHook

StorageHook

BundleFileFactoryHook

BundleFileWrapperFactoryHookk

Page 26: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Hooks in dm Server

ClassloadingHook:• Replace ClassLoader

BundleFileWrapperFactoryHook• Manifest transformation

• URL fixup

Page 27: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

DEMO: Hooks

Page 28: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Handling Concurrency

Page 29: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

OSGi Concurrency Basics

Bundle state changes are thread-safe

Service register/unregister/lookup are thread-safe

No ordering guarantees

No managed thread-safety for user code

Page 30: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Interacting with OSGi state changes

Listener infrastructure• FrameworkListener

• BundleListener

• ServiceListener

BundleActivator callback

Page 31: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Concurrent Application Design

Define consistency model• Prefer weak consistency

Use OSGi events to drive your system• Guarantees interaction with all state changes (refresh etc)

Page 32: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

DEMO: Concurrency

Page 33: Building Server Platform with OSGi and Equinoxjavasymposium.techtarget.com/.../RHarrop_osgi_equinox.pdf · 2009-03-12 · Building Server Platform with OSGi and Equinox Rob Harrop

Q&A