On Sun, Feb 3, 2013 at 8:05 PM, Erwin Hogeweg < [email protected]> wrote:
> Neil, > > Thank for the quick reply. > > You need to show where the getInstance() method is called. Since you don't > call it from your start() or stop() method, I suspect you must be calling > it from another bundle or a thread. > > Correct, the getInstance() is called from another bundle through a > registered service. > Is the bundle exporting the service interface package, in addition to registering the service instance? If so, the importing bundle will be fixed to that export until a Refresh Packages operation is done. > Both of these could cause the old version to be pinned in memory; meaning > you will have both the old and new versions loaded simultaneously. > > (How) Could this be cleaned up? As far as I know all services are > unregistered and all resources cleaned up when the bundle is stopped. > Two ways: 1) Don't export the service interface package from the same bundle that registers the service instance. For example have a third bundle that only contains pure APIs, no implementation code. 2) Refresh packages (use the "refresh" command from the Gogo shell). This causes OSGi to recalculate the package wiring graph... now the importing bundle can be rewiring to the new version of the export. It's important to understand that package wirings in OSGi are *not* particularly dynamic, because calculating them is an expensive operation. After an update (or better, after a batched series of updates/installs/uninstalls) you should call the refresh command to indicate to OSGi that you have finished and it can now go ahead and perform the rewiring. Regards, Neil > > Regards, > > Erwin > > > > > > On Sun, Feb 3, 2013 at 4:49 PM, Erwin Hogeweg < > [email protected]> wrote: > >> Hi, >> >> I ran into an issue after I updated a bundle. After some digging I found >> that a static variable didn't have the expected value after the update. I >> have a feel for what is going on, but I can't quite connect all the dots. >> >> So here is what's happening: >> >> I have an Activator with a static self. >> >> public Activator(...){ >> private static Activator self; >> ... >> public void start(...){ >> self = this; >> ... >> } >> >> public void stop(...){ >> self = null; >> ...} >> >> public static Activator getInstance(){ >> return self; >> } >> >> When the framework starts up, everything works as expected. When the >> bundle that contains this activator is updated though, the returned value >> for self = null. When I remove the null assignment in the stop() method, >> the getInstance() method returns the self reference from before the bundle >> update. So somehow, the framework holds on to the initial Activator class, >> and keeps using this 'old' reference, even when the getInstance() call is >> made from within the bundle itself. >> >> When I inspect the classloader inside the getInstance() method it shows >> the same reference before and after the update, which is suspicious, and >> probably the cause of the problem. >> >> I am not necessarily looking for a solution because there is a better way >> to solve this problem, but I would like to understand exactly what is going >> here. I don't quite get it yet. >> >> Any insight is highly appreciated. >> >> Kind Regards, >> >> Erwin >> >> >> _______________________________________________ >> OSGi Developer Mail List >> [email protected] >> https://mail.osgi.org/mailman/listinfo/osgi-dev >> > > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev > > > > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev >
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
