Migration solution for singletons in an OSGI environment

Posted by Ido on Stack Overflow See other posts from Stack Overflow or by Ido
Published on 2009-08-23T15:51:12Z Indexed on 2010/05/11 22:54 UTC
Read the original article Hit count: 316

Filed under:
|
|
|
|

I'm working in a JEE Environment in which each application is in a war file of its own. In the WEB-INF/lib of each application war file there is a common jar that is shared by all applications. This common jar contains several Singletons which are accessed from many points in the code. Because of the war-file boundaries each application has its own instances of the Singletons. Which is how we operate today, since we want to configure some of the singletons differently in each application.

Now we are moving towards an OSGi environment, where this solution will no longer work since each bundle has its own class loader, so if I try to access MySingleton which resides in bundle "common.jar" from bundle "appA.jar" or from bundle "appB.jar" I will get the same instance.

Remember I "want" a different instance of a singleton per bundle. (as ironic as it sounds)

Now I realize the ideal solution would be to fix the code to not rely on those singletons, however due to a tight schedule I was wondering if you guys can suggest some sort of a migration solution that would allow me to use bundle-wide singletons so each of them could be configured per bundle.

© Stack Overflow or respective owner

Related posts about osgi

Related posts about singleton