Simple OSGi Components
A recurring argument against the OSGi Service Platform is the complexity of its programming model. The dynamic nature of the services that can come and go at any time is by many considered to be too hard for "Al Bundle", the prototypical bundle programmer. Though I do not agree with the implied disdain for application programmers, I do like an easier programming model. However, what is an easier programming model? The Mobile Expert Group had an easier programming model is one of the key requirements. It turned out that people can have wildly different opinions about what an "easy model" is. Is it consistency, readable names, convenience functions, pure object oriented model? I tend to favor size over almost anything else: less is more. If it is small, it is easy to grasp and remember.
So I think I have come up with a model that almost completely takes the pain out of the dynamic service model: byte code weaving. Inspired by Richard S. Hall's Service Binder and the upcoming Declarative Services I have come up with an even more minimalistic model. Instead of having the programmers handle the drudgery of getting and ungetting services, the programmer writes code as if there are no dynamics. It uses fields as if they hold the service objects. For example:
public class MyComponent { private LogService log; private void activate() { log.log(LogService.LOG_INFO, "Hello world"); } } }
The runtime uses some (very minimal) manifest information as well as the Java type information to infer the service dependencies. It then rewrites the class byte codes of the component to instrument any references to the field with the appropriate OSGi code. This model is extremely clean, uses lazy activation, offers lots of opportunities for more functionality in similar vein, and best of all, is absolutely minimal. I can not see how the programmer could do less.
Now the strange things is that I get lots of objections from experts: not OO, violates the encapsulation, is ugly ... Still, isn't what matters the easy of programming for Al and me?
I have implemented a small prototype and it works. Anybody interested in playing with this prototype should contact me.
Peter Kriens
posted by Peter @ Wednesday, June 22, 2005



