OSGi and Java Modularity

127
OSGi & Java Modularity Jazoon 2009, Zürich by Peter Kriens donderdag 25 juni 2009

description

A presentation about OSGi and Java modularity given on DevCon 2009. It lays out what is wrong with Java with respect to modularity and how OSGi fixes these flaws.

Transcript of OSGi and Java Modularity

Page 1: OSGi and Java Modularity

OSGi &Java Modularity

Jazoon 2009, Zürich

by Peter Kriens

donderdag 25 juni 2009

Page 2: OSGi and Java Modularity

donderdag 25 juni 2009

Page 3: OSGi and Java Modularity

donderdag 25 juni 2009

Page 4: OSGi and Java Modularity

donderdag 25 juni 2009

Page 5: OSGi and Java Modularity

Prod

uctiv

ity

Application Complexity

donderdag 25 juni 2009

Page 6: OSGi and Java Modularity

Prod

uctiv

ity

Application Complexity

Assembly

donderdag 25 juni 2009

Page 7: OSGi and Java Modularity

Prod

uctiv

ity

Application Complexity

Assembly

Structured Programming

donderdag 25 juni 2009

Page 8: OSGi and Java Modularity

Prod

uctiv

ity

Application Complexity

Assembly

Structured Programming

Object Oriented Programming

donderdag 25 juni 2009

Page 9: OSGi and Java Modularity

Prod

uctiv

ity

Application Complexity

Assembly

Structured Programming

Object Oriented Programming

Service Oriented Programming?

donderdag 25 juni 2009

Page 10: OSGi and Java Modularity

donderdag 25 juni 2009

Page 11: OSGi and Java Modularity

Application

donderdag 25 juni 2009

Page 12: OSGi and Java Modularity

Application

Extensions

Application

Foundation

Java VM

Basic

Convenience

Something

Core

donderdag 25 juni 2009

Page 13: OSGi and Java Modularity

Application

Extensions

Application

Foundation

Java VM

Basic

Convenience

Something

CoreJava VM

log4j barcode4j axis batik commons

derbyfopezmorphfreemarkerhttpunit

jakarta jcl json jdbm jdom

jenks jpos18 jython looks lucene

mail mx4j naming jetty poi

resolver rome serializer servlets tomcat

velocity

ws-commons

xalan

wsdl4j

xerces

xmlgraphics

xmlrpc

xmlapis

..

geronimo

bsh

bsf

guiapp hhfacility manufact. marketing minerva

accounting assetmaint

base

bi

catalinacommon

oagis order

ebaycontent

datafile

ecommerce

entity

googlebase

Application layer

widget

minilang party pos. product workeffort workflow …

sunjce_prov.pluginjssejcert dnsns ..

Libs

donderdag 25 juni 2009

Page 14: OSGi and Java Modularity

Application

Extensions

Application

Foundation

Java VM

Basic

Convenience

Something

CoreJava VM

log4j barcode4j axis batik commons

derbyfopezmorphfreemarkerhttpunit

jakarta jcl json jdbm jdom

jenks jpos18 jython looks lucene

mail mx4j naming jetty poi

resolver rome serializer servlets tomcat

velocity

ws-commons

xalan

wsdl4j

xerces

xmlgraphics

xmlrpc

xmlapis

..

geronimo

bsh

bsf

guiapp hhfacility manufact. marketing minerva

accounting assetmaint

base

bi

catalinacommon

oagis order

ebaycontent

datafile

ecommerce

entity

googlebase

Application layer

widget

minilang party pos. product workeffort workflow …

sunjce_prov.pluginjssejcert dnsns ..

Libs

donderdag 25 juni 2009

Page 15: OSGi and Java Modularity

by Damoiselle de Pique

donderdag 25 juni 2009

Page 16: OSGi and Java Modularity

by Damoiselle de Pique

Was Pollock an Early OOProgrammer?

donderdag 25 juni 2009

Page 17: OSGi and Java Modularity

donderdag 25 juni 2009

Page 18: OSGi and Java Modularity

