Declarative Services Dependency Injection OSGi style

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites & 1 Group

    Declarative Services Dependency Injection OSGi style - Presentation Transcript

    1. Declarative Services Dependency Injection OSGi style Felix Meschberger Day Management AG [email_address] Zurich, September 22 nd 2009
    2. 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
    3. Contents
      • Dependency Injection
      • Implementations for OSGi
      • Declarative Services
      • Issues
      • Maven SCR Plugin
      • Declarative Services 1.1
    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. 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 …
    6. Declarative Services
      • Version 1.0
      • Part of Compendium Services since R4
      • XML Descriptor Based
      • Lifecycle Management
      • Dependency Injection (Services)
      • Configuration Support
    7. 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
    8. 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>
    9. Lifecycle Management
      • Load Descriptors on Bundle Start
      • Instantiation
      • Configuration
      • Activation
      • Dependency Injection
      • Deactivation
      • Unload on Bundle Stop
    10. 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>
    11. 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“); } }
    12. 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; } }
    13. 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“); } }
    14. Component Types
      • Regular Component (non-service)
      • Service
      • Service Factory
      • Component Factory
    15. Dependency Injection
      • Event-based using bind/unbind methods
      • Lookup oriented using ComponentContext
      • Optionality
      • Multiplicity
      • Binding Policy
    16. Configuration
      • Configuration from Configuration Admin
      • Properties from Descriptor
      • Provided through ComponentContext.getProperties()
    17. Instantiation (non Factory)
      • If Enabled and Satisfied
      • Single Instance
        • No Configuration
        • Singleton Configuration ( service.pid )
      • Multiple Instances
        • Factory Configuration ( service.factoryPid )
    18. Instantiation (Component Factory)
      • ComponentFactory.newInstance()
      • ComponentInstance.dispose()
      • Controlled by Application Only
      • Configuration may not be Factory Configuration
    19. Descriptor Unvealed: Component
        <scr:component name= enabled= immediate= factory= configuration-policy= activate= deactivate= > … Component Description …
      • </scr:component>
    20. Descriptor Unvealed: Implementation
        <implementation class= />
    21. Descriptor Unvealed: Property
        <property name= value= type= /> <property name= type= > … values … </property>
    22. Descriptor Unvealed: Properties
        <properties entry= />
    23. Descriptor Unvealed: Service
        <service servicefactory= > <provide interface= /> … More Provide Elements … </service>
    24. Descriptor Unvealed: Reference
        <reference name= interface= cardinality= policy= target= bind= unbind= />
    25. Issue: Configuration Data Types
      • Wrapper of primitive types
        • Byte, Short, Integer, Long, etc.
      • String
      • Array or Vector
        • Primitive types
        • Wrappers of primitive types
        • String
    26. Issue: XML Descriptor
      • Good to re-use legacy POJO
      • Problematic to keep in-sync with DS Classes
      • YAXF – Yet another XML File
    27. Maven SCR Plugin
      • Generates Descriptors from Java Source
        • JavaDoc tags
          • @scr.component, @scr.property, ...
        • Java Annotations
          • @Component, @Property, ...
        • High Level Annotations
          • @SlingServlet
    28. 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
    29. 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
    30. 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
    31. 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
    32. Questions
    33. Thank You!

    + Felix MeschbergerFelix Meschberger, 4 months ago

    custom

    1739 views, 4 favs, 1 embeds more stats

    About the standardized way of using Dependency Inje more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1739
      • 1673 on SlideShare
      • 66 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 77
    Most viewed embeds
    • 66 views on http://dev.day.com

    more

    All embeds
    • 66 views on http://dev.day.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events