From: timur m. <tim...@we...> - 2005-02-24 11:55:53
|
Hello, I am using Jython in an OSGI container (http://oscar.objectweb.org/ for example) and it works really well. To me, OSGI containers provide two major advantages: 1. dynamic linking on the level of Java packages 2. dynamic updating of components (bundles) at runtime I discovered a problem with 2. when using Jython. The problem manifests, when I update a bundle in which Jython is being used and a Jython script instantiates some of my Java classes (which might have been updated). When doing such an OSGI bundle update, my OSGI Java adapter class does infact (using the Jython interpreter) executes the new/updated version of my Jython script in the bundle. But for some reason, that Jython script then continues to used the old/previous version of my Java classes. Not the new/updated ones. In order to fix this problem, I would need to gain a better understanding of how the Jython interpreter in normal cases discovers that Java classes in the classpath were modified. Since the VM is not restarted when an OSGI bundle get's updated, I might need to trigger this 'check for modified Java classes' manually, no? Some additional info: in order to make Jython 'see' the dynamically provided Java packages in the first place, I do the following in my OSGI Java adapter class: sys = Py.getSystemState(); sys.setClassLoader(new JythonClassLoader(getClass().getClassLoader())); Making use of the following tiny class: /** * Custom classloader, used to make Jython respect it's parent classloader. * * This will make Java packages made available through a OSGI classloader * become accessable in Jython scripts. */ public class JythonClassLoader extends ClassLoader { public JythonClassLoader(ClassLoader parent) { super(parent); } } Then, I need to make any Java package, provided through the OSGI container, become available to the Jython script by using multiple: sys.add_package(packageName); This is no problem, because all these package names can easily be retrieved. However, when the classes in these packages have been updated, they are not being used, but instead the old/non-updated version of these Java classes (the ones that were available the very first time Jython tried to instatiate them) are always used. Thus, the OSGI update does not result in a real update. (I confirmed with the Oscar developers, that indeed the two versions (old and new) of the bundle are loaded in memory in parallel during the updated process. But Jython does for some reason not let go of the old version.) Please help. BR, Timur |