modularity

donderdag 25 juni 2009

Page 19: OSGi and Java Modularity

donderdag 25 juni 2009

Page 20: OSGi and Java Modularity

donderdag 25 juni 2009

Page 21: OSGi and Java Modularity

donderdag 25 juni 2009

Page 22: OSGi and Java Modularity

donderdag 25 juni 2009

Page 23: OSGi and Java Modularity

donderdag 25 juni 2009

Page 24: OSGi and Java Modularity

low coupling,

donderdag 25 juni 2009

Page 25: OSGi and Java Modularity

low coupling,high cohesion &

donderdag 25 juni 2009

Page 26: OSGi and Java Modularity

low coupling,

encapsulationhigh cohesion &

donderdag 25 juni 2009

Page 27: OSGi and Java Modularity

donderdag 25 juni 2009

Page 28: OSGi and Java Modularity

How Do WeHandle ThisComplexity

in Java?

donderdag 25 juni 2009

Page 29: OSGi and Java Modularity

donderdag 25 juni 2009

Page 30: OSGi and Java Modularity

Visibilityvs

Accessibility

donderdag 25 juni 2009

Page 31: OSGi and Java Modularity

Visibility

ClassS

ClassT

ClassT

donderdag 25 juni 2009

Page 32: OSGi and Java Modularity

Visibility

ClassS

ClassT

ClassT

donderdag 25 juni 2009

Page 33: OSGi and Java Modularity

Visibility

ClassS

ClassT

donderdag 25 juni 2009

Page 34: OSGi and Java Modularity

Visibility

ClassS

ClassT

donderdag 25 juni 2009

Page 35: OSGi and Java Modularity

Visibility

ClassS

ClassT

ModuleSystem

donderdag 25 juni 2009

Page 36: OSGi and Java Modularity

Hierarchical Class Loaders

ext

app app

cust

boot

donderdag 25 juni 2009

Page 37: OSGi and Java Modularity

Hierarchical Class Loaders

ext

app app

custvisibility

boot

donderdag 25 juni 2009

Page 38: OSGi and Java Modularity

Context Class Loaders

ext

boot

app app

cust

X {}

Y {}

donderdag 25 juni 2009

Page 39: OSGi and Java Modularity

Context Class Loaders

ext

boot

app app

cust

X {}

Y {}

Thread -> ContextClassLoader

donderdag 25 juni 2009

Page 40: OSGi and Java Modularity

Context Class Loaders

ext

boot

app app

cust

X {}

Y {}

Thread -> ContextClassLoader

donderdag 25 juni 2009

Page 41: OSGi and Java Modularity

Accessibility

public

package

module

private

donderdag 25 juni 2009

Page 42: OSGi and Java Modularity

module

package

class

Accessibility

ClassS

ClassT

ClassW

Class U

ClassV

donderdag 25 juni 2009

Page 43: OSGi and Java Modularity

Java VM

log4j

barcode4j

axis

batik

commons

derby

fop

ezmorph

freemarker

httpunit

jakarta

jcl

json

jdbm

jdom

jenks

jpos18

jython

looks

lucene

mail

mx4j

naming

jetty

poi

resolver

rome

serializer

servlets

tomcat

velocity

ws-commons

xalan

wsdl4j

xerces

xmlgraphics

xmlrpc

xmlapis

..

geronimo

bsh

bsf

guiapp

hhfacility

manufact.

marketing

minerva

accounting

assetmaint

base

bi

catalina

common

oagis

order

ebay

content

datafile

ecommerce

entity

googlebase

ofbiz

widget

minilang

party

pos.

product

workeffort

workflow

sunjce_prov.

plugin

jsse

jce

rt

dnsns

..

BeginHere

donderdag 25 juni 2009

Page 44: OSGi and Java Modularity

Java VM

log4j

barcode4j

axis

batik

commons

derby

fop

ezmorph

freemarker

httpunit

jakarta

jcl

json

jdbm

jdom

jenks

jpos18

jython

looks

lucene

mail

mx4j

naming

jetty

