back to API     back to index     prev     next  

ProActive on top of OSGi

Overview of OSGi -- Open Services Gateway initiative

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 active object will be accessible remotely from any java application, or any other OSGi gateway. The communication can be either rmi or http; in case of using http, the ProActive bundle requires the installation of the Http Service that will handle http communications through a Servlet. We show in the example section how to use the ProActive service.

Yet another Hello World

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 :

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"

Current and Future works



Copyright © April 2005 INRIA All Rights Reserved.