Weitere ähnliche Inhalte
Ähnlich wie JAX 09 - OSGi Service Components Models (20)
Mehr von Heiko Seeberger (20)
Kürzlich hochgeladen (20)
JAX 09 - OSGi Service Components Models
- 1. OSGi Service
Component 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. JAX 2009
- 2. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 2
- 3. OSGi Service Component Models
Why Components?
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 3
- 4. OSGi Service Component Models
The OO Dream
quot;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!quot;
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. 4
- 5. OSGi Service Component Models
The OO Reality
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 5
- 6. OSGi Service Component Models
Coupling!
• 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. 6
- 7. OSGi Service Component Models
How can Components help?
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 7
- 8. OSGi Service Component Models
Components ...
• 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. 8
- 9. 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
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 9
- 10. OSGi Service Component Models
Why Service Component Models?
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 10
- 11. 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
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 11
- 12. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 12
- 13. OSGi Service Component Models
OSGi Framework
Active Bundle Active Bundle
Component Component
Service
Component Component
reference
Instance Description
provide
Component Component
Description Instance
OSGi Declarative Services
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 13
- 14. OSGi Service Component Models
OSGi Framework
DS-powered Bundle
Service Component
Runtime
Component create
Service Component Runtime
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 14
- 15. OSGi Service Component Models
Declaring a Component
• Specify component description(s) via
Service-Component manifest header
Service-Component: OSGI-INF/treeView.xml
• Specify the implementation class
<component xmlns=quot;http://www.osgi.org/xmlns/scr/v1.1.0quot;>
<implementation class=quot;...TreeViewquot;/>
</component>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 15
- 16. OSGi Service Component Models
Providing a Service
• Specify each service interface
• By default components providing a service are delayed
<service>
<provide interface=quot;...IViewContributionquot;/>
<provide interface=quot;...IPersonListenerquot;/>
</service>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 16
- 17. OSGi Service Component Models
Referencing Services
• Specify the service interface
• Specify bind and unbind methods
• Specify the cardinality
<reference interface=quot;...IPersonManagerquot;
bind=quot;setPersonManagerquot;
unbind=quot;removePersonManagerquot;
cardinality=quot;1..1quot;/>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 17
- 18. OSGi Service Component Models
Concurrency for static and dynamic Policy
• 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=quot;dynamicquot;/>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 18
- 19. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 19
- 20. OSGi Service Component Models
OSGi Framework
Active Bundle Active Bundle
Application Context Application Context
Service
Bean import Bean
export
Bean
Bean
Bean
Spring Dynamic Modules
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 20
- 21. OSGi Service Component Models
OSGi Framework
Spring-powered Bundle
Spring DM Extender
Application Context create
Spring DM Extender
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 21
- 22. OSGi Service Component Models
Declaring a Bundle Application Context
• 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. 22
- 23. OSGi Service Component Models
Providing a Service
• Specify each service interface or use auto-export
• Beans exported as service cannot be lazy
<osgi:service ref=quot;treeViewquot;
auto-export=quot;interfacesquot; />
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 23
- 24. OSGi Service Component Models
Referencing Services
• A local bean is created with given ID
• Specify the service interface
• Specify the cardinality
<osgi:reference id=quot;personManagerOSGiquot;
interface=quot;...IPersonManagerquot;
cardinality=quot;1..1quot;>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 24
- 25. 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
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 25
- 26. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 26
- 27. OSGi Service Component Models
OSGi Framework
Active Bundle Active Bundle
Component Component
Service
Component Component
reference
Instance Metadata
provide
Component Component
Metadata Instance
Apache iPOJO
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 27
- 28. OSGi Service Component Models
Declaring a Component
• Component metadata will be used to
instrument the bytecode at build-time
• Specify component and instance
<ipojo>
<component classname=quot;...TreeViewquot; />
<instance component=quot;...TreeViewquot; />
</ipojo>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 28
- 29. OSGi Service Component Models
Providing a Service
• 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. 29
- 30. OSGi Service Component Models
Referencing Services
• iPOJO offers field and method injection
<requires field=quot;logServicequot; />
<requires>
<callback type=quot;bindquot; method=quot;setPersonManagerquot; />
<callback type=quot;unbindquot; method=quot;removePersonManagerquot; />
</requires>
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 30
- 31. OSGi Service Component Models
Concurrency in iPOJO
• 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. 31
- 32. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 32
- 33. OSGi Service Component Models
Comparison
DS DM iPOJO
+ + +
POJO-ness
o + o
DI power
o o +
Ease of programming model
+ + -
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. 33
- 34. OSGi Service Component Models
Agenda
• Why? What?
• OSGi Declarative Services
• Spring Dynamic Modules
• Apache iPOJO
• Guice Peaberry
• Comparison
• Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 34
- 35. OSGi Service Component Models
Dynamic Swing OSGi Demo
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. 35
- 36. OSGi Service Component Models
How to get the Demo?
• 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. 36
- 37. Thank you!
Slides at www.slideshare.net/heiko.seeberger/jax-09-osgi-service-components-models
Demo at max-server.myftp.org/trac/pm
© 2009 Seeberger, Tödter. Released under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Germany License. JAX 2009