Changes

Jump to: navigation, search

OSGi : Develop Simple Apps

242 bytes added, 22:48, 22 January 2011
no edit summary
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleContext.html BundleContext]
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator]
----------
<h4>2. Define the Bundle Service Interface</h4>
}
</source>
 
<h5>2.2 Define in the MANIFEST.MF cs.ecl.osgi.simple.bookfinder </h5>
Export-Package: cs.ecl.osgi.simple.bookfinder
</source>
----------
<h4>3. Define the Bundle Service Provider</h4>
The service ''bookfinder'' could be used only if one there is a bundle that implements the service. The bundle ''cs.ecl.osgi.simple.bookfinderservice '' implements ''BundleActivator'' interface in the ''Activator'' class. This bundle will be called 'service provider'.
<h5>3.1 Define the Activator classfor the service provider</h5>
<source lang="java">
package cs.ecl.osgi.simple.bookfinderservice;
import cs.ecl.osgi.simple.bookfinder.BookFinder;
import cs.ecl.osgi.simple.bookfinderservice.internals.BookFinderImplementation;
 
public class Activator implements BundleActivator {
</source>
<h5>3.2 Define the internal implementation of the service in a class BookFinderImplementation . The class must be defined in an internal package ''cs.ecl.osgi.simple.bookfinderservice.internals'' <u>The package will not be exposed to the outside world</u>)</h5>
<source lang="java">
}
}
//This could be any is a simple and trivial implementation: . //There real implementation should use database, file distributed system, distributed, etc. 
</source>
<h5>3.3 Define in the MANIFEST.MF for the ''cs.ecl.osgi.simple.bookfinderservice'' bundle
<source lang="xml">
Manifest-Version: 1.0
</source>
The bundle export only the package ''cs.ecl.osgi.simple.bookfinderservice '' Meanwhile, the implementation package - ''cs.ecl.osgi.simple.bookfinderservice.internals '' - <strong>is hidden to the outside world and can be change dynamically</strong> and can be changed dynamically anytime any time a better implementation is created</strong>.
The bundle provider requires the osgi framework and the interface bundle (e.g. ''cs.ecl.osgi.simple. bookfinder '' bundle)
: ''Require-Bundle'': cs.ecl.osgi.simple.bookfinder;bundle-version="1.0.0"
: ''Import-Package'': org.osgi.framework;version="1.3.0"
The bundle export its service (for instance, the bood finder service - '' cs.ecl.osgi.simple.bookfinderservice)'' export its service, namely the bood finder service:
: ''Export-Package'': cs.ecl.osgi.simple.bookfinderservice
 
----------

Navigation menu