JTheque : Problems when migrating to OSGi

Like you perhaps know, i'm currently migrating JTheque to OSGi. During this migration i found several problems in the JTheque architecture that made the migration impossible without changing some concepts. In this post I'll detail all the problems I found.


First of all, i had to completely change the way to cache resources. Before, i used a ResourceManager to cache images/icons. To get an image/icon, i gave to it the path to the resource and the manager made the rest. I used Spring to load the resources (using the Resource class). That worked well because all the modules and the core were in the same application context.

But now, there is an application context for each OSGi bundle, so that doesn't work at all. So i had to find an other way. The manager cannot load the resources because they're accessible from the other bundles. So I changes the way the manager works :

  1. The modules must register all the resources they need in the resource manager. They can always use Spring to load the resource or direct use the Resource class to load it.
  2. When the module need an image/icon, it ask the resource manager. The manager watch on the cache (the cache associates the Resource to the loaded image/icon) if the image is already cached. If it's cached, it directly return the image else, it load the image from the resource and return the loaded image

In that way, the resource manager doesn't have to access directly to resources on other bundles and everything works well.


The states are a way to store configuration for the modules. Before, the states must implements an interface and when they we're saved, the class were saved in a file and at startup created by reflection. But that's was not possible anymore, because the class was not accessible from the state bundle.

So I changed the way the data were saved using directly methods of the interface to get the stored data and to restore them at startup. Moreover, I also replaced the interface by annotations.


More than these other major changes, i've also some others problems :

  • The JDBC driver class was not accessible. I add the package import to the manifest headers and get the driver version from SpringSource Repository to works with OSGi
  • Substance doesn't work anymore. At this time, i don't know i that comes from OSGi or from other changes i made in the application, but i've not solved this problem.

Related articles

  • JTheque is going to OSGi
  • JTheque Core 2.1.0 released !
  • OSGi 4.2 Entreprise Release is available !
  • OSGi - Simple Hello World with services
  • Modular Java – Book Review
  • JTheque Utils 1.1.5
  • Comments

    Comments powered by Disqus