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.
- distracted by infrastructure : the time you spend on it is a time you could have used focusing on your business
- 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 ?
- 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
- Being too fine-grained : just because you can declare a lot of services, does not mean you should; think twice about your use case;
- 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
- Low packages cohesion : do finer grained package, to be able to evolute easily
- Failure to refactor : don’t forget to refactor ! It’s agile development !
- 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.
- 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.
- 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 !