Thanks John for the reply. you are right, I think OSGi supports dynamic swapping through enforcing a programming model that needs to be admitted to by both the service providers and the service consumers. In my particular case however, I am reluctant to assume that all other bundles need to follow this programming model. Especially because I am dealing with bundles which may not necessarily have the source code for their classes available. Even though for exposed services the problem is taken care of by the OSGi internals, I don't want to enforce this constraint to all the other classes in the bundle. So, I wonder if hot swapping can be done with minimal intervention to the internals of other previously written bundles.
As a separate question, do we always assume that all classes in a bundle are either not shared with other bundles or if shared, it is through the OSGi service registry? And that if sharing through import-packge and export-package constructs happen, then there is no guarantee for proper code swapping to take place? cheers, -Nima 2010/11/30 John Bäckstrand <[email protected]> > Would the other bundles not need to do something actively to swap out > classes? You can't (as far as I know?) swap classes seamlessly from under > running java code without the code doing its own classloading, getting new > classloaders at the very least. I dont think OSGI tried to do what jrebel > for instance does. > > On Tue, Nov 30, 2010 at 10:53, Nima Kaviani <[email protected]> > wrote: > > > Hello all, > > > > I have a ClassLoading issue with my bundles and I hope you can help me > > solve > > it. > > > > The problem is that I have two versions of a bundle ( let's name them A > and > > A' ) exposing some services to other bundles in the application. Both > > versions have quite identical classes except for bundle A having some > extra > > profiling code in all of its classes compared bundle A. Each bundle A or > A' > > shares instances from its classes with other bundles either through > service > > hooks or through explicit export- and import-package constructs. > > > > The problem I am facing is that when I swap A with A', the objects shared > > as > > OSGi services get swapped as expected, however the classes shared through > > explicit import and export constructs don't get swapped. Explicitly said, > > some of the classes from A remain loaded and accessible to classes in > other > > bundles through the defining class loader that for the first time loads > > those classes. However, classes providing a service are swapped as a > matter > > of replacing A with A'. > > > > I believe this is mainly because the defining loader that initially loads > > classes from A remains reachable by some other bundles in the > application. > > However, it seems very difficult for me to detect which bundles are > holding > > references and to which classes from the initially loaded classes in A. I > > wonder if there is any way to explicitly enforce the initially loaded > > classes to get garbage collected so that every single time I swap A and > A', > > I get proper wiring for classes in each bundle as expected. > > > > I would very much appreciate any help or hint, > > -Nima > > > > -- > > http://nima.magic.ubc.ca > > > > > > -- > John Bäckstrand > -- http://nima.magic.ubc.ca