poi

resolver

rome

serializer

servlets

tomcat

velocity

ws-commons

xalan

wsdl4j

xerces

xmlgraphics

xmlrpc

xmlapis

..

geronimo

bsh

bsf

guiapp

hhfacility

manufact.

marketing

minerva

accounting

assetmaint

base

bi

catalina

common

oagis

order

ebay

content

datafile

ecommerce

entity

googlebase

ofbiz

widget

minilang

party

pos.

product

workeffort

workflow

sunjce_prov.

plugin

jsse

jce

rt

dnsns

..

ClassNot

FoundException

BeginHere

donderdag 25 juni 2009

Page 45: OSGi and Java Modularity

import exportprivate

A

B

C

JARs

2

Split Packages

donderdag 25 juni 2009

Page 46: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

import exportprivate

A

B

C

JARs

package com.foo: X, Y, Z

2

Split Packages

donderdag 25 juni 2009

Page 47: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

import exportprivate

A

B

C

JARs

package com.foo: X, Y, Z

2

Split Packages

donderdag 25 juni 2009

Page 48: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

import exportprivate

A

B

C

JARs

package com.foo: X, Y, Z

2

Split Packages

donderdag 25 juni 2009

Page 49: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2package com.foo: X, Z

import exportprivate

A

B

C

JARs

Versioning

donderdag 25 juni 2009

Page 50: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2

package com.bar: A,B,C;2.0

package com.bar: A,B,C;1.0

package com.bar: A;2.0

package com.foo: X, Z

import exportprivate

A

B

C

JARs

Versioning

donderdag 25 juni 2009

Page 51: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2

package com.bar: A,B,C;2.0

package com.bar: A,B,C;1.0

package com.bar: A;2.0

package com.foo: X, Z

import exportprivate

A

B

C

JARs

Versioning

donderdag 25 juni 2009

Page 52: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2

package com.bar: A,B,C;2.0

package com.bar: A,B,C;1.0

package com.bar: A;2.0

package com.foo: X, Z

import exportprivate

A

B

C

JARs

Private Packages

donderdag 25 juni 2009

Page 53: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2

package com.bar: A,B,C;2.0

package com.bar: A,B,C;1.0

package com.bar: A;2.0

package com.foo: X, Z

package com.private: G

package com.private: G,H,I

import exportprivate

A

B

C

JARs

Private Packages

donderdag 25 juni 2009

Page 54: OSGi and Java Modularity

package com.foo: X, Y

package com.foo: X, Y, Z

2

package com.bar: A,B,C;2.0

package com.bar: A,B,C;1.0

package com.bar: A;2.0

package com.foo: X, Z

package com.private: G

package com.private: G,H,I

import exportprivate

A

B

C

JARs

Private Packages

donderdag 25 juni 2009

Page 55: OSGi and Java Modularity

How Do WeHandle ThisComplexity

in Java?

donderdag 25 juni 2009

Page 56: OSGi and Java Modularity

We Don’t ...

donderdag 25 juni 2009

Page 57: OSGi and Java Modularity

donderdag 25 juni 2009

Page 58: OSGi and Java Modularity

donderdag 25 juni 2009

Page 59: OSGi and Java Modularity

OS + Hardware

Execution Environment

Module

Life Cycle

Service

SECURITY

Applications(bundles)

donderdag 25 juni 2009

Page 60: OSGi and Java Modularity

Execution Environment

donderdag 25 juni 2009

Page 61: OSGi and Java Modularity

donderdag 25 juni 2009

Page 62: OSGi and Java Modularity

CLDC/MIDP

J2SE 1.3, 1.4,

5, 6, ...CDC/FP

OSGiMin.

donderdag 25 juni 2009

Page 63: OSGi and Java Modularity

Kim Scarborough

donderdag 25 juni 2009

Page 64: OSGi and Java Modularity

Module Layer

donderdag 25 juni 2009

Page 65: OSGi and Java Modularity

Import, Export, Private

Bundle A

Bundle B

.

p

r

q-[1.2,1.8)

