Tutorial OSGi avec Apache Felix - Partie 4

From air
Jump to navigation Jump to search

Revenir au sommaire

Requirements

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...
    1. Create an empty target platform (check nothing...)
    2. Add the bin and bundle folders of your Felix installation to the Target Platform
  4. Set the new target platform as the current one

I. Activator


1. Create Eclipse Project "bundle.1"
New > Plug-in project
- "Target Platform" > "an OSGi framework" > "standard"
- Next
- Check "Generate an activator"
- Finish

2. Print Hello/Bye in the activator

3. Export bundle
Right clic on project > Export > iPOJO Bundle
- choose an output folder (the felix framework folder)
- finish

(note: discuss about Eclipse plug-in export and iPOJO Nature export)

4. Test bundle
- start felix
- install the bundle
- start / stop / update

II. Pure-OSGi service


1. Create the API bundle "bundle.api"
- "Target Platform" > "an OSGi framework" > "standard"
- Next
- Uncheck "Generate an activator"
- Finish

2. Create the IScheduleService interface in the package fr.erods.tp.api

3. Export the API package
- Open Manifest.mf of bundle.api
- Runtime > "exported packages" > Add

4. Import the API package in bundle 1
- Open Manifest.mf of bundle.api
- Dependencies > Imported Packages > Add

5. Implement the service in bundle 1
- Create class ScheduleImpl implementing IScheduleService in a package in bundle 1

6. Export the service in the Activator
- regSvc -> start()
- unregSvc -> stop()

7. Implement the client in bundle 2
- Create project bundle.2 (with activator)
- Import package API
- Implement a Consumer class, implementing ServiceListener
- Print a message when a service is bound/unbound

8. Test the bundles

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")