Archives de catégorie : eclipsecon2011

10 signs you’re doing OSGi wrong at EclipseCon 2011

Jeff Mc Affer and Paul VanderLei , in a relaxed chat, presented the audience some funny slides  to emphasize on things we’re doing wrong when using OSGi.

  1. distracted by infrastructure : the time you spend on it is a time you could have used focusing on your business
  2. It’s bad mojo to pollute the POJO (Austin Powers anyone ?) : why are those developers always obsessed at getting their BundleContext ? to register services ? did you read the declarative services spec ?
  3. Using Services in a risky way : Jeff gave an example with previous P2 code, using helper method to getService (find the registry, get the reference, and the service from that reference) why risky ? to use the serviceTracker safely, you need a fat amount of lines of code, there are 5 synchronized blocks, etc.. The solution ? use Declarative Services
  4. Being too fine-grained : just because you can declare a lot of services, does not mean you should; think twice about your use case;
  5. Putting too much in your bundle : does this class needs to be duplicated or should I create a huge bundle to contain all my utility classes ? classes have to be together for a good reason
  6. Low packages cohesion : do finer grained package, to be able to evolute easily
  7. Failure to refactor : don’t forget to refactor ! It’s  agile development !
  8. Failure to define (good) API : with good fences and good gate it protects you from having people using this private method you clearly do not want to support, as a producer you have to make clear how to consume your API.
  9. Failure to follow API : related to point 9. , follow the restrictions, if you do not, migrating to the next version will become an head ache.
  10. Clinging to old ideas : it will cost you time, modularity, money if you stick on old ideas that do not take into account OSGi at all.

Stop trying to guess your start levels, think dynamic !

In a nutshell :

  • Get your granularity right
  • plan for refactoring
  • don’t pollute your POJOs, for that,
  • Use declarative services
  • Manage your APIs
  • Respect other people’s API

There’s a last sign you do OSGi wrong : you did not read the book OSGi and Equinox , Creating Modular Java Systems ;-)

Very interesting and entertaining presentation !