Now the topic is on OSGI by Sameera Jayasoma . WSO2 is an open source company hased in Srilanka. Their main product is WSO2 carbon,Which is a fully componentized SOA platform based on OSGI. Then there was some PR on their company.
Break large system into more smaller,understandable units called modules.Benefits of modular systems are reuse,abstraction,division of labour and ease of repair.
Module should be self contained,highly cohesive and loosely coupled.
Java for building Modular systems
--> provides class level modularity(public, non public methods)
--> we need somthing like external packages, internal packages in a jar
ClassLoader hierarchy : Bootstrap classloader (rt.jar) --> extension classloader (ext.jar) --> application classloader (a.jar,b.jar)
Problems with JARs
--> Jar is unit of deployment in Java and typical java app consists of set of jar files
--> no runtime representation for a JAR.
when java loads a class, it tries to load class one by one in the classpath.
--> multiple version of jar files cannot be loaded simultaneoulsy
--> Jar files cannot declare their dependencies on other jars
Java lacks true modularism and dynamism. Java has given flexibility to build system on top of it. This is called OSGI (dynamic module system for java)
--> Bundle is a unit of modularization of OSGi. OSGI app is a collection of Bundle.
Bundle is similar to jar and contains additional metada in Manifest.mf file. In osgi , java package is the unit of information hiding. unlike in jar when class is the
unit of information hiding.
--> bundle can share and hide packages from other bundles.
sample manifest.mf file
Bundle-Version:1.0.0 (major,minor,micro version)
symbolic name and version are unique for a bundle. default value for version is 1.0.0
all packages in bundle are hidden from other bundle by default. if we need to share package explicitly mention the name.
Bundles & Class Loaders
OSGI gives separate classloaders per bundle,thereby eliminating hierarchial classloading in java
System bundle is a special bundle that represents the framework and registers system services
Tooling for osgi : eclipse pde is the best of the lot
osgi provides command line interface
ss -> lists all the bundles in the system
b 0 --> gives system bundl information
export-hundle and import-bundle
require-bundle : import all exported packages from another bundle. but this is discouraged.
Issues with require bundle
Split packages,bundle changes over time,require bundles chain can occur.
fragment bundles : attached to a host bundle by the framework.Shares parent classloader.
runtime class loading in osgi: order of loadin
1) call parent clas loader (only for java.*)
4)load from its own internal classpath
5)Load from fragment classpath
Usage of fragment bundle 1) provide translation files to different locales
OSGI specifications --specifies framework and specificaions
current version is 4.1
osgi can be considered as a layer on top of java.can also use jni to talk to OS. functionality of framework is deivided into several layers
1)module 2)lifecycle 3(
Lifecyce layer : manage lifecyle of api.
bundle starts --> installed,resolved,starting,active,stopping,uninstalled.
Register a service using bundle service using registerservice on bundlecontext
Using a service --> find a serviceReference,get the object,cast it to a proper type and use the service
Events and Listeners
framework fires serviceevents during registering a service,unregistering a service
services are dynamic. monitor services using service listeners,service trackers,declarative service,iPOJO and blueprint services.
SCR (service component runtime)