Enabling modularization through OSGi and SpringDM


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Enabling modularization through OSGi and SpringDM

  1. 1. Enabling Modularization through OSGi and SpringDynamicModules Mukul Kumar System Software Engineer India Software Labs IBM, INDIA [email_address]
  2. 2. Agenda <ul><li>OSGi as Service Platform </li></ul><ul><li>Spring Dynamic Modules </li></ul><ul><li>Summary </li></ul><ul><li>Q & A </li></ul>
  3. 3. OSGi as Service Platform <ul><li>Limitations with conventional Java applications </li></ul><ul><li>What is OSGi ? </li></ul><ul><li>OSGi Framework Architecture </li></ul><ul><li>SOA Infusion </li></ul><ul><li>Demo </li></ul>
  4. 4. Limitations with conventional Java applications <ul><li>JAR Hell ( limitations caused by JAR files ) </li></ul><ul><li>No Runtime boundaries between the JAR files. </li></ul><ul><li>Information hiding only at class level but not at modular level. </li></ul><ul><li>No versioning </li></ul><ul><li>Classloading </li></ul><ul><li>Dependency on other JAR(s) </li></ul>
  5. 5. JSR 277 – Java Module System <ul><li>Module is a deployment abstraction. </li></ul><ul><li>Defines a distribution format (i.e. Java Module) and a repository for collections of Java code and related resources. It also defines the discovery, loading, and integrity check mechanism at runtime. </li></ul><ul><li>JSR 277 defines a static module system. There is no dynamic loading and unloading of modules/bundles, any change will require to reboot the JVM. </li></ul>
  6. 6. What is OSGi ? <ul><li>OSGi stands for Open Service Gateway Initiative. </li></ul><ul><li>OSGi is Dynamic Module System for Java. </li></ul><ul><li>OSGi framework implements a complete service oriented and dynamic module system. </li></ul><ul><li>OSGi specification also enables modules/bundles to hide their implementation from other modules/bundles. </li></ul>
  7. 7. OSGi Framework Architecture http://www.osgi.org
  8. 8. Module Layer <ul><li>Packaging: Reusable bundles contains application code and libraries. </li></ul><ul><li>Code Security: Supports code hiding and explicit sharing. </li></ul><ul><li>Versioning : Different versions of same JAR can be used in single VM. </li></ul><ul><li>Classloading : Advance classloading schemes. </li></ul>bundle bundle bundle bundle bundle bundle
  9. 9. Life Cycle Layer <ul><li>Offers an API for bundle life cycle management that manages modules at runtime. </li></ul><ul><li>These dynamics are generally not part of applications and fully protected with security mechanism. </li></ul>installed resolved uninstalled active stopping starting start stop install uninstall uninstall
  10. 10. Bundles <ul><li>A bundle mainly consists of a group of Java classes and a metadata descriptor, MANIFEST.MF file. </li></ul>
  11. 11. MANIFEST.MF
  12. 12. Activator <ul><li>Bundle is started by BundleActivator class. </li></ul><ul><li>Interface has 2 methods. </li></ul><ul><ul><li>start(): initialize and return immediately </li></ul></ul><ul><ul><li>stop(): clean up </li></ul></ul><ul><li>BundleContext gives access to framework functions. </li></ul><ul><li>Framework functions enables us to start/stop the group of applications. </li></ul>
  13. 13. Service Layer <ul><li>Provides an In-VM service Model </li></ul><ul><ul><li>Discover services based on their interface or properties. </li></ul></ul><ul><ul><li>Bind to one or more services. </li></ul></ul>OSGi Service Registry Bundle A Bundle B registers get
  14. 14. SOA Infusion <ul><li>Based on contract (interface) </li></ul><ul><li>Separate the contract form implementations. </li></ul><ul><li>Dynamically discover and bind alternate implementations inside a Java VM. </li></ul><ul><li>Components are reusable. </li></ul>Service Contract Component provides uses courtesy:
  15. 15. DEMO <ul><li>Hello OSGi </li></ul><ul><li>Service Registration </li></ul><ul><li>Service Tracker </li></ul>
  16. 16. Service Registration <ul><li>Exporting Service </li></ul><ul><ul><li>MANIFEST.MF </li></ul></ul><ul><ul><ul><li>Export-Package : com.eclipseday.osgi.employee.service </li></ul></ul></ul><ul><li>Importing Service </li></ul><ul><ul><li>MANIFEST.MF </li></ul></ul><ul><ul><ul><li>Import-Package : com.eclipseday.osgi.employee.service </li></ul></ul></ul><ul><li>This is also called Bundle Dependency Management, facilitated by OSGi Framework Module Layer. </li></ul>
  17. 17. Service Registration
  18. 18. Service Tracker <ul><li>Extend from class org.osgi.util.tracker.ServiceTracker </li></ul>
  19. 19. Service Tracker
  20. 20. Spring Dynamic Modules <ul><li>Spring Framework </li></ul><ul><li>What is SpringDM ? </li></ul><ul><li>Extender Pattern </li></ul><ul><li>Spring Application Context </li></ul><ul><li>Demo </li></ul>
  21. 21. Spring Framework <ul><li>Lightweight Container </li></ul><ul><ul><li>Manages through the bean lifecycle </li></ul></ul><ul><li>Provide support for IOC </li></ul><ul><ul><li>Declarative support for beans wiring </li></ul></ul><ul><li>Provide support for AOP </li></ul><ul><ul><li>Advice can be applied declaratively </li></ul></ul><ul><li>Integration with Web frameworks </li></ul><ul><ul><li>Spring MVC, Struts, JSF… </li></ul></ul><ul><li>Spring JDBC support and ORM integration </li></ul>
  22. 22. Without Dependency Injection
  23. 23. With Dependency Injection <ul><li>Based on Interface, not coupled to implementation. </li></ul><ul><li>Reusable </li></ul><ul><li>Easily testable </li></ul>
  24. 24. What is SpringDM ? <ul><li>SpringDM brings OSGi benefits in to Java EE application development. </li></ul><ul><li>An OSGi Service can be imported and exported as if it were a Spring bean. </li></ul><ul><li>SpringDM is also at the heart of springsource dm server. </li></ul><ul><li>Download SpringDM from: http://www.springframework.org/osgi </li></ul>
  25. 25. Extender Pattern: org.springframework.osgi.bundles.extender <ul><li>Checks for the spring enabled bundles to be installed and create application/module context for those bundles. </li></ul><ul><li>Spring enabled bundle: </li></ul><ul><ul><li>META-INF/ spring/*.xml </li></ul></ul><ul><ul><li>Spring-Context header in MANIFEST.MF </li></ul></ul>
  26. 27. Spring Application Context <ul><li>For each spring enabled bundle, Spring Application Context (or Module Context ) will be created. </li></ul><ul><li>Application Context will be created when bundle is started and destroyed when bundle is stopped. </li></ul><ul><li>A Spring Bean can be published as if it were an OSGi Service . </li></ul><ul><li>An OSGi Service can be imported as if it were a Spring Bean in that Application Context. </li></ul><ul><li>Spring Beans/ OSGi Services communicate via OSGi Service Registry. </li></ul><ul><li>Saves interaction with low level OSGi Framework API. </li></ul>
  27. 28. DEMO <ul><li>Exporting a Spring Bean as OSGi Service </li></ul><ul><li>Importing an OSGi Service as Spring Bean </li></ul><ul><li>Using Service/Bean </li></ul>
  28. 29. Service Export Service Import
  29. 30. Using the Service
  30. 31. Summary <ul><li>OSGi benefits modular application development via: </li></ul><ul><ul><li>Versioning </li></ul></ul><ul><ul><li>Modularity </li></ul></ul><ul><ul><li>Life Cycle Management </li></ul></ul><ul><ul><li>Service Registry </li></ul></ul><ul><li>SpringDM supports modular application development by bringing OSGi benefits and Spring IOC support together. </li></ul><ul><ul><li>No need to work with low level OSGi framework API. </li></ul></ul><ul><ul><li>Manages the service dynamics internally. </li></ul></ul>
  31. 32. <ul><li>Q & A </li></ul>
  32. 33. <ul><li>Further Queries, Feedback, Suggestions … </li></ul><ul><li>are welcome @ </li></ul><ul><li>[email_address] </li></ul>
  33. 34. <ul><li>Thank you ! </li></ul>