View
2.191
Download
1
Category
Tags:
Preview:
Citation preview
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.01
Enabling Modularization through OSGi and SpringDynamicModules
Mukul KumarSystem Software EngineerIndia Software LabsIBM, INDIAMukul.kumar@in.ibm.com
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.02
Agenda
• OSGi as Service Platform• Spring Dynamic Modules• Summary• Q & A
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.03
OSGi as Service Platform
• Limitations with conventional Java applications• What is OSGi ?• OSGi Framework Architecture• SOA Infusion• Demo
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.04
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)
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.05
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.06
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.07
OSGi Framework Architecture
http://www.osgi.org
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.08
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.09
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.010
Bundles
• A bundle mainly consists of a group of Java classes and a metadata descriptor, MANIFEST.MF file.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.011
MANIFEST.MF
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.012
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.013
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.014
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
Componentprovides
uses
courtesy:
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.015
DEMO
• Hello OSGi• Service Registration• Service Tracker
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.016
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.017
Service Registration
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.018
Service Tracker
• Extend from class org.osgi.util.tracker.ServiceTracker
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.019
Service Tracker
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.020
Spring Dynamic Modules
• Spring Framework• What is SpringDM ?• Extender Pattern• Spring Application Context• Demo
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.021
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.022
Without Dependency Injection
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.023
With Dependency Injection
• Based on Interface, not coupled to implementation.• Reusable• Easily testable
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.024
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.025
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
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.026
JVM
OSGi Service Platform
Framework Bundles Application Bundles
Spring Application Contexts
SpringDM Extender Bundle Spring enabled Bundles
Spring bean
Service
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.027
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.028
DEMO
• Exporting a Spring Bean as OSGi Service• Importing an OSGi Service as Spring Bean• Using Service/Bean
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.029
Service Export
Service Import
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.030
Using the Service
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.031
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.
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.032
Q & A
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.033
Further Queries, Feedback, Suggestions …
are welcome @
mukul.kumar@in.ibm.com
Enabling Modularization through OSGi and SpringDynamicModules | by Mukul Kumar | available under EPL v1.034
Thank you !
Recommended