[jboss-cvs] JBossAS SVN: r90216 - projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 15 18:07:12 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-06-15 18:07:12 -0400 (Mon, 15 Jun 2009)
New Revision: 90216
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarUtils.java
Log:
Use HashSet which is typically O(1) rather than COWAS which is typically O(n)
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarUtils.java 2009-06-15 20:26:46 UTC (rev 90215)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarUtils.java 2009-06-15 22:07:12 UTC (rev 90216)
@@ -24,7 +24,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.HashSet;
+import java.util.Collections;
/**
* JarUtils.
@@ -34,20 +35,26 @@
*/
public class JarUtils
{
- /** The jar suffixes */
- private static Set<String> jarSuffixes = new CopyOnWriteArraySet<String>();
+ /** The jar suffixes (immutable, do not update unless updateLock is held) */
+ private static volatile Set<String> jarSuffixes;
+ /** The lock to hold in order to update jarSuffixes */
+ private static final Object updateLock = new Object();
// Initialise known suffixes
static
{
- jarSuffixes.add(".zip");
- jarSuffixes.add(".ear");
- jarSuffixes.add(".jar");
- jarSuffixes.add(".rar");
- jarSuffixes.add(".war");
- jarSuffixes.add(".sar");
- jarSuffixes.add(".har");
- jarSuffixes.add(".aop");
+ final HashSet<String> set = new HashSet<String>();
+ set.add(".zip");
+ set.add(".ear");
+ set.add(".jar");
+ set.add(".rar");
+ set.add(".war");
+ set.add(".sar");
+ set.add(".har");
+ set.add(".aop");
+ synchronized (updateLock) {
+ jarSuffixes = set;
+ }
}
/**
@@ -60,7 +67,11 @@
{
if (suffixes == null)
throw new IllegalArgumentException("Null suffix");
- jarSuffixes = suffixes;
+
+ synchronized (updateLock)
+ {
+ jarSuffixes = new HashSet<String>(suffixes);
+ }
}
/**
@@ -74,7 +85,19 @@
{
if (suffix == null)
throw new IllegalArgumentException("Null suffix");
- return jarSuffixes.add(suffix);
+
+ synchronized (updateLock)
+ {
+ if (jarSuffixes.contains(suffix))
+ return false;
+ else
+ {
+ final HashSet<String> newSet = new HashSet<String>(jarSuffixes);
+ newSet.add(suffix);
+ jarSuffixes = Collections.unmodifiableSet(newSet);
+ return true;
+ }
+ }
}
/**
@@ -88,13 +111,28 @@
{
if (suffix == null)
throw new IllegalArgumentException("Null suffix");
- return jarSuffixes.remove(suffix);
+
+ synchronized (updateLock)
+ {
+ if (jarSuffixes.contains(suffix))
+ {
+ final HashSet<String> newSet = new HashSet<String>(jarSuffixes);
+ newSet.remove(suffix);
+ if (newSet.isEmpty())
+ jarSuffixes = Collections.emptySet();
+ else
+ jarSuffixes = Collections.unmodifiableSet(newSet);
+ return true;
+ }
+ else
+ return false;
+ }
}
/**
- * Get the lis of jar suffixes
+ * Get the set of jar suffixes
*
- * @return the list of suffixes
+ * @return the set of suffixes
*/
public static Set<String> getSuffixes()
{
@@ -102,12 +140,13 @@
}
/**
- * Clear the list of suffixes
- *
+ * Clear the set of suffixes
*/
public static void clearSuffixes()
{
- jarSuffixes.clear();
+ synchronized (updateLock) {
+ jarSuffixes = Collections.emptySet();
+ }
}
/**
More information about the jboss-cvs-commits
mailing list