services first migration to osgi - osgi users forum uk 16-nov2011

Post on 28-Nov-2014

1.750 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation by Peter Kriens at OSGi Users' Forum UK meeting on Nov 16, 2011 in London.Abstract: The OSGi Service Platform is a standard that specifies a comprehensive model of modules that communicate through a powerful, no overhead, Inter Module Communication mechanism: OSGi Services. OSGi enforces module-level isolation that forbids ad hoc cross-module class loading but this conflicts with prevalent Java software patterns that assume application-wide class visibility. OSGi Connect proposes the OSGi programming model without the module-level isolation. This presentation will show you how you can use OSGi Connect to begin to modularize your existing applications with the OSGi programming model with a minimal upfront investment.

TRANSCRIPT

Services-First Migration to OSGi

BJ Hargrave (IBM)Peter Kriens (aQute)

woensdag 16 november 11

Agenda

• Modularity Maturity Model

• The Brick Wall

• Couplings

• µServices

• What Broker?

• Example

• Conclusion

woensdag 16 november 11

Modularity Maturity Model

• 1 Ad Hoc

• 2 Managed

• 3 Contracts

• 4 Fences

• 5 Optimize

Page 2 OSGi Alliance Marketing © 2008-2011 . All Rights Reserved, © IBM Corp. 2011

21.09.2011

Inspired by Graham Charters’ excellent OSGi Community Event 2011 presentation @ http://slidesha.re/q8EHFp

woensdag 16 november 11

Modularity Maturity Model

woensdag 16 november 11

1. Ad Hoc• Flat, manual class path

• Single name space

• Full visibility and normal accessibility

• Monolithic

• Highly coupled

• Split Packages

• Add/Shuffle JARs until it works

woensdag 16 november 11

1. Ad Hoc• Flat, manual class path

• Single name space

• Full visibility and normal accessibility

• Monolithic

• Highly coupled

• Split Packages

• Add/Shuffle JARs until it works

JAR H

ell

woensdag 16 november 11

2. Managed

• Treat JARs as a module

• JAR Identity

• Naming

• Versioning

• Dependencies

• Repositories

woensdag 16 november 11

2. Managed

• Treat JARs as a module

• JAR Identity

• Naming

• Versioning

• Dependencies

• Repositories

Down

load

the

inter

net

woensdag 16 november 11

3. Contracts

• Interface based design, POJOs

• Provide contracts for each connection between JARs

• Implementation details inside the JAR

• Versioning on contracts

woensdag 16 november 11

3. Contracts

• Interface based design, POJOs

• Provide contracts for each connection between JARs

• Implementation details inside the JAR

• Versioning on contracts

classloa

der

hacks

woensdag 16 november 11

4. Fences

• Explicitly Import/Export packages

• Explicitly specify requirements and capabilities

• Enforce the module boundaries

• Semantic Versioning

• Side-by-side versioning supported

woensdag 16 november 11

4. Fences

• Explicitly Import/Export packages

• Explicitly specify requirements and capabilities

• Enforce the module boundaries

• Semantic Versioning

• Side-by-side versioning supported

Good!

woensdag 16 november 11

5. Optimize• Exploit concepts for

modules and contracts

• Delegated Control

• Optimize the code base to leverage new patterns:

• Extender

• Whiteboard

• Repeat

woensdag 16 november 11

5. Optimize• Exploit concepts for

modules and contracts

• Delegated Control

• Optimize the code base to leverage new patterns:

• Extender

• Whiteboard

• Repeat

woensdag 16 november 11

Today1.

Ad Hoc

2.Managed

3.Contracts

4.Fences

5.Optimize

woensdag 16 november 11

Today1.

Ad Hoc

2.Managed

3.Contracts

4.Fences

5.Optimize

mvn

Ivy

jigsaw

guice

,CDI

sprin

g

Enterprise

woensdag 16 november 11

OSGi

Today1.

Ad Hoc

2.Managed

3.Contracts

4.Fences

5.Optimize

mvn

Ivy

jigsaw

guice

,CDI

sprin

g

Enterprise

woensdag 16 november 11

OSGi

Today1.

Ad Hoc

2.Managed

3.Contracts

4.Fences

5.Optimize

mvn

Ivy

jigsaw

guice

,CDI

sprin

g

Enterprise

4.Fences

woensdag 16 november 11

woensdag 16 november 11

woensdag 16 november 11

Class.forName(String)

woensdag 16 november 11

Class Space

class

package

woensdag 16 november 11

Class Space

class

package

woensdag 16 november 11

Class Space

class

package

woensdag 16 november 11

Class Space

V1 V2

woensdag 16 november 11

Class Space

V1 V2

woensdag 16 november 11

Class Space

V1 V2

Class.forName

woensdag 16 november 11

Class Space

V1 V2

xxClass.forName

woensdag 16 november 11

Class Space

V1 V2

xxClass.forName

woensdag 16 november 11

Why Class.forName?

woensdag 16 november 11

Why Class.forName?

COUP

LING!!!!!!!!!!!!!

woensdag 16 november 11

How to get an Instance?That is the Question!

woensdag 16 november 11

Couplings

modular not modular

Example

type FooImpl foo;

instanceFoo foo = (Foo) Class.forName(“FooImpl”) .newInstance();

