[jboss-cvs] JBossAS SVN: r95108 - in projects/jboss-cl/trunk: classloader/src/main/java/org/jboss/classloader/plugins/loader and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 19 07:52:26 EDT 2009
Author: adrian at jboss.org
Date: 2009-10-19 07:52:26 -0400 (Mon, 19 Oct 2009)
New Revision: 95108
Modified:
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomainMBean.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderSystem.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/Loader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderMBean.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/FilteredDelegateLoader.java
projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/test/support/MockClassLoaderPolicy.java
projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
Log:
[JBCL-123] - Make sure we don't do dns lookups during getResources()
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/ClassLoaderUtils.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -24,10 +24,13 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URL;
import java.security.AccessController;
import java.security.CodeSource;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
+import java.util.Comparator;
/**
* ClassLoaderUtils.
@@ -308,4 +311,74 @@
return null;
return protectionDomain.getCodeSource();
}
+
+ /**
+ * Compare two urls
+ *
+ * @param one the first url
+ * @param two the second url
+ * @return whether one is less than two
+ */
+ public static int compareURL(URL one, URL two)
+ {
+ if (one == null)
+ throw new IllegalArgumentException("Null one");
+ if (two == null)
+ throw new IllegalArgumentException("Null one");
+
+ String a = one.getProtocol();
+ String b = two.getProtocol();
+ int result = compare(a, b);
+ if (result != 0)
+ return result;
+
+ a = one.getHost();
+ b = two.getHost();
+ result = compare(a, b);
+ if (result != 0)
+ return result;
+
+ a = one.getFile();
+ b = two.getFile();
+ result = compare(a, b);
+ if (result != 0)
+ return result;
+
+ int c = one.getPort();
+ int d = two.getPort();
+ result = c - d;
+ if (result != 0)
+ return result;
+
+ String ref1 = one.getRef();
+ String ref2 = two.getRef();
+ return compare(ref1, ref2);
+ }
+
+ private static int compare(String one, String two)
+ {
+ if (one == null && two == null)
+ return 0;
+ if (one == null)
+ return -1;
+ if (two == null)
+ return +1;
+ return one.compareTo(two);
+ }
+
+ /**
+ * URLComparator.
+ */
+ public static class URLComparator implements Comparator<URL>, Serializable
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 169805004616968144L;
+
+ public static final URLComparator INSTANCE = new URLComparator();
+
+ public int compare(URL o1, URL o2)
+ {
+ return compareURL(o1, o2);
+ }
+ }
}
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -127,6 +127,7 @@
return url;
}
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(final String name, Set<URL> urls) throws IOException
{
final ClassLoader classLoader = getClassLoader();
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomain.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -31,12 +31,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import java.util.Map.Entry;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import org.jboss.classloader.plugins.ClassLoaderUtils;
import org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter;
import org.jboss.classloader.spi.base.BaseClassLoaderDomain;
import org.jboss.classloader.spi.filter.ClassFilter;
@@ -261,9 +263,10 @@
return null;
}
+ // FindBugs: The Set doesn't use equals/hashCode
public Set<URL> loadResources(String name) throws IOException
{
- HashSet<URL> result = new HashSet<URL>();
+ TreeSet<URL> result = new TreeSet<URL>(ClassLoaderUtils.URLComparator.INSTANCE);
getResources(name, result);
return result;
}
@@ -486,6 +489,7 @@
}
@Override
+ // FindBugs: The Set doesn't use equals/hashCode
protected void beforeGetResources(String name, Set<URL> urls) throws IOException
{
boolean trace = log.isTraceEnabled();
@@ -501,6 +505,7 @@
}
@Override
+ // FindBugs: The Set doesn't use equals/hashCode
protected void afterGetResources(String name, Set<URL> urls) throws IOException
{
boolean trace = log.isTraceEnabled();
@@ -522,6 +527,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
protected void getResourcesFromParent(String name, Set<URL> urls) throws IOException
{
Loader parentLoader = getParent();
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomainMBean.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomainMBean.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderDomainMBean.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -110,6 +110,7 @@
* @return the resource urls
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
Set<URL> loadResources(String name) throws IOException;
/**
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -176,6 +176,7 @@
* @param urls the list of urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
public abstract void getResources(String name, Set<URL> urls) throws IOException;
/**
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderSystem.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderSystem.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderSystem.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -700,7 +700,7 @@
*
* @return the translators
*/
- public List<Translator> getTranslators()
+ public synchronized List<Translator> getTranslators()
{
if (translators == null || translators.isEmpty())
return Collections.emptyList();
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/Loader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/Loader.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/Loader.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -56,6 +56,7 @@
* @param urls the list of urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResources(String name, Set<URL> urls) throws IOException;
/**
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -38,6 +38,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
@@ -210,11 +211,14 @@
return new HashSet<String>(resourceCache.keySet());
}
+ // FindBugs: The Set doesn't use equals/hashCode
public Set<URL> listLoadedResources()
{
if (resourceCache == null)
return Collections.emptySet();
- return new HashSet<URL>(resourceCache.values());
+ Set<URL> result = new TreeSet<URL>(ClassLoaderUtils.URLComparator.INSTANCE);
+ result.addAll(resourceCache.values());
+ return result;
}
/**
@@ -479,6 +483,7 @@
return Iterators.toEnumeration(resourceURLs.iterator());
}
+ // FindBugs: The Set doesn't use equals/hashCode
public Set<URL> loadResources(String name) throws IOException
{
BaseClassLoaderPolicy basePolicy = policy;
@@ -487,7 +492,7 @@
if (trace)
log.trace(this + " findResources " + name + " domain=" + domain);
- Set<URL> resourceURLs = new HashSet<URL>();
+ Set<URL> resourceURLs = new TreeSet<URL>(ClassLoaderUtils.URLComparator.INSTANCE);
if (domain != null)
domain.getResources(this, name, resourceURLs);
return resourceURLs;
@@ -660,6 +665,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResourcesLocally(String name, Set<URL> urls) throws IOException
{
getResourcesLocally(name, urls, log.isTraceEnabled());
@@ -673,6 +679,7 @@
* @param trace whether trace is enabled
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResourcesLocally(final String name, final Set<URL> urls, boolean trace) throws IOException
{
if (trace)
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -466,6 +466,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResources(BaseClassLoader classLoader, String name, Set<URL> urls, boolean allExports) throws IOException
{
boolean trace = log.isTraceEnabled();
@@ -761,6 +762,7 @@
* @param trace whether trace is enabled
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResourcesFromExports(BaseClassLoader classLoader, String name, Set<URL> urls, boolean trace) throws IOException
{
String packageName = ClassLoaderUtils.getResourcePackageName(name);
@@ -931,6 +933,7 @@
* @param trace whether trace is enabled
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResourcesFromImports(ClassLoaderInformation info, String name, Set<URL> urls, boolean trace) throws IOException
{
List<? extends DelegateLoader> delegates = info.getDelegates();
@@ -1037,6 +1040,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
protected abstract void beforeGetResources(String name, Set<URL> urls) throws IOException;
/**
@@ -1046,6 +1050,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
protected abstract void afterGetResources(String name, Set<URL> urls) throws IOException;
/**
@@ -1136,6 +1141,7 @@
return getResource(classLoader, name, false);
}
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(String name, Set<URL> urls) throws IOException
{
getResources(null, name, urls, true);
@@ -1149,6 +1155,7 @@
* @param urls the urls to add to
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
void getResources(BaseClassLoader classLoader, String name, Set<URL> urls) throws IOException
{
getResources(classLoader, name, urls, false);
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderMBean.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderMBean.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderMBean.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -119,6 +119,7 @@
*
* @return the loaded resources
*/
+ // FindBugs: The Set doesn't use equals/hashCode
Set<URL> listLoadedResources();
/**
@@ -137,6 +138,7 @@
* @return the resource urls
* @throws IOException for any error
*/
+ // FindBugs: The Set doesn't use equals/hashCode
Set<URL> loadResources(String name) throws IOException;
/**
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseDelegateLoader.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -143,6 +143,7 @@
return null;
}
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(String name, Set<URL> urls) throws IOException
{
BaseClassLoader classLoader = getBaseClassLoader("getting resources ", name);
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/FilteredDelegateLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/FilteredDelegateLoader.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/filter/FilteredDelegateLoader.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -149,6 +149,7 @@
return null;
}
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(String name, Set<URL> urls) throws IOException
{
boolean trace = log.isTraceEnabled();
Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/test/support/MockClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/test/support/MockClassLoaderPolicy.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/test/support/MockClassLoaderPolicy.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -389,6 +389,7 @@
}
@Override
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(String path, Set<URL> urls) throws IOException
{
if (paths == null)
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -23,6 +23,7 @@
import java.net.URL;
+import org.jboss.classloader.plugins.ClassLoaderUtils;
import org.jboss.classloader.spi.filter.ClassFilter;
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
@@ -121,10 +122,8 @@
URL rootURL = root.toURL();
for (URL url : urls)
{
- if (rootURL.equals(url))
- {
+ if (ClassLoaderUtils.compareURL(rootURL, url) == 0)
return true;
- }
}
return false;
}
Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2009-10-19 11:51:08 UTC (rev 95107)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/policy/VFSClassLoaderPolicy.java 2009-10-19 11:52:26 UTC (rev 95108)
@@ -512,6 +512,7 @@
}
@Override
+ // FindBugs: The Set doesn't use equals/hashCode
public void getResources(String name, Set<URL> urls) throws IOException
{
if (checkFilters(name, "getResources"))
More information about the jboss-cvs-commits
mailing list