|
![]() |
OSGi is a corporation that works on the definition and promotion of open specifications.
These specifications are mainly aimed to packaging and delivering services among all kinds of networks.
OSGi Framework
The OSGi specification define a framework that allows to a diversity of services to
be executed in a service gateway, by this way, many applications can share a single JVM .
The OSGi framework entities.
Bundles
In order to be delivered and deployed on OSGi, each piece of code is packaged into bundles.
Bundles are functionnal entities offering services and packages.
They can be delivered dynamically to the framework. Concretely a bundle is a Java jar file containing :
Bundles can be plugged dynamically and their so called lifecycle can be managed through the framework ( start, stop, update, ...).
Manifest file
This important file contains crucial parameters for the bundle file.
It specifies which Activator (entry point) the bundle has to use, the bundle classpath, the imported and exported packages, ...
Services
Bundles communicates with each other thanks to services and packages sharing.
A service is an object registered into the framework in order to be used by other applications.
The definition of a service is specified in a Java interface. OSGi specify a set of standard services like Http Service, Log Service ...
We currently use the OSCAR objectweb implementation.
For more information on OSGi, please visit the OSGi website .
ProActive bundle and service
In order to use ProActive on top of OSGi, we have developped the ProActive Bundle that contains all classes required to launch a ProActive runtime.
The ProActive bundle offers a service , the ProActiveService that have almost the same interface that the ProActive static classe.
When installed, the ProActive bundle starts a new runtime, and clients that use the ProActive Service will be able to create active object on this runtime.
The Proactive Bundle uses the standard Http Service
The example above is a simple hello world that uses ProActive Service . It creates an Hello active Object
and register it as a service.
We use the hello basic service in the ProActive example. We have to write a bundle Activator that will create the active object and register
it as a OSGi service.
The HelloActivator has to implements the BundleActivator interface.
public class HelloActivator implements BundleActivator { ... }
The start ()
method is the one executed when the bundle starts. When the hello bundle start we need to get the reference
on the ProActive service and use it. Once we have the reference, we can create our active object thanks to the ProActiveService.newActive()
method.
Finally, we register our new service in the framework.
public void start(BundleContext context) throws Exception { this.context = context; /* gets the ProActive Service */ ServiceReference sr = this.context.getServiceReference(ProActiveService.class.getName()); this.proActiveService = (ProActiveService) this.context.getService(sr); Hello h = (Hello)this.proActiveService.newActive("org.objectweb.proactive.examples.hello.Hello", new Object [] {}); /* Register the service */ Properties props = new Properties(); props.put("name", "helloWorld"); reg = this.context.registerService("org.objectweb.proactive.osgi.ProActiveService", h, props); }
Now that we created the hello active service, we have to package the application into a bundle. First of all, we have to write a Manifest File where we specify :
Hello World ProActive Service
org.objectweb.proactive.HelloActivator
org.objectweb.proactive....
Here is what the Manifest looks like :
Bundle-Name: ProActive Hello World Bundle Bundle-Description: Bundle containing Hello World ProActive example Bundle-Vendor: OASIS - INRIA Sophia Antipolis Bundle-version: 1.0.0 Export-Package: org.objectweb.proactive.examples.hello DynamicImport-Package: org.objectweb.proactive ... Bundle-Activator: org.objectweb.proactive.examples.osgi.hello.HelloActivator
Installing the ProActive Bundle and the Hello Bundle.
In order to run the example you need to install an OSGi framework. You can download and install one from the OSCAR website.
Install the required services on the OSCAR framework :
--> obr start "Http Service"
proActiveBundle
target.
> cd $PROACTIVE_DIR/compile > ./build proActiveBundle
The bundle jar file will be generated in the $PROACTIVE_DIR/dist/ProActive/bundle/
directory.
We need now to install and start it into the OSGi Framework :
--> start file:///$PROACTIVE_DIR/dist/ProActive/bundle/proActiveBundle.jar
This command will install and start the proActive bundle on the gateway. Users can now deploy application that uses the ProActiveService.
Generation of the Hello World example bundle
To generate the Hello World bundle you have to run the build script with the helloWorldBundle
target.
> cd $PROACTIVE_DIR/compile > ./build helloWorldBundle
The bundle jar file will be generated in the $PROACTIVE_DIR/dist/ProActive/bundle/
directory.
We need now to install and start it into the OSGi Framework :
--> start file:///$PROACTIVE_DIR/dist/ProActive/bundle/helloWorldBundle.jar
The command will install and start the Hello active service. The hello service is now an OSGi service and can be accessed remotely.