JAX 09 - OSGi Service Components Models

Post on 15-May-2015

3.767 views 1 download

Tags:

description

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

Transcript of 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)

© 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

© 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

© 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

© 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

© 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 . . .

© 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

© 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

© 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

© 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

© 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

© 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

© 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

© 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

© 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>

© 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>

© 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"/>

© 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"/>

© 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

© 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

© 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

© 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

© 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" />

© 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">

© 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

© 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

© 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

© 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>

© 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>

© 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>

© 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

© 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

© 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 + - +

© 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

© 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

© 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.

© 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