• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Declarative Services Dependency Injection OSGi style
 

Declarative Services Dependency Injection OSGi style

on

  • 18,610 views

About the standardized way of using Dependency Injection in OSGi applications

About the standardized way of using Dependency Injection in OSGi applications

Statistics

Views

Total Views
18,610
Views on SlideShare
18,399
Embed Views
211

Actions

Likes
5
Downloads
206
Comments
0

4 Embeds 211

http://www.slideshare.net 105
http://dev.day.com 100
http://www.linkedin.com 5
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Declarative Services Dependency Injection OSGi style Declarative Services Dependency Injection OSGi style Presentation Transcript

    • Declarative Services Dependency Injection OSGi style Felix Meschberger Day Management AG [email_address] Zurich, September 22 nd 2009
    • About Felix Meschberger
      • Senior Developer at Day Management AG
      • [email_address]
      • http://blog.meschberger.ch
      • OSGi Implementations @ Apache Felix
        • Declarative Services
        • Configuration Admin
        • Metatype Service
    • Contents
      • Dependency Injection
      • Implementations for OSGi
      • Declarative Services
      • Issues
      • Maven SCR Plugin
      • Declarative Services 1.1
    • 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
    • Implementations for OSGi
      • Declarative Services
      • iPOJO (Evolution of Declarative Services)
      • Spring DM
      • Blueprint Service (Evolution of Spring DM)
      • Peaberry (based on Google Guice)
      • … possibly more …
    • Declarative Services
      • Version 1.0
      • Part of Compendium Services since R4
      • XML Descriptor Based
      • Lifecycle Management
      • Dependency Injection (Services)
      • Configuration Support
    • Component Descriptor
      • XML
      • Descriptors may be embedded
      • Namespace for Component
        • http://www.osgi.org/xmlns/scr/v1.0.0
      • Descriptors listed in Bundle Manifest Header
        • Service-Component
      • Multiple Components per Document
    • Component Descriptor
        <scr:component name=“sample.component“ xmlns:scr=“...“> <implementation class=“org.sample.component“ /> <reference interface=“org.osgi.service.log.LogService“ bind=“bindLog unbind=“unbindLoad“ /> <property name=“p1“ value=“sample“ /> <property name=“p2“ type=“Integer“> 1 2 </property> </component>
    • Lifecycle Management
      • Load Descriptors on Bundle Start
      • Instantiation
      • Configuration
      • Activation
      • Dependency Injection
      • Deactivation
      • Unload on Bundle Stop
    • Component Descriptor
        <scr:component name=“sample.component“ xmlns:scr=“...“> <implementation class=“org.sample.component“ /> <reference interface=“org.osgi.service.log.LogService“ bind=“bindLog unbind=“unbindLoad“ /> <property name=“p1“ value=“sample“ /> <property name=“p2“ type=“Integer“> 1 2 </property> </component>
    • Lifecycle Sample: Activation
        package org.sample; public class Component { protected void activate ( ComponentContext c) { System.out.println(„Activating“); } protected void deactivate ( ComponentContext c) { System.out.println(„Deactivating“); } }
    • Lifecycle Sample: Binding
        package org.sample; public class Component { protected void bindLog ( LogService ls) { this.logService = ls } protected void unbindLog ( LogService ls) { this.logService = null; } }
    • Lifecycle Sample: Configuration
        package org.sample; public class Component { protected void activate ( ComponentContext c) { Dictionary props = c .getProperties() ; String p1 = (String) props.get(„p1“); int[] p2 = (int[]) props.get(„p2“); } }
    • Component Types
      • Regular Component (non-service)
      • Service
      • Service Factory
      • Component Factory
    • Dependency Injection
      • Event-based using bind/unbind methods
      • Lookup oriented using ComponentContext
      • Optionality
      • Multiplicity
      • Binding Policy
    • Configuration
      • Configuration from Configuration Admin
      • Properties from Descriptor
      • Provided through ComponentContext.getProperties()
    • Instantiation (non Factory)
      • If Enabled and Satisfied
      • Single Instance
        • No Configuration
        • Singleton Configuration ( service.pid )
      • Multiple Instances
        • Factory Configuration ( service.factoryPid )
    • Instantiation (Component Factory)
      • ComponentFactory.newInstance()
      • ComponentInstance.dispose()
      • Controlled by Application Only
      • Configuration may not be Factory Configuration
    • Descriptor Unvealed: Component
        <scr:component name= enabled= immediate= factory= configuration-policy= activate= deactivate= > … Component Description …
      • </scr:component>
    • Descriptor Unvealed: Implementation
        <implementation class= />
    • Descriptor Unvealed: Property
        <property name= value= type= /> <property name= type= > … values … </property>
    • Descriptor Unvealed: Properties
        <properties entry= />
    • Descriptor Unvealed: Service
        <service servicefactory= > <provide interface= /> … More Provide Elements … </service>
    • Descriptor Unvealed: Reference
        <reference name= interface= cardinality= policy= target= bind= unbind= />
    • Issue: Configuration Data Types
      • Wrapper of primitive types
        • Byte, Short, Integer, Long, etc.
      • String
      • Array or Vector
        • Primitive types
        • Wrappers of primitive types
        • String
    • Issue: XML Descriptor
      • Good to re-use legacy POJO
      • Problematic to keep in-sync with DS Classes
      • YAXF – Yet another XML File
    • Maven SCR Plugin
      • Generates Descriptors from Java Source
        • JavaDoc tags
          • @scr.component, @scr.property, ...
        • Java Annotations
          • @Component, @Property, ...
        • High Level Annotations
          • @SlingServlet
    • Issue: Not really POJO
      • Requires OSGi API for full functionality
      • Activate and Deactivate method names fixed
      • Configuration through ComponentContext
      • Service properties through ServiceReference
      • Fixed in Declarative Services 1.1
    • Declarative Services 1.1
      • Scheduled for OSGi R 4.2
      • Configurable names for (de)activator methods
      • More (de)activator method arguments
        • ComponentContext
        • BundleContext
        • Map
        • int/Integer (deactivator only)
        • Any combination
    • Declarative Services 1.1 (cont.)
      • More (un)bind method arguments
        • ServiceReference
        • Service instance
        • Service instance and Map
      • Configuration Dependency
        • Optional
        • Ignore
        • Require
      • Support for private properties
    • Declarative Services 1.1 (cont.)
      • Activator and bind methods may be
        • public (discouraged)
        • protected
        • private (if in the component class)
        • default (if in the same package)
      • Wildcards for Service-Component header
    • Questions
    • Thank You!