2. 2
About Felix Meschberger
• Senior Developer at Day Management AG
• fmeschbe@day.com
• http://blog.meschberger.ch
• OSGi Implementations @ Apache Felix
– Declarative Services
– Configuration Admin
– Metatype Service
4. 4
Dependency Injection
• Loose Coupling
– „Don't call use, we'll call you“
• Easier Testing
– Inject different implementations
• Popular in Spring Framework
• Traditionally Descriptor Based
• Current Trend: Java Annotations
5. 5
Implementations for OSGi
• Dependency Manager
• Declarative Services
• iPOJO (Evolution of Declarative Services)
• Spring DM
• Blueprint Service (Evolution of Spring DM)
• Peaberry (based on Google Guice)
• … possibly more …
6. 6
Declarative Services
• Version 1.0, Compendium R4
• Version 1.1, Comendium R4.2
• XML Descriptor Based
• Lifecycle Management
• Dependency Injection (Services)
• Configuration Support
7. 7
Component Descriptor
• XML
• Descriptors may be embedded
• Namespace for Component
– http://www.osgi.org/xmlns/scr/v1.0.0
– http://www.osgi.org/xmlns/scr/v1.1.0
• Descriptors listed in Bundle Manifest Header
– Service-Component
• Multiple Components per Document
26. 26
Configuration Data
• Wrapper of primitive types
– Byte, Short, Integer, Long, etc.
• String
• Array or Vector
– Primitive types
– Wrappers of primitive types
– String
• Aligned with...
– Metatype Service Specification
– Configuration Admin Specification
27. 27
DS 1.0 not really POJO
• Requires OSGi API for full functionality
• Activate and Deactivate method names
fixed and public or protected
• Configuration through ComponentContext
• Reference Service Properties through
ServiceReference
• Fixed in Declarative Services 1.1
28. 28
DS 1.1
• Configurable names for (de)activator
methods
• More (de)activator method arguments
– ComponentContext
– BundleContext
– Map
– int/Integer (deactivator only)
– Any combination
29. 29
DS 1.1 (cont.)
• More (un)bind method arguments
– ServiceReference
– Service instance
– Service instance and Map
• Configuration Dependency
– Optional
– Ignore
– Require
• Support for private properties
30. 30
DS 1.1 (cont.)
• Activator and bind methods may be
– public (discouraged)
– protected
– private (if in the component class)
– default (if in the same package)
• New features require DS 1.1 Namespace
• Service-Component supports Wildcards
– E.g. OSGi-INF/ds*.xml
31. 31
XML Descriptor
• Good to re-use legacy POJO
• Problematic to keep in-sync with DS Classes
• YAXF – Yet another XML File
36. 36
Apache Felix Extensions
• Management API
– Since Apache Felix SCR 1.0
– Now also in Equinox DS 1.2.0v20100125
• Service Reference: updated
– Since Apache Felix SCR 1.4.0
– OSGi Bug #63