Monday, October 29, 2012

OSGI

OSGi- Open Service Gateway initiative, OSGi defines a complete and dynamic component called Bundle.

Bundle (a jar) contains a manifest file MANIFEST.MF that specifies bundles it depends on, exposed API, excecution environment, etc.,.

Creating Bundles
A Sample MANIFEST.MF built using maven bundle plugin
Manifest-Version: 1.0
Export-Package: demo.osgi.sort
Private-Package: demo.osgi.activator
Built-By: Murali
Tool: Bnd-0.0.238
Bundle-Name: SomeOSGiBundle
Created-By: Apache Maven Bundle Plugin
Bundle-Version: 0.0.1.SNAPSHOT
Build-Jdk: 1.6.0_20
Bnd-LastModified: 1349471796912
Bundle-ManifestVersion: 2
Bundle-Activator: demo.osgi.activator.DemoBundleActivator
Bundle-SymbolicName: sample.osgi.SomeOSGiBundle
Import-Package: demo.osgi.sort,org.osgi.framework;version="1.4"
generated for below configuration-
<plugin>
 <groupId>org.apache.felix</groupId>
 <artifactId>maven-bundle-plugin</artifactId>
 <version>1.4.0</version>
 <extensions>true</extensions>
 <configuration>
  <instructions>
   <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
   <Bundle-Name>${project.name}</Bundle-Name>
   <Bundle-Version>${project.version}</Bundle-Version>
   <Bundle-Activator>demo.osgi.activator.DemoBundleActivator</Bundle-Activator>
   <Private-Package>demo.osgi.activator</Private-Package>
   <Export-Package>demo.osgi.sort</Export-Package>
  </instructions>
 </configuration>
</plugin>

Deploy bundles 
Eclipse Equinox and Apache Felix are 2 OSGi implementations.

Felix Gogo Shell- osgi command shell, to install, update, remove bundles.
Felix Remote Shell - Telnet to remote osgi instance to administer.

Service Platform
OSGi runtime is a service platform where a bundle provide for/ consume services from other bundle.