p

q-1.4

import export

r

private

Bundle A

donderdag 25 juni 2009

Page 66: OSGi and Java Modularity

Import, Export, Private

Bundle A

Bundle B

.

p

r

q-[1.2,1.8)

p

q-1.4

import

imports

export

r

private

Bundle A

donderdag 25 juni 2009

Page 67: OSGi and Java Modularity

Import, Export, Private

Bundle A

Bundle B

.

p

r

q-[1.2,1.8)

p

q-1.4

import

imports

exports

export

r

private

Bundle A

donderdag 25 juni 2009

Page 68: OSGi and Java Modularity

donderdag 25 juni 2009

Page 69: OSGi and Java Modularity

donderdag 25 juni 2009

Page 70: OSGi and Java Modularity

Uses ConstraintsBundle B

q-[1.2,1.8)

p

q-1.4

Bundle A

Bundle DBundle C

r;2.0r;1.0

r;2.0r;1.0

p

import exportprivate

donderdag 25 juni 2009

Page 71: OSGi and Java Modularity

Uses ConstraintsBundle B

q-[1.2,1.8)

p

q-1.4

imports

Bundle A

Bundle DBundle C

r;2.0r;1.0

r;2.0r;1.0

p

import exportprivate

donderdag 25 juni 2009

Page 72: OSGi and Java Modularity

Uses ConstraintsBundle B

q-[1.2,1.8)

p

q-1.4

imports

exports

Bundle A

Bundle DBundle C

r;2.0r;1.0

r;2.0r;1.0

p

import exportprivate

donderdag 25 juni 2009

Page 73: OSGi and Java Modularity

Uses ConstraintsBundle B

q-[1.2,1.8)

p

q-1.4

imports

exports

Bundle A

Bundle DBundle C

r;2.0r;1.0

r;2.0r;1.0

p

import exportprivate

donderdag 25 juni 2009

Page 74: OSGi and Java Modularity

SystemLoader

ExtensionLoader

Application BLoader

CustomLoader

donderdag 25 juni 2009

Page 75: OSGi and Java Modularity

SystemLoader

ExtensionLoader

Application BLoader

CustomLoader

OSGi

donderdag 25 juni 2009

Page 76: OSGi and Java Modularity

SystemLoader

ExtensionLoader

FrameworkLoader

Application BLoader

CustomLoader

Bundle G

Bundle C

Bundle A

Bundle B

Bundle F

Bundle E

Bundle D

OSGi

donderdag 25 juni 2009

Page 77: OSGi and Java Modularity

donderdag 25 juni 2009

Page 78: OSGi and Java Modularity

Life Cycle Layer

donderdag 25 juni 2009

Page 79: OSGi and Java Modularity

INSTALLED

RESOLVED

UNINSTALLED

ACTIVE

STOPPING

STARTING

donderdag 25 juni 2009

Page 80: OSGi and Java Modularity

BundleX

BundleX-v2

BundleB

MANAGE-MENT

BUNDLE

BundleA

Systembundle

donderdag 25 juni 2009

Page 81: OSGi and Java Modularity

Service Layer

donderdag 25 juni 2009

Page 82: OSGi and Java Modularity

donderdag 25 juni 2009

Page 83: OSGi and Java Modularity

donderdag 25 juni 2009

Page 84: OSGi and Java Modularity

donderdag 25 juni 2009

Page 85: OSGi and Java Modularity

donderdag 25 juni 2009

Page 86: OSGi and Java Modularity

Services

BundleA

BundleB

register get

notify

defined ininterface/class

donderdag 25 juni 2009

Page 87: OSGi and Java Modularity

Services

void foo() {…}

…s.foo()…

interface Foo { void foo();}

donderdag 25 juni 2009

Page 88: OSGi and Java Modularity

donderdag 25 juni 2009

Page 89: OSGi and Java Modularity

donderdag 25 juni 2009

Page 90: OSGi and Java Modularity

donderdag 25 juni 2009

Page 91: OSGi and Java Modularity

donderdag 25 juni 2009

