OSGi with the Spring Framework

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

    Favorites, Groups & Events

    OSGi with the Spring Framework - Presentation Transcript

    1. Spring DM - OSGi with Spring Framework
      Patrick Baumgartner
      AD Consultant
      patrick.baumgartner@trivadis.com
      Zürich, 10.11.2009
    2. About me
      Application Development Consultant
      Web development with Spring Framework
      OSGi with Spring DM & Spring Framework
      Agile Software Development
      Certified ScrumMaster
      Co-Author of "OSGi in der Praxis“
      Spring Dynamic Modules - OSGi with Spring Framework
      2
    3. Agenda
      What is OSGi?
      The hard-coding Way
      Declarative Services
      Spring DM
      Blueprint Services
      Demo
      Conclusion
      Spring Dynamic Modules - OSGi with Spring Framework
      3
    4. What is OSGi?
      The OSGi framework is a module system for Java that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments. […] (Source: Wikipedia)
      Spring Dynamic Modules - OSGi with Spring Framework
      4
    5. Bundle Manifest – A special JAR
      Spring Dynamic Modules - OSGi with Spring Framework
      5
      Image Source: http://www.handycandy.co.uk
    6. Lifecycle of a Bundle
      Spring Dynamic Modules - OSGi with Spring Framework
      6
      UPDATE REFRESH
      INSTALL
      STARTING
      INSTALLED
      START
      UPDATE REFRESH
      RESOLVE
      EXCEPTION
      ACTIVE
      RESOLVED
      UNINSTALL
      UNINSTALL
      STOP
      STOPPING
      UNINSTALLED
    7. Service Registry
      Spring Dynamic Modules - OSGi with Spring Framework
      7
      SERVICE REGISTRY
      REGISTER
      DISCOVER
      SERVICE DESCRIPTION
      BIND
      SERVICE CONSUMER
      SERVICE PROVIDER
    8. OSGi – A Module System for Java
      Clear boundaries
      Dependencies
      Metadata
      Lifecycle
      Service Registry
      Spring Dynamic Modules - OSGi with Spring Framework
      8
    9. The hard-coding Way
      Spring Dynamic Modules - OSGi with Spring Framework
      9
    10. The hard-coding Way – Register a Service
      Register
      ServiceRegistration reg = bundleContext.registerService( ChatterBoxService.class.getName(), twitterChatterbox, properties);
      Unregister
      reg.unregister();
      Spring Dynamic Modules - OSGi with Spring Framework
      10
    11. The hard-coding Way – Consume a Service
      Get Service
      ServiceReference ref = bundleContext.getServiceReference( ChatterBoxService.class.getName());
      ChatterBoxService chatterbox = (ChatterBoxService)bundleContext.getService(ref);
      Unget Service
      bundleContext.ungetService(ref);
      Spring Dynamic Modules - OSGi with Spring Framework
      11
    12. The hard-coding Way – Consume a Service
      Get Service with ServiceTracker
      ServiceTracker tracker = new ServiceTracker( bundleContext, LogService.class.getName(), serviceTrackerCustomizer);
      tracker.open();LogService logService = (LogService) tracker.getService();
      Spring Dynamic Modules - OSGi with Spring Framework
      12
    13. Declarative Services
      Spring Dynamic Modules - OSGi with Spring Framework
      13
    14. Declarative Services
      Declarative Services (DS) are part of OSGi R4 Specification – Service Compendium
      Declaration of components in XML
      OSGI-INF/<component>.xml
      Components provides and depend on other Services
      Components need a special bundle manifest headere.g. Service-Component: OSGI-INF/TwitterChatterBox.xml
      Spring Dynamic Modules - OSGi with Spring Framework
      14
    15. Declarative Services
      <?xml version="1.0" encoding="UTF-8"?>
      <component name="com.trivadis.chatterbox.twitter">
      <implementation class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"/>
      <service>
      <provide interface="com.trivadis.chatterbox.service.ChatterBoxService"/>
      </service>
      <reference name="LOGGER"
      interface="org.osgi.service.log.LogService"
      cardinality="0..n"
      policy="dynamic"
      bind="addLogService"
      unbind="removeLogService"/>
      </component>
      Spring Dynamic Modules - OSGi with Spring Framework
      15
    16. Spring Dynamic Modules
      Spring Dynamic Modules - OSGi with Spring Framework
      16
    17. Spring Dynamic Modules
      Integration of Springs Dependency Injection and OSGi
      Formerly known as Spring OSGi
      XML files are located in META-INF/spring
      Very similar approach compared to DS
      Uses Spring DI for references to other Services and POJOs
      (Almost) no dependencies on OSGi APIs
      Components need a special bundle manifest headere.g. Spring-Context: META-INF/spring/bundle-context.xml, …
      Spring Dynamic Modules - OSGi with Spring Framework
      17
    18. The Spring DM Idea
      Spring Dynamic Modules - OSGi with Spring Framework
      18
      APPLICATION CONTEXT
      APPLICATION CONTEXT
      APPLICATION CONTEXT
      Imported Service
      Exported Service
      Spring Bean
      SPRING & SPRING DM
      OSGI FRAMEWORK
      JVM
    19. Spring Dynamic Modules
      bundle-context.xml
      <beans … >
      <bean id="twitterChatterBox"class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl">
      <property name="logService" ref="logServiceOsgi" />
      </bean>
      </beans>
      Spring Dynamic Modules - OSGi with Spring Framework
      19
    20. Spring Dynamic Modules
      bundle-context-osgi.xml
      <beans:beans …>
      <service ref="twitterChatterBox"
      interface="com.trivadis.chatterbox.service.ChatterBoxService"/>
      <reference id="logServiceOsgi" interface="org.osgi.service.log.LogService" />
      </beans:beans>
      Spring Dynamic Modules - OSGi with Spring Framework
      20
    21. Spring Dynamic Modules
      Also supports listeners, filters, and collections
      Dynamics are handled by the framework
      Proxies for service instances and collections
      Method calls are buffered
      Configurable timeouts
      Annotation-Based Injection with @ServiceReference
      Spring Dynamic Modules - OSGi with Spring Framework
      21
    22. Blueprint Services
      Spring Dynamic Modules - OSGi with Spring Framework
      22
    23. Blueprint Services
      Blueprint Services are a Standard since OSGi R 4.2 and based on the Ideas of Spring DM 1.0
      Spring DM 2.0 is the Reference Implementation (RI)
      Apache Aries Blueprint is an other implementation
      Extremely similar to Spring DM but a standard
      XML files are located in META-INF/blueprint
      Components need a special bundle manifest headere.g. Bundle-Blueprint: OSGI-INF/blueprint/config.xml, …
      Spring Dynamic Modules - OSGi with Spring Framework
      23
    24. Blueprint Services
      config.xml
      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
      <bean id="twitterChatterBox" class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl">
      <property name="logService" ref="logService" />
      </bean>
      <service ref="twitterChatterBox"
      interface="com.trivadis.chatterbox.service.ChatterBoxService" />
      <reference id="logService"
      interface="org.osgi.service.log.LogService" />
      </blueprint>
      Spring Dynamic Modules - OSGi with Spring Framework
      24
    25. Comparison Spring DM vs. Blueprint Services
      Dependency Injection
      Spring Dynamic Modules - OSGi with Spring Framework
      25
      Spring DM
      Blueprint Services
      Constructor Injection
      Setter Injection
      Field Injection
      Method Injection
      Arbitrary Method Injection
      Autowiring
      YES
      YES
      YES
      YES
      YES
      YES
      YES
      YES
      NO
      NO
      NO
      NO
      Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
    26. Comparison Spring DM vs. Blueprint Services
      Component Lifecycle
      Spring Dynamic Modules - OSGi with Spring Framework
      26
      Spring DM
      Blueprint Services
      Lazy Initialization
      Bean Scopes
      Custom Bean Scopes
      Built-in Callbacks
      Custom Callbacks
      Initialization Processing
      YES
      YES
      YES
      YES
      YES
      YES
      YES
      YES
      NO
      NO
      YES
      NO
      Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
    27. Demo
      Spring Dynamic Modules - OSGi with Spring Framework
      27
    28. Conclusion
      Should I use Declarative Services, Spring DM or Blueprint Services?
      DS, DM or Blueprint Services are better than program the life cycles and service infrastructure by hand
      If you already use Spring, use Spring DM
      If you want to use Standards use DS or Blueprint
      To switch from Blueprint Services to Spring DM you need just a few changes in the XML configuration.
      Spring Dynamic Modules - OSGi with Spring Framework
      28
    29. Thank you!

    + Patrick BaumgartnerPatrick Baumgartner, 4 months ago

    custom

    529 views, 0 favs, 0 embeds more stats

    This slides covers the programmatic and declarative more

    More info about this presentation

    © All Rights Reserved

    • Total Views 529
      • 529 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 17
    Most viewed embeds

    more

    All embeds

    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