[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
manik at jboss.org
Wed May 23 06:28:58 EDT 2007
User: msurtani
Date: 07/05/23 06:28:58
Modified: src/org/jboss/cache CacheImpl.java Fqn.java
Log:
Initiated a bunch of performance fixes, including replacing CopyOnWriteArraySets with org.jboss.cache.util.concurrent.ConcurrentHashSet.
Also ran an imports optimiser on the code base - there were a lot of unused imports floating about.
Revision Changes Path
1.73 +60 -60 JBossCache/src/org/jboss/cache/CacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- CacheImpl.java 23 May 2007 05:16:32 -0000 1.72
+++ CacheImpl.java 23 May 2007 10:28:58 -0000 1.73
@@ -43,6 +43,7 @@
import org.jboss.cache.transaction.TransactionManagerLookup;
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.ExposedByteArrayOutputStream;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
import org.jgroups.Address;
@@ -81,7 +82,6 @@
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
/**
* The default implementation class of {@link org.jboss.cache.Cache} and {@link org.jboss.cache.CacheSPI}. This class
@@ -154,7 +154,7 @@
* Set<Fqn> of Fqns of the topmost node of internal regions that should
* not included in standard state transfers.
*/
- private Set<Fqn> internalFqns = new CopyOnWriteArraySet<Fqn>();
+ private Set<Fqn> internalFqns = new ConcurrentHashSet<Fqn>();
/**
* True if state was initialized during start-up.
1.52 +23 -13 JBossCache/src/org/jboss/cache/Fqn.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Fqn.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Fqn.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- Fqn.java 12 Mar 2007 21:17:05 -0000 1.51
+++ Fqn.java 23 May 2007 10:28:58 -0000 1.52
@@ -58,7 +58,7 @@
* Another way to look at it is that the "/" separarator is only parsed when it forms
* part of a String passed in to Fqn.fromString() and not otherwise.
*
- * @version $Revision: 1.51 $
+ * @version $Revision: 1.52 $
*/
@Immutable
public class Fqn<E> implements Cloneable, Externalizable, Comparable<Fqn>
@@ -93,9 +93,24 @@
*/
public Fqn(List<E> names)
{
+ // the list is unsafe - may be referenced externally
+ this(names, false);
+ }
+
+ /**
+ * If safe is false, Collections.unmodifiableList() is used to wrap the list passed in. This is an optimisation so
+ * Fqn.fromString(), probably the most frequently used factory method, doesn't end up needing to use the unmodifiableList()
+ * since it creates the list internally.
+ *
+ * @param names List of names
+ * @param safe whether this list is referenced externally (safe = false) or not (safe = true).
+ */
+ protected Fqn(List<E> names, boolean safe)
+ {
if (names != null)
{
- elements = Collections.unmodifiableList(new ArrayList<E>(names));
+ // if not safe make a defensive copy
+ elements = safe ? names : new ArrayList<E>(names);
}
else
{
@@ -103,6 +118,7 @@
}
}
+
/**
* Constructs a Fqn from an array of names.
*
@@ -110,14 +126,8 @@
*/
public Fqn(E... names)
{
- if (names != null)
- {
- elements = Collections.unmodifiableList(Arrays.asList(names));
- }
- else
- {
- elements = Collections.emptyList();
- }
+ // safe - the list is created here.
+ this(Arrays.asList(names), true);
}
/**
@@ -142,7 +152,7 @@
List<E> elements = new ArrayList<E>(base.elements.size() + relative.size());
elements.addAll(base.elements);
elements.addAll(relative);
- this.elements = Collections.unmodifiableList(elements);
+ this.elements = elements;
}
/**
@@ -156,7 +166,7 @@
List<E> elements = new ArrayList<E>(base.elements.size() + childNames.length);
elements.addAll(base.elements);
elements.addAll(Arrays.asList(childNames));
- this.elements = Collections.unmodifiableList(elements);
+ this.elements = elements;
}
/**
@@ -188,7 +198,7 @@
List<String> list = new ArrayList<String>();
StringTokenizer tok = new StringTokenizer(stringRepresentation, SEPARATOR);
while (tok.hasMoreTokens()) list.add(tok.nextToken());
- return new Fqn<String>(list);
+ return new Fqn<String>(list, true);
}
/**
More information about the jboss-cvs-commits
mailing list