woensdag 16 november 11

Type Couplingclass FooImpl{}class Client {}

woensdag 16 november 11

Type Couplingclass FooImpl{}class Client {}

woensdag 16 november 11

Type Couplingclass FooImpl{}

interface Foo{}

class Client {}

woensdag 16 november 11

Type Couplingclass FooImpl{}

interface Foo{}

class Client {}

uses implements

woensdag 16 november 11

Type Couplingclass FooImpl{}

interface Foo{}

class Client {}

uses implements

get instance

woensdag 16 november 11

Type Couplingclass FooImpl{}

interface Foo{}

class Client {}

uses implements

get instance

Contro

l

Issue

s?

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

implclient container

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

implclient container

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

implclient container

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

implclient container

woensdag 16 november 11

Instance Coupling

• New

• Factory

• Inversion of Control

• Broker

implclient container

woensdag 16 november 11

µServices Primitive• Broker Pattern

• Direction

• Contract

• Publish

• Find

• Bind

• Who’s Listening?

• Cardinality

woensdag 16 november 11

µServices Primitive• Broker Pattern

• Direction

• Contract

• Publish

• Find

• Bind

• Who’s listening?

• Cardinality

BA S

woensdag 16 november 11

Patterns

• Factory

• Listener

• Discovery

• Distribution

woensdag 16 november 11

5. Optimize

E

woensdag 16 november 11

5. Optimize

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

Back to the Brick Wall

woensdag 16 november 11

Migration

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

Migration

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

D

A

G

B

E

H

C

F

I

Migration

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

D

A

G

B

E

H

C

F

I

Migration

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

Migration

D

A

G

B

E

H

C

F

I

woensdag 16 november 11

So we need a broker that runs without

fences...

woensdag 16 november 11

So we need a Broker that runs without

Fences...

PojoSR

woensdag 16 november 11

POJOSR

• Developed by Karl Pauls

• JavaOne presentation 24811

• http://pojosr.googlecode.com

• Based on Apache Felix

woensdag 16 november 11

Gain• Existing libraries and many bundles work without

modification

• Bundle (JAR) activation (have their own local main)

• µServices

• Dynamicity (in µServices)

• Extender pattern (react on JAR content)

• Migration path to Fences (OSGi)

• Existing OSGi and non-OSGi tooling can be used

woensdag 16 november 11

Loss

• No dynamic install/uninstall/update

• No side-by-side versioning

• No module privacy

• No explicit dependencies

• No Lazy activation

• No Bundle classpath

• No Native Code support

woensdag 16 november 11

Migrating

• Example: extend ant … the tool we all (sometimes) love and (sometimes) hate

• We make different <helloXXX/> tasks

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

pojosrant

......

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojosrant

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojosrant

Class<Task>

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojosrant

helloactivator

Class<Task>

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojosrant

helloactivator

Class<Task>

woensdag 16 november 11

Ant Your Service

<project name="master">

<path id="bundles"> <fileset dir="bundles"> <include name="*.jar" /> </fileset> </path>

<taskdef name="auto" classname="aQute.ant.connect.AutoTask" classpathref="bundles" /> <auto />

<helloActivator />

</project>

woensdag 16 november 11

Ant Your Servicepublic class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception { Properties props = new Properties(); props.put("ant", "helloActivator"); context.registerService(Class.class.getName(), HelloTask.class, props); }

public void stop(BundleContext context) throws Exception { }}public class HelloTask extends Task { String message = "Hello Activator"; public void execute() { System.out.println(message); } public void setMessage(String m) { this.message = m; }}

woensdag 16 november 11

Ant Your Servicepublic class Activator implements BundleActivator {

public void start(BundleContext context) throws Exception { Properties props = new Properties(); props.put("ant", "helloActivator"); context.registerService(Class.class.getName(), HelloTask.class, props); }

public void stop(BundleContext context) throws Exception { }}public class HelloTask extends Task { String message = "Hello Activator"; public void execute() { System.out.println(message); } public void setMessage(String m) { this.message = m; }}

cruft

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojoant

helloactivator

Class<Task>

pojosrant

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojoant

helloactivator

Class<Task>

pojosrant

helloextendee

woensdag 16 november 11

Ant Your Service

• Base ant

• Activator

• Extenderant

......

pojoant

helloactivator

Class<Task>

pojosrant

helloextendee

Manifest-Version: 1.0Ant-Task: helloExtender=HelloTask

woensdag 16 november 11

Ant Your Service

public class HelloTask extends Task { String message = "Hello Extender"; public void execute() { System.out.println(message); } public void setMessage(String m) { this.message = m; }}

woensdag 16 november 11

Ant Your Service

public class HelloTask extends Task { String message = "Hello Extender"; public void execute() { System.out.println(message); } public void setMessage(String m) { this.message = m; }}

NO cr

uft

woensdag 16 november 11

Conclusion

• Moving to Fences is hard because popular instance creation patterns are fundamentally not modular

• Services-First approach works without Fences

• After completion, moving to Fences is much easier

woensdag 16 november 11

Good FencesMake Good Neighbors

woensdag 16 november 11

Good FencesMake Good Neighborsmodules

woensdag 16 november 11

Q&A

woensdag 16 november 11

top related