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 .
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:
The application classes, including the so called bundle Activator
The Manifest file that specifies properties about the application, for instance, which is the bundle Activator, whick packages are required by the application
Other resources the application could need ( images, native libraries, or data files ... ) .
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 .
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 has almost the same interface that the ProActive static class. 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 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.
The example below is a simple hello world that uses ProActive Service . It creates an Hello active Object and registers it as a service. We reuse the basic hello example provided within the ProActive's examples. 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 starts 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:
The name of the bundle: Hello World ProActive
Service
The class of the Activator:
org.objectweb.proactive.HelloActivator
The packages our application requires:
org.objectweb.proactive....
The packages our application exports: org.objectweb.proactive.examples.osgi.hello
We can specify others informations like author, ...
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'
Generation of the ProActive Bundle
To generate the proActiveBundle you have to run the build script with the 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.
We are working on a management application that remotely monitors and manages a large number of OSGi gateways. It uses standard Management API such as JMX ( Java Management eXtension). We are writing a ProActive Connector in order to access these JMX enabled gateways and uses Group Communications to handle large scale. Moreover, this application will be graphically written as an Eclipse plugin.
We plan to deploy remotely active objects and fractal components on OSGi gateways.
© 1997-2008 INRIA Sophia Antipolis All Rights Reserved