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

More Related Content

Enabling modularization through OSGi and SpringDM

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