Friday, December 10, 2010

Beware declaring services

The stuff to be aware of developing declared services and factories for OSGi in Eclipse

There are some simple rules I have learned, a developer need to remember to avoid wasting time trying to to understand why some things are not working:

  1. A component needs to be declared in xml file located in OSGI-INF folder.
  2. Required component's xmls needs to be included into META-INF/MANIFEST.MF via Service-Component property. Use OSGI-INF/* to include all xmls.
  3. OSGI-INF folder needs to be included into build.properties file to be deployed within bundle's jar via bin.includes property. OSGI-INF folder is not included to deployment by default.
  4. Use unique names for component name.
  5. Use component name as service.pid for declared services to avoid any configuration issues and complexity. This mean: don't declare explicitly property service.pid for declared service with value other then component.name or don't declare service.pid at all.
  6. Use component.modified property and declare component's modified method to avoid recreation of new service instance every time when configuration changed. In other words, use modified component method to update instance with new configuration at runtime or omit modified methodf new service instance has to be created for each configuration update.