May 9, 2017
The Open Services Gateway Initiative (OSGi) defines an architecture for developing and deploying modular applications and libraries. It is also known as the Dynamic Module System for Java, defines an architecture for modular application development. It is proven to help build, package and maintain robust API’s for Java based Enterprise software components running in the Cloud or On Premise.
It is a specification having various implementations like Eclipse Equinox, Apache Felix, Knopflerfish, ProSyst. There are 5 specifications versions released so far and Latest version 1.8.
How it helps:
Considering all of the above points, OSGi enables implementation to be modularised, structured, and loosely coupled. Also, OSGi benefits faster deliverable considering “Semantic versioning”- which in simple words: Various versions of packages should reflect the evolution of these packages. For this reason, a change in the first (major) part of the version signals backward incompatible changes to the artifacts. That is, going from version 1.5 to version 2 signals that another artifact compiled against 1.5 up to (but not including) version 2 of that initial artifact is not compatible with the new version of the initial artifact.
Let’s go through an example of how OGSi services to manage and consumer concept demonstration.
And before we proceed, here are the list of prerequisites:
Here are the steps.
Activator class:- Activator class which implements the BundleActivator interface. An instance of this class is created when the plug-in gets activated. Its start() and stop() methods are called whenever the plug-in is started or stopped.
Go to META-INF -> MANIFEST.MF -> Runtime -> Add -> “com.enprowess.summation.service”
Same as step 4.
Right click on “Calculator” module and click on “Run As -> Run Configurations”
Click on “OSGi Framwork” – “New”.
Provide appropriate name for this configuration. Here it is given as “Calculator”.
Uncheck “Target Platform” and click on “Add Required Bundles” which should automatically add the required references. You may click on “Only show selected” just to view final list of dependencies.
ss: list of services.
Start <id>: It starts the service/module mentioned by id from ‘ss’ command.
Stop <id>: It stop the service/module mentioned by id from ‘ss’ command.
To summarize, we have seen in above example, how do we use osgi modularization. Decoupling of modules gives faster turnaround time and ultimately helps business to release features and fixes at faster pace.