jax 09 - osgi service components models

37
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. JAX 2009 OSGi Service Component Models Heiko Seeberger (WeigleWilczek) Kai Tödter (Siemens Corporate Technology)

Upload: heiko-seeberger

Post on 15-May-2015

3.772 views

Category:

Technology


1 download

DESCRIPTION

Short talk (30 minutes) about "OSGi Service Components Models" at JAX 2009.

TRANSCRIPT

Page 1: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. JAX 2009

OSGi ServiceComponent Models

Heiko Seeberger (WeigleWilczek)Kai Tödter (Siemens Corporate Technology)

Page 2: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

2

Page 3: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Why Components?

3

Page 4: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

The OO Dream

4

"Object Oriented technology was going to change the world . . . we would have all these objects in our library and building a new system would be a snap. Just get a few classes,

bunch them together . . . and voila!"Peter Kriens, http://www.aqute.biz/Blog/2006-04-29

Page 5: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

The OO Reality

5

Page 6: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Coupling!

6

• Classes can almost never be used in isolation

• They depend on other classes

• Those classes depend on other packages, which depend on other JARs . . .

Page 7: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

How can Components help?

7

Page 8: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Components ...

8

• are self-contained and declare their dependencies

• declare their interface and hide their internals

• interact with the container and obey to a life cycle

Page 9: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi enables Components

• OSGi Framework is the container

• Managed dependencies

• Life cycle and interactions with the container

• Loose coupling through service model

9

Page 10: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Why Service Component Models?

10

Page 11: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Why not use plain OSGi APIs?

• We want to avoid OSGi glue code

• POJOs enhance testability

• Repetitive glue code reduces productivity

• Service Component Models ease service handling

• OSGi APIs lead to involved code

• SCMs offer advanced features

11

Page 12: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

12

Page 13: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi Framework

Active Bundle

Component

Component Instance

Service

reference

Component Description

Active Bundle

Component

Component Description

Component Instance

provide

OSGi Declarative Services

13

Page 14: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi Framework

DS-powered Bundle

Service ComponentRuntime

createComponent

Service Component Runtime

14

Page 15: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Declaring a Component

15

• Specify component description(s) via Service-Component manifest header

• Specify the implementation class

Service-Component: OSGI-INF/treeView.xml

<component xmlns="http://www.osgi.org/xmlns/scr/v1.1.0"> <implementation class="...TreeView"/></component>

Page 16: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Providing a Service

16

• Specify each service interface

• By default components providing a service are delayed

<service> <provide interface="...IViewContribution"/> <provide interface="...IPersonListener"/></service>

Page 17: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Referencing Services

17

• Specify the service interface

• Specify bind and unbind methods

• Specify the cardinality

<reference interface="...IPersonManager" bind="setPersonManager" unbind="removePersonManager" cardinality="1..1"/>

Page 18: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Concurrency for static and dynamic Policy

18

• No concurrency issues for static policy

• On (un)binding of references the component is deactivated and activated again

• Pay attention to concurrency for dynamic policy

• The component must be thread-safe regarding references

<reference ... policy="dynamic"/>

Page 19: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

19

Page 20: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi Framework

Active Bundle

Application Context

Bean

Service

import

Active Bundle

Application Context

Bean

exportBean

Bean

Bean

Spring Dynamic Modules

20

Page 21: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi Framework

Spring-powered Bundle

Spring DM Extender

createApplication Context

Spring DM Extender

21

Page 22: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Declaring a Bundle Application Context

22

• By default configurations are looked up under META-INF/spring/

• Multiple configurations are merged into a single Application Context

Page 23: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Providing a Service

23

• Specify each service interface or use auto-export

• Beans exported as service cannot be lazy

<osgi:service ref="treeView" auto-export="interfaces" />

Page 24: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Referencing Services

24

• A local bean is created with given ID

• Specify the service interface

• Specify the cardinality

<osgi:reference id="personManagerOSGi" interface="...IPersonManager" cardinality="1..1">

Page 25: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Concurrency in Spring DM

• References are only injected once

• Proxies for unary references

• Managed collections for multiple references with “Iterator guarantee”

• Concurrency issue is swapped for uncertainty

• ServiceUnavilableException

25

Page 26: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

26

Page 27: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

OSGi Framework

Active Bundle

Component

Component Instance

Service

reference

Component Metadata

Active Bundle

Component

Component Metadata

Component Instance

provide

Apache iPOJO

27

Page 28: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Declaring a Component

28

• Component metadata will be used to instrument the bytecode at build-time

• Specify component and instance

<ipojo> <component classname="...TreeView" /> <instance component="...TreeView" /></ipojo>

Page 29: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Providing a Service

29

• Service interfaces are computed by iPOJO

• iPOJO services are created lazily

<component ...> <provides /></component>

Page 30: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Referencing Services

30

• iPOJO offers field and method injection

<requires field="logService" /><requires> <callback type="bind" method="setPersonManager" /> <callback type="unbind" method="removePersonManager" /></requires>

Page 31: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Concurrency in iPOJO

31

• iPOJO manages concurrency for references

• We can write our code without regard for thread-safety

• Bytecode instrumentation weaves in all necessary synchronization

Page 32: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

32

Page 33: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Comparison

33

DS DM iPOJO

POJO-ness + + +

DI power o + o

Ease of programming model o o +

Ease of build + + -

Size and dependencies + - +

Support for laziness + - +

Page 34: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Agenda

• Why? What?

• OSGi Declarative Services

• Spring Dynamic Modules

• Apache iPOJO

• Guice Peaberry

• Comparison

• Demo

34

Page 35: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

Dynamic Swing OSGi Demo

35

Page 36: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License.

OSGi Service Component Models

How to get the Demo?

36

• http://max-server.myftp.org/trac/pm

• Wiki with some documentation

• Anonymous Subversion access

• Trac issue tracking

• Licenses

• All PM project sources are licensed under EPL

• Swing Application Framework (JSR 296) implementation is licensed under LGPL

• Swing Worker is licensed under LGPL

• The nice icons from FamFamFam are licensed under the Creative Commons Attribution 2.5 License.

Page 37: JAX 09 - OSGi Service Components Models

© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. JAX 2009

Thank you!Slides at www.slideshare.net/heiko.seeberger/jax-09-osgi-service-components-models

Demo at max-server.myftp.org/trac/pm