Page 92: OSGi and Java Modularity

donderdag 25 juni 2009

Page 93: OSGi and Java Modularity

Services Solve Class Loader

Problems!donderdag 25 juni 2009

Page 94: OSGi and Java Modularity

donderdag 25 juni 2009

Page 95: OSGi and Java Modularity

Security

donderdag 25 juni 2009

Page 96: OSGi and Java Modularity

donderdag 25 juni 2009

Page 97: OSGi and Java Modularity

Real Code!

donderdag 25 juni 2009

Page 98: OSGi and Java Modularity

donderdag 25 juni 2009

Page 99: OSGi and Java Modularity

package com.acme;import org.osgi.framework.*;public class HelloWorld extends BundleActivator { public void start(BundleContext context) { System.out.println(“Hello World”); } public void stop(BundleContext context) { System.out.println(“Goodbye World”); }}

---------------------------------------------

Manifest: 1.0Bundle-Activator: com.acme.HelloWorldImport-Package: org.osgi.framework;version=1.3

donderdag 25 juni 2009

Page 100: OSGi and Java Modularity

Bundles are active entities in runtime

donderdag 25 juni 2009

Page 101: OSGi and Java Modularity

donderdag 25 juni 2009

Page 102: OSGi and Java Modularity

294

donderdag 25 juni 2009

Page 103: OSGi and Java Modularity

2947

donderdag 25 juni 2009

Page 104: OSGi and Java Modularity

donderdag 25 juni 2009

Page 105: OSGi and Java Modularity

donderdag 25 juni 2009

Page 106: OSGi and Java Modularity

Is JSR 294 aMeta Module System? (Implemented by OSGi™, Jigsaw, Guice, …)

donderdag 25 juni 2009

Page 107: OSGi and Java Modularity

Is JSR 294 aMeta Module System? (Implemented by OSGi™, Jigsaw, Guice, …)

No Java™ Standard for

Modules!donderdag 25 juni 2009

Page 108: OSGi and Java Modularity

donderdag 25 juni 2009

Page 109: OSGi and Java Modularity

donderdag 25 juni 2009

Page 110: OSGi and Java Modularity

donderdag 25 juni 2009

Page 111: OSGi and Java Modularity

Legacy

donderdag 25 juni 2009

Page 112: OSGi and Java Modularity

Class .forName

donderdag 25 juni 2009

Page 113: OSGi and Java Modularity

Class .forName

donderdag 25 juni 2009

Page 114: OSGi and Java Modularity

donderdag 25 juni 2009

Page 115: OSGi and Java Modularity

Bloat?donderdag 25 juni 2009

Page 116: OSGi and Java Modularity

AccidentalComplexity

donderdag 25 juni 2009

Page 117: OSGi and Java Modularity

‘97 ‘98 ‘99 ‘00 ‘01 ‘02 ‘03 ‘04 ‘05 ‘06 ‘07 ‘08 ‘09 ‘10

donderdag 25 juni 2009

Page 118: OSGi and Java Modularity

‘97 ‘98 ‘99 ‘00 ‘01 ‘02 ‘03 ‘04 ‘05 ‘06 ‘07 ‘08 ‘09 ‘10

donderdag 25 juni 2009

Page 119: OSGi and Java Modularity

donderdag 25 juni 2009

Page 120: OSGi and Java Modularity

donderdag 25 juni 2009

Page 121: OSGi and Java Modularity

bundleA-1.2

bundleB-4.1

bundleC-1.0

bc

a

donderdag 25 juni 2009

Page 122: OSGi and Java Modularity

donderdag 25 juni 2009

Page 123: OSGi and Java Modularity

donderdag 25 juni 2009

Page 124: OSGi and Java Modularity

The ComponentFramework

donderdag 25 juni 2009

Page 125: OSGi and Java Modularity

donderdag 25 juni 2009

Page 126: OSGi and Java Modularity

Q&Adonderdag 25 juni 2009

Page 127: OSGi and Java Modularity

Thanks!

donderdag 25 juni 2009