Tag Archives: equinox

Given a class, how to retrieve its bundle?

OSGI R4.2 (thus Equinox 3.5) comes (well, will come, since the spec. is not final yet) with a new simple and handy utility: the org.osgi.framework.FrameworkUtil.getBundle(Class) static method, which allows to retrieve the bundle a given class belongs to.

More specifically, this method will give you the bundle who loaded the given class, or null if the class has not been loaded by the OSGi framework (e.g. if it is a class belonging to the boot classpath…).

Thus, whenever you want to access information such as the version of a bundle, its headers,  etc. without having to query its Activator (perhaps you don’t even have an Activator for this bundle…), you know what you’ve got to use! Of course, whoever says Bundle, means BundleContext, and this handy helper is also very convenient to easily publish/consume OSGi services on behalf of the bundle… 🙄

Equinox p2: Large Scale Deployment

Last year’s Eclipse release (Ganymede) came with a new provisioning platform called p2. For years, Eclipse has been shipped along with a component called the “Update Manager”, which allowed users to easily update their Eclipse installations. Nevertheless, year after year, and especially when Eclipse 3.0 came out, it has become much more than just an IDE: it is now a software platform, built on top of Equinox (the reference implementation of the OSGi specification).

Thus, deployment needs are not limited to installing and updating only plug-ins anymore. People building software on top of Eclipse need to be able to deliver an installer for their product, which may come with a license manager which needs provisioning too, they need to have their own UI for the updating process, … and p2 answers to virtually all these needs.

p2: a provisioning platform…

To be able to provision virtually everything, the main strength of p2 is to have no a priori knowledge of the way Eclipse plug-ins or even Java applications must be handled. It’s indeed a very light framework to describe the parts that are to be installed (the Installable Units), and how they depend on each other. p2 comes with some basic instructions about how an OSGi bundle or an Eclipse product should be installed, but nothing else.

It’s up to the software vendor who wants to deliver, let’s say, a Windows executable program (which may require adding keys to the registry, or icons on the desktop, for instance) together with its Eclipse RCP application, to write the code (in fact, a p2 plug-in!) to explain p2 how this particular Installable Unit should be handled when provisioned in a given system.

… and, the next deployment standard?

Of course, although p2 is still a very young project, and may not seem mature enough for industrial usage. It is still not 100% reliable yet and lacks tooling, but the quality of this very first release is still pretty high. Since it was released, p2 has started gathering a community which is leveraging p2 in other domains than just the Eclipse project itself. Software companies like Cloudsmith, EclipseSource and Anyware Technologies are already developing tools on top of p2 ; and IBM, among others, is working hard to improve the p2 core and design a clear API.

The massive adoption of OSGi in many different areas (Eclipse runtime technologies like Equinox itself or RAP, applications servers like Websphere or Glassfish, etc.) will definitely make p2 the smartest way to deploy not only Eclipse-based applications, but any sort of scalable application as well. Indeed, when high availability is an important requirement (in other words — almost always), then you need to be able to dynamically install new modules into the running system, update existing ones, sometimes even do this remotely.

Since there is currently no real sustainable alternative for industrial deployments – did you ever try to use Java Web Start for more than just a very simple Swing or RCP application? – p2 will probably come up as a de facto provisioning technology standard.

Fiche de référence OSGi

Equinox & OSGiEn guise d’avant-goût au livre “Equinox and OSGi: The Power Behind Eclipse“, une fiche de référence sur OSGi et son implémentation de référence Equinox a été concoctée par Jeff McAffer et mise à disposition sur le site DZone.

Attention, il faut un compte pour pouvoir télécharger le PDF —et je n’ai pas le droit de le mettre à disposition ici 😉 .

En 6 pages, Jeff fait le tour de tous les concepts de base d’OSGi/Equinox, et répond à des questions que tout développeur de bundles OSGi (et plus généralement de plug-ins Eclipse) s’est un jour posé :

  • Faut-il préférer l’en-tête Import-Package à Require-Bundle pour la gestion des dépendances?
  • Quelle sont les différences entre les services OSGi, les declarative services et les extensions Eclipse? 
  • Comment manipuler ses bundles depuis la console OSGi?
  • etc. 😉

A lire absolument!