Tutorial OSGi avec Apache Felix - Partie 4

Revenir au sommaire

=Requirements=


 * Felix Framework Distribution (voir Tutorial OSGi avec Apache Felix - Partie 1)
 * Eclipse.
 * To support OSGi development, Eclipse needs the PDE (Plug-in Development Environment) plug-in, bundled in Eclipse IDE for Java EE Developers
 * iPOJO Nature plug-in for Eclipse as an archive distribution
 * Install the iPOJO Project Nature and iPOJO Nature Dependencies plug-ins

Eclipse Configuration
By default, Eclipse uses its installation directory as the Target Platform, i.e. the group of bundles accessible by your bundle project. You should declare the installation folder of the Felix Framework as the target platform to avoid compilation and access rights errors.


 * 1) Open Eclipse preferences
 * 2) Plug-in Development > Target Platform
 * 3) Add...
 * 4) Create an empty target platform (check nothing...)
 * 5) Add the bin and bundle folders of your Felix installation to the Target Platform
 * 6) Set the new target platform as the current one

=I. Activator=


 * 1) Create an Eclipse Plug-in project fr.erods.tp.bundle1
 * 2) * New > Plug-in project
 * 3) * Select the option "Target Platform" > "an OSGi framework" > standard
 * 4) * Next
 * 5) * Check "Generate an activator"
 * 6) * Finish
 * 7) Open the activator class and print some text when the bundle starts and stops
 * 8) Export the bundle JAR file with iPOJO Nature
 * 9) * Right click on the bundle project > Export > iPOJO Bundle
 * 10) * Choose an output folder (the Felix installation folder)
 * 11) * Finish
 * 12) Install and test the bundle using the Felix shell (start/update/stop)

=II. Pure-OSGi service=


 * 1) Create an new bundle project fr.erods.tp.api.
 * 2) * Activator is not needed: uncheck "Generate an activator" in step 2
 * 3) Create the   interface with two methods:
 * 4) Export the API package
 * 5) * Open the Manifest.mf file of fr.erods.tp.api
 * 6) * In tab "Runtime" > "Exported Packages" > Add
 * 7) ** Select the  package
 * 8) Implement the service in bundle 1
 * 9) * Create the class, implementing   in the bundle 1.
 * 10) Register the service with the activator of bundle 1
 * 11) * see registerService
 * 12) * see unregister
 * 13) Implement a service consumer in a new bundle
 * 14) * Create project fr.erods.tp.bundle2
 * 15) * Import the API package
 * 16) ** In the Manifest.mf file of bundle 2
 * 17) ** In tab "Dependencies" > "Imported Packages" > Add
 * 18) ** Select the  package
 * 19) * Implement a  class, implementing the OSGi   interface
 * 20) * Print a message when the service is bound/unbound
 * 21) Test the bundles in Felix
 * 22) * What happens when the consumer is started after the service bundle ?
 * 23) * Correct this behavior, using getServiceReference and getService
 * 1) * What happens when the consumer is started after the service bundle ?
 * 2) * Correct this behavior, using getServiceReference and getService

=II. iPOJO: provide and consume with iPOJO= 1. Either use new projects or rewrite existing ones -> Import package API

2. Set iPOJO Nature to the project, with annotations

3. Implement ConsumerIpojo and ProviderIpojo

4. Test

=III. Whiteboard pattern= 1. Create interface IJobListener in package API (onJobCreation, onJobDeletion) 2. Create a new bundle, with iPOJO annoations 3. Import package API 4. Create a component providing IJobListener 5. Modify the schedule component to require the listeners, as optional requirement, and notify them on job creation/deletion 6. Test =IV. Config Admin with iPOJO=

=V. JMX MBean with iPOJO= 1. Create a new bundle, with iPOJO annotations to list current jobs status

=VI. Gogo Command with iPOJO= 1. Create a new bundle, with iPOJO annotations to list current jobs status

=VII. Event Admin with iPOJO= 1. Create a new bundle, with iPOJO annotations to send events on jobs status changes

=IX. Extender with iPOJO= ??

=X. Guidelines & Good Practices ("OSGi Zen")=