POJO Service Registry brings OSGi to the Classpath
A new project on Google Code, the Pojo Service Registry, aims to provide an OSGi-lite mechanism for Java applications, but outside of a OSGi runtime.
Although OSGi is known for its strong approach to modularity, sometimes the use of multiple classloaders (required in order to be able to dynamically install, update and remove bundles) causes problems with libraries that assume a flat classpath. However, a key benefit of programming against the OSGi μservice model is that implementations and clients need have no prior knowledge of their implementations in order to be wired up.
The aim of the Pojo Service Registry is to provide a means to take advantage of the OSGi service model, but without the multiple classloaders and dynamic bundle requirements. The same APIs and signatures are used, but in order to locate a service in PojoSR the classpath is scanned for any services that are exported in an OSGi-like manner. In addition, bundle activators are automatically started as part of the classpath scanning at startup.
Although it has been referred to as OSGi-lite, it remains to be seen whether the OSGi namespace and APIs can continue to be used, since it is not part of the official OSGi specification. On the other hand, it has inspired many to pick up and work with it, including getting an implementation of Felix on Google App Engine; a demonstration app is available at http://pojosr-demo.appspot.com/system/console.
Getting Felix to run on Google App Engine is not as simple as it seems; for example, GAE does not allow threads to be created (and inherently the OSGi framework is multi-threaded) – but with a few minor modifications (including making the event notification framework synchronous) allows the runtime to be bootstrapped.
One other aspect is that since the class path is computed based on the set of JARs on the classpath, any nested bundles (using
Bundle-ClassPath) won't be resolved. This has led some to question whether it is better to embed or inline nested dependencies – though arguably, in a PojoSR approach where the classpath is flat, it may make sense to do neither and externalise the dependency as its own bundle.
PojoSR allows projects to migrate towards using OSGi μservices without having to go the full OSGi way, and provide services by adjusting the contents of the classpath rather than the contents of an XML file. Whether it gets officially blessed or tolerated by the OSGi Alliance remains to be seen.
How Can We Use Our Creative Power and Technological Opportunity to Address the Challenges of the 21st Century?
Gyorgyi Galik Feb 26, 2015