Mercurial > hg > release > icedtea6-1.6
changeset 1667:da9eb62e065f
Port from trunk.
Fix classloader support such that the same loader is used for parent and all
child jnlps for a given instance.
author | Deepak Bhole <dbhole@redhat.com> |
---|---|
date | Tue, 25 Aug 2009 10:53:05 -0400 |
parents | 6bec6d168a87 |
children | 66cdb266311e |
files | ChangeLog rt/net/sourceforge/jnlp/JNLPFile.java rt/net/sourceforge/jnlp/PluginBridge.java rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java |
diffstat | 4 files changed, 106 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Aug 25 09:27:59 2009 +0100 +++ b/ChangeLog Tue Aug 25 10:53:05 2009 -0400 @@ -1,3 +1,19 @@ +2009-08-25 Deepak Bhole <dbhole@redhat.com> + + * rt/net/sourceforge/jnlp/JNLPFile.java: Add a new key variable that is + unique to each instance. + (JNLPFile): Existing constructor changed to generate a new key on call. + (JNLPFile): New constructor that takes a key. If called, sets the file's + key to it. + (getUniqueKey): Returns the unique key for the instance. + * rt/net/sourceforge/jnlp/PluginBridge.java: Generate new instance + specific unique key. + * rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java + (getInstance): Use unique instance keys to determine which classloader to + use, rather than using the URL. + (getInstance): Same. + (initializeExtensions): Provide unique key to getInstance. + 2009-08-25 Edward Nevill <ed@camswl.com> * cppInterpreter_arm.s
--- a/rt/net/sourceforge/jnlp/JNLPFile.java Tue Aug 25 09:27:59 2009 +0100 +++ b/rt/net/sourceforge/jnlp/JNLPFile.java Tue Aug 25 10:53:05 2009 -0400 @@ -23,6 +23,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -66,6 +67,9 @@ /** the network location of this JNLP file */ protected URL fileLocation; + + /** A key that uniquely identifies connected instances (main jnlp+ext) */ + protected String uniqueKey = null; /** the URL used to resolve relative URLs in the file */ protected URL codeBase; @@ -171,6 +175,33 @@ parse(root, strict, location); this.fileLocation = location; + + this.uniqueKey = Calendar.getInstance().getTimeInMillis() + "-" + + Math.abs(((new java.util.Random()).nextInt())) + "-" + + location; + + if (JNLPRuntime.isDebug()) + System.err.println("UNIQUEKEY=" + this.uniqueKey); + } + + /** + * Create a JNLPFile from a URL, parent URLm a version and checking for + * updates using the specified policy. + * + * @param location the location of the JNLP file + * @param uniqueKey A string that uniquely identifies connected instances + * @param version the version of the JNLP file + * @param strict whether to enforce the spec when + * @param policy the update policy + * @throws IOException if an IO exception occurred + * @throws ParseException if the JNLP file was invalid + */ + public JNLPFile(URL location, String uniqueKey, Version version, boolean strict, UpdatePolicy policy) throws IOException, ParseException { + this(location, version, strict, policy); + this.uniqueKey = uniqueKey; + + if (JNLPRuntime.isDebug()) + System.err.println("UNIQUEKEY (override) =" + this.uniqueKey); } /** @@ -248,6 +279,13 @@ } /** + * Returns the location of the parent file if it exists, null otherwise + */ + public String getUniqueKey() { + return uniqueKey; + } + + /** * Returns the JNLP file's version. */ public Version getFileVersion() {
--- a/rt/net/sourceforge/jnlp/PluginBridge.java Tue Aug 25 09:27:59 2009 +0100 +++ b/rt/net/sourceforge/jnlp/PluginBridge.java Tue Aug 25 10:53:05 2009 -0400 @@ -24,6 +24,7 @@ import java.net.URL; import java.net.MalformedURLException; +import java.util.Calendar; import java.util.Hashtable; import java.util.Locale; import java.util.List; @@ -103,7 +104,10 @@ codebase.getHost()); else security = null; - + + this.uniqueKey = Calendar.getInstance().getTimeInMillis() + "-" + + Math.abs(((new java.util.Random()).nextInt())) + "-" + + documentBase; } public String getTitle()
--- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Aug 25 09:27:59 2009 +0100 +++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java Tue Aug 25 10:53:05 2009 -0400 @@ -209,21 +209,54 @@ * @param policy the update policy to use when downloading resources */ public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy) throws LaunchException { + JNLPClassLoader baseLoader = null; JNLPClassLoader loader = null; - URL location = file.getFileLocation(); + String uniqueKey = file.getUniqueKey(); - if (location != null) - loader = (JNLPClassLoader) urlToLoader.get(location); + if (uniqueKey != null) + baseLoader = (JNLPClassLoader) urlToLoader.get(uniqueKey); try { - if (loader == null) - loader = new JNLPClassLoader(file, policy); + + // If base loader is null, or the baseloader's file and this + // file is different, initialize a new loader + if (baseLoader == null || + !baseLoader.getJNLPFile().getFileLocation().equals(file.getFileLocation())) { + + loader = new JNLPClassLoader(file, policy); + + // New loader init may have caused extentions to create a + // loader for this unique key. Check. + JNLPClassLoader extLoader = (JNLPClassLoader) urlToLoader.get(uniqueKey); + + if (extLoader != null) { + for (URL u : loader.getURLs()) + extLoader.addURL(u); + + loader = extLoader; + } + + // loader is now current + ext. But we also need to think of + // the baseLoader + if (baseLoader != null) { + for (URL u : loader.getURLs()) + baseLoader.addURL(u); + + loader = baseLoader; + } + + } else { + // if key is same and locations match, this is the loader we want + loader = baseLoader; + } + } catch (LaunchException e) { throw e; } - if (file.getInformation().isSharingAllowed()) - urlToLoader.put(location, loader); + // loaders are mapped to a unique key. Only extensions and parent + // share a key, so it is safe to always share based on it + urlToLoader.put(uniqueKey, loader); return loader; } @@ -236,12 +269,12 @@ * @param version the file's version * @param policy the update policy to use when downloading resources */ - public static JNLPClassLoader getInstance(URL location, Version version, UpdatePolicy policy) + public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version, UpdatePolicy policy) throws IOException, ParseException, LaunchException { - JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(location); + JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(uniqueKey); - if (loader == null) - loader = getInstance(new JNLPFile(location, version, false, policy), policy); + if (loader == null || !location.equals(loader.getJNLPFile().getFileLocation())) + loader = getInstance(new JNLPFile(location, uniqueKey, version, false, policy), policy); return loader; } @@ -259,8 +292,9 @@ //if (ext != null) { for (int i=0; i < ext.length; i++) { try { - JNLPClassLoader loader = getInstance(ext[i].getLocation(), ext[i].getVersion(), updatePolicy); - loaderList.add(loader); + String uniqueKey = this.getJNLPFile().getUniqueKey(); + JNLPClassLoader loader = getInstance(ext[i].getLocation(), uniqueKey, ext[i].getVersion(), updatePolicy); + loaderList.add(loader); } catch (Exception ex) { ex.printStackTrace();