[jbosscache-commits] JBoss Cache SVN: r5788 - in core/trunk/src: main/java/org/jboss/cache/annotations and 6 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu May 1 12:15:05 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-05-01 12:15:04 -0400 (Thu, 01 May 2008)
New Revision: 5788

Added:
   core/trunk/src/main/java/org/jboss/cache/annotations/
   core/trunk/src/main/java/org/jboss/cache/annotations/Experimental.java
   core/trunk/src/test/java/org/jboss/cache/profiling/StringPerformanceTest.java
Modified:
   core/trunk/src/main/java/org/jboss/cache/Cache.java
   core/trunk/src/main/java/org/jboss/cache/DataContainer.java
   core/trunk/src/main/java/org/jboss/cache/Fqn.java
   core/trunk/src/main/java/org/jboss/cache/StringFqn.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveDataCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/FqnTest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Refactoring

Modified: core/trunk/src/main/java/org/jboss/cache/Cache.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Cache.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/Cache.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -192,7 +192,7 @@
     * @param fqn   <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be accessed.
     * @param key   key with which the specified value is to be associated.
     * @param value value to be associated with the specified key.
-    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link CacheStatus.STARTED}.
+    * @throws IllegalStateException if {@link #getCacheStatus()} would not return {@link org.jboss.cache.CacheStatus#STARTED}.
     */
    void putForExternalRead(Fqn<?> fqn, K key, V value);
 

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -25,7 +25,6 @@
  */
 public class DataContainer
 {
-   // TODO: 2.2.0: Refactor and standardise method names, consolidate where possible.  A lot of these can be moved into commands.
    private static final Log log = LogFactory.getLog(DataContainer.class);
    private static boolean trace = log.isTraceEnabled();
 
@@ -36,6 +35,11 @@
     */
    private NodeSPI root;
 
+   /**
+    * Set<Fqn> of Fqns of the topmost node of internal regions that should
+    * not included in standard state transfers.
+    */
+   private final Set<Fqn> internalFqns = new HashSet<Fqn>();
 
    @Inject
    public void injectDependencies(Configuration configuration)
@@ -44,12 +48,28 @@
    }
 
    /**
-    * Set<Fqn> of Fqns of the topmost node of internal regions that should
-    * not included in standard state transfers.
+    * Retrieves the root node.
+    *
+    * @return the root node
     */
-   private final Set<Fqn> internalFqns = new HashSet<Fqn>();
+   public NodeSPI getRoot()
+   {
+      return root;
+   }
 
    /**
+    * Sets the root node reference to the node passed in.
+    *
+    * @param root node
+    */
+   public void setRoot(NodeSPI root)
+   {
+      if (root == null || !root.getFqn().isRoot())
+         throw new CacheException("Attempting to set an invalid node [" + root + "] as a root node!");
+      this.root = root;
+   }
+
+   /**
     * Adds the specified Fqn to the list of Fqns to be considered "internal".
     *
     * @param fqn fqn to add to list
@@ -59,28 +79,18 @@
       internalFqns.add(fqn);
    }
 
-
    /**
-    * Finds a node given a fully qualified name.
-    * Whenever nodes are created, and the global transaction is not null, the created
-    * nodes have to be added to the transaction's {@link org.jboss.cache.transaction.TransactionEntry}
-    * field.<br>
-    * When a lock is acquired on a node, a reference to the lock has to be
-    * {@link org.jboss.cache.transaction.TransactionEntry#addLock(org.jboss.cache.lock.NodeLock) added to the list of locked nodes}
-    * in the {@link org.jboss.cache.transaction.TransactionEntry}.
-    * <p>This operation will also apply different locking to the cache nodes, depending on
-    * <tt>operation_type</tt>. If it is <tt>read</tt> type, all nodes will be acquired with
-    * read lock. Otherwise, the operation is <tt>write</tt> type, all parent nodes will be acquired
-    * with read lock while the destination node acquires write lock.</p>
+    * Finds a node given a fully qualified name, directly off the interceptor chain.  In the event of an exception,
+    * returns null.  Does not include invalid or deleted nodes.
     *
     * @param fqn Fully qualified name for the corresponding node.
-    * @return DataNode
+    * @return Node referenced by the given Fqn, or null if the node cannot be found or if there is an exception.
     */
-   public NodeSPI findNode(Fqn fqn)
+   public NodeSPI peek(Fqn fqn)
    {
       try
       {
-         return findNode(fqn, null);
+         return peek(fqn, null);
       }
       catch (CacheException e)
       {
@@ -90,29 +100,35 @@
    }
 
    /**
-    * Finds a node given a fully qualified name and DataVersion.  Does not include invalid nodes.
+    * Finds a node given a fully qualified name and DataVersion.  Does not include invalid or deleted nodes.  If the data
+    * version passed in is null, then data version checking is skipped.  Data version checking is also skipped if optimistic
+    * locking is not used.
+    *
+    * @param fqn     fqn to find
+    * @param version version of the node to find
+    * @return a node, if found, or null if not.
     */
-   public NodeSPI findNode(Fqn fqn, DataVersion version)
+   public NodeSPI peek(Fqn fqn, DataVersion version)
    {
-      return findNode(fqn, version, false);
+      return peek(fqn, version, false);
    }
 
    /**
-    * Similar to {@link #findNode(Fqn, org.jboss.cache.optimistic.DataVersion)} except that it throws a {@link org.jboss.cache.NodeNotExistsException}
+    * Similar to {@link #peek(Fqn, org.jboss.cache.optimistic.DataVersion)} except that it throws a {@link org.jboss.cache.NodeNotExistsException}
     * if the node cannot be found.
     *
-    * @param tx             global transaction
-    * @param fqn            fqn to fine
+    * @param gtx            global transaction
+    * @param fqn            fqn to find
     * @param includeInvalid if true, invalid nodes are considered as well.
     * @return the node
     */
-   public NodeSPI findNodeCheck(GlobalTransaction tx, Fqn fqn, boolean includeInvalid)
+   public NodeSPI peekStrict(GlobalTransaction gtx, Fqn fqn, boolean includeInvalid)
    {
-      NodeSPI n = findNode(fqn, null, includeInvalid);
+      NodeSPI n = peek(fqn, null, includeInvalid);
       if (n == null)
       {
          StringBuilder builder = new StringBuilder();
-         builder.append("Node ").append(fqn).append(" not found (gtx=").append(tx).append(")");
+         builder.append("Node ").append(fqn).append(" not found (gtx=").append(gtx).append(")");
          String errStr = builder.toString();
          if (trace) log.trace(errStr);
          throw new NodeNotExistsException(errStr);
@@ -121,14 +137,16 @@
    }
 
    /**
-    * Searches for a specific node.
+    * Searches for a specific node, with a specific data version and, optionally, invalid nodes as well, but not
+    * deleted nodes.  If the data version passed in is null, then data version checking is skipped.  Data version
+    * checking is also skipped if optimistic locking is not used.
     *
     * @param fqn                 Fqn to find
     * @param version             version of the node to find
     * @param includeInvalidNodes if true, invalid nodes are considered
     * @return the node, if found, or null otherwise.
     */
-   public NodeSPI findNode(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
+   public NodeSPI peek(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
    {
       if (fqn == null) return null;
 
@@ -152,8 +170,21 @@
    }
 
    /**
-    * Peeks for a specified node.
+    * Same as calling <tt>peek(fqn, includeDeletedNodes, false)</tt>.
     *
+    * @param fqn                 Fqn to find
+    * @param includeDeletedNodes if true, deleted nodes are considered
+    * @return the node, if found, or null otherwise.
+    */
+   public NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes)
+   {
+      return peek(fqn, includeDeletedNodes, false);
+   }
+
+   /**
+    * Peeks for a specified node.  This involves a direct walk of the tree, starting at the root, until the required node
+    * is found.  If the node is not found, a null is returned.
+    *
     * @param fqn                 Fqn of the node to find
     * @param includeDeletedNodes if true, deleted nodes are also considered
     * @param includeInvalidNodes if true, invalid nodes are also considered
@@ -185,55 +216,46 @@
    }
 
    /**
-    * Prepares a list of {@link NodeData} objects for a specified node and all its children.
+    * Tests if an Fqn exists and is valid and not deleted.
     *
-    * @param list List of NodeData objects, which will be added to.
-    * @param node node to recursively add to the list
-    * @return the same list passed in
+    * @param fqn the fqn representing the node to test
+    * @return true if the node exists, false otherwise.
     */
-   public List<NodeData> getNodeData(List<NodeData> list, NodeSPI node)
+   public boolean exists(Fqn fqn)
    {
-      NodeData data = new NodeData(BuddyFqnTransformer.getActualFqn(node.getFqn()), node.getDataDirect());
-      list.add(data);
-      for (Object childNode : node.getChildrenDirect())
-      {
-         getNodeData(list, (NodeSPI) childNode);
-      }
-      return list;
+      return peek(fqn, false, false) != null;
    }
 
    /**
-    * Same as calling <tt>peek(fqn, includeDeletedNodes, false)</tt>.
+    * Returns true if the Fqn exists, is valid and is not deleted, and the node has children.
     *
-    * @param fqn                 Fqn to find
-    * @param includeDeletedNodes if true, deleted nodes are considered
-    * @return the node, if found, or null otherwise.
-    */
-   public NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes)
-   {
-      return peek(fqn, includeDeletedNodes, false);
-   }
-
-   /**
-    * Returns true if the Fqn exists and the node has children.
-    *
     * @param fqn the fqn to test
-    * @return true if the Fqn exists and the node has children.
+    * @return true if the Fqn exists, is valid and is not deleted, and the node has children.
     */
-   public boolean hasChild(Fqn fqn)
+   public boolean hasChildren(Fqn fqn)
    {
       if (fqn == null) return false;
 
-      NodeSPI n = findNode(fqn);
+      NodeSPI n = peek(fqn);
       return n != null && n.hasChildrenDirect();
    }
 
    /**
-    * @return the root node
+    * Prepares a list of {@link NodeData} objects for a specified node and all its children.
+    *
+    * @param list List of NodeData objects, which will be added to.
+    * @param node node to recursively add to the list
+    * @return the same list passed in
     */
-   public NodeSPI getRoot()
+   public List<NodeData> buildNodeData(List<NodeData> list, NodeSPI node)
    {
-      return root;
+      NodeData data = new NodeData(BuddyFqnTransformer.getActualFqn(node.getFqn()), node.getDataDirect());
+      list.add(data);
+      for (Object childNode : node.getChildrenDirect())
+      {
+         buildNodeData(list, (NodeSPI) childNode);
+      }
+      return list;
    }
 
    /**
@@ -300,17 +322,6 @@
    }
 
    /**
-    * Tests if an Fqn exists and is valid and not deleted.
-    *
-    * @param fqn the fqn representing the node to test
-    * @return true if the node exists, false otherwise.
-    */
-   public boolean exists(Fqn fqn)
-   {
-      return peek(fqn, false, false) != null;
-   }
-
-   /**
     * Returns a Set<Fqn> of Fqns of the topmost node of internal regions that
     * should not included in standard state transfers. Will include
     * {@link BuddyManager#BUDDY_BACKUP_SUBTREE} if buddy replication is
@@ -436,7 +447,7 @@
     */
    public int getNumberOfAttributes(Fqn fqn)
    {
-      return numAttributes(findNode(fqn));
+      return numAttributes(peek(fqn));
    }
 
    private int numAttributes(NodeSPI n)
@@ -468,7 +479,7 @@
     * @param skipMarkerCheck if true, skips checking the boolean {@link org.jboss.cache.NodeSPI#isDeleted()} flag and deletes the node anyway.
     * @return Returns true if the node was found and removed, false if not.
     */
-   public boolean realRemove(Fqn f, boolean skipMarkerCheck)
+   public boolean removeFromDataStructure(Fqn f, boolean skipMarkerCheck)
    {
       NodeSPI n = peek(f, true);
       if (n == null)
@@ -524,7 +535,7 @@
    public boolean evict(Fqn fqn)
    {
       if (peek(fqn, false, true) == null) return true;
-      if (hasChild(fqn))
+      if (hasChildren(fqn))
       {
          if (trace)
             log.trace("removing DATA as node has children: evict(" + fqn + ")");
@@ -542,7 +553,7 @@
 
    private void removeNode(Fqn fqn)
    {
-      NodeSPI targetNode = findNode(fqn, null, true);
+      NodeSPI targetNode = peek(fqn, null, true);
       if (targetNode == null) return;
       NodeSPI parentNode = targetNode.getParent();
       if (parentNode != null)
@@ -554,7 +565,7 @@
 
    protected void removeData(Fqn fqn)
    {
-      NodeSPI n = findNode(fqn, null);
+      NodeSPI n = peek(fqn, null);
       if (n == null)
       {
          log.warn("node " + fqn + " not found");
@@ -631,9 +642,4 @@
          n = childNode;
       }
    }
-
-   public void setRoot(NodeSPI root)
-   {
-      this.root = root;
-   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -101,7 +101,7 @@
     * Immutable root FQN.
     */
    @SuppressWarnings("unchecked")
-   public static final Fqn ROOT = new StringFqn();
+   public static final Fqn ROOT = new Fqn(true);
 
    /**
     * A cached string representation of this Fqn, used by toString to it isn't calculated again every time.
@@ -184,10 +184,7 @@
     */
    public static <E> Fqn<E> fromList(List<E> names)
    {
-      if (containsStrings(names))
-         return new StringFqn((List<String>) names);
-      else
-         return new Fqn<E>(true, names, false);
+      return new Fqn<E>(true, names, false);
    }
 
    /**
@@ -228,11 +225,7 @@
     */
    public static <E> Fqn<E> fromElements(E... elements)
    {
-      List el = Arrays.asList(elements);
-      if (containsStrings(el))
-         return new StringFqn(el);
-      else
-         return new Fqn<E>(true, el, true);
+      return new Fqn<E>(true, Arrays.asList(elements), true);
    }
 
    /**
@@ -258,10 +251,7 @@
     */
    public static Fqn<Object> fromRelativeFqn(Fqn<?> base, Fqn<?> relative)
    {
-      if (base.getClass().equals(StringFqn.class) && relative.getClass().equals(StringFqn.class))
-         return new StringFqn((StringFqn) base, (StringFqn) relative);
-      else
-         return new Fqn<Object>(true, base, relative.elements);
+      return new Fqn<Object>(true, base, relative.elements);
    }
 
    /**
@@ -287,10 +277,7 @@
     */
    public static Fqn<Object> fromRelativeList(Fqn<?> base, List<?> relativeElements)
    {
-      if (base.getClass().equals(StringFqn.class) && containsStrings(relativeElements))
-         return new StringFqn((StringFqn) base, (List<String>) relativeElements);
-      else
-         return new Fqn<Object>(true, base, relativeElements);
+      return new Fqn<Object>(true, base, relativeElements);
    }
 
    /**
@@ -316,22 +303,9 @@
     */
    public static Fqn<Object> fromRelativeElements(Fqn<?> base, Object... relativeElements)
    {
-      List rel = Arrays.asList(relativeElements);
-      if (base.getClass().equals(StringFqn.class) && containsStrings(rel))
-         return new StringFqn((StringFqn) base, rel);
-      else
-         return new Fqn<Object>(true, base, rel);
+      return new Fqn<Object>(true, base, Arrays.asList(relativeElements));
    }
 
-   protected static boolean containsStrings(List l)
-   {
-      for (Object o : l)
-      {
-         if (!(o instanceof String)) return false;
-      }
-      return true;
-   }
-
    /**
     * Returns a new Fqn from a string, where the elements are deliminated by
     * one or more separator ({@link #SEPARATOR}) characters.<br><br>
@@ -359,7 +333,8 @@
       {
          return ROOT;
       }
-      return new StringFqn(stringRepresentation);
+      List<String> elements = Arrays.asList(stringRepresentation.split("/"));
+      return new Fqn(true, elements, false);
    }
 
    /**
@@ -414,10 +389,7 @@
    public Fqn<E> getSubFqn(int startIndex, int endIndex)
    {
       List el = elements.subList(startIndex, endIndex);
-      if (containsStrings(el))
-         return new StringFqn(el);
-      else
-         return new Fqn<E>(true, el, true);
+      return new Fqn<E>(true, el, true);
    }
 
    /**
@@ -544,14 +516,6 @@
          E e = (E) in.readObject();
          elements.add(e);
       }
-
-      if (getClass().equals(StringFqn.class))
-      {
-         if (isRoot())
-            stringRepresentation = SEPARATOR;
-         else
-            stringRepresentation = getStringRepresentation(elements);
-      }
    }
 
 
@@ -612,11 +576,6 @@
     */
    protected int calculateHashCode()
    {
-      if (containsStrings(elements))
-      {
-         if (stringRepresentation == null) stringRepresentation = getStringRepresentation(elements);
-         return stringRepresentation.hashCode();
-      }
       int hashCode = 0;
       int count = 1;
       Object o;
@@ -637,7 +596,8 @@
       StringBuilder builder = new StringBuilder();
       for (Object e : elements)
       {
-         if (!e.equals(SEPARATOR) && !e.equals(""))
+         // incase user element 'e' does not implement equals() properly, don't rely on their implementation.
+         if (!SEPARATOR.equals(e) && !"".equals(e))
          {
             builder.append(SEPARATOR);
             builder.append(e);

Modified: core/trunk/src/main/java/org/jboss/cache/StringFqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/StringFqn.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/StringFqn.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -1,5 +1,7 @@
 package org.jboss.cache;
 
+import org.jboss.cache.annotations.Experimental;
+
 import java.util.Arrays;
 import java.util.List;
 
@@ -15,7 +17,8 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.2.0
  */
-// TODO: 2.2.0: Implement proper String escaping.
+// TODO: 3.0.0: Implement proper String escaping.
+ at Experimental
 public class StringFqn extends Fqn
 {
    // Needs to be public because of NodeData serialization.

Added: core/trunk/src/main/java/org/jboss/cache/annotations/Experimental.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/annotations/Experimental.java	                        (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/annotations/Experimental.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -0,0 +1,22 @@
+package org.jboss.cache.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A marker annotation to mark that a class, method or field is experimental and as such, should be used with extreme
+ * care as it may not be completely implemented, may not work at all, and/or may be prone to incompatible changes in
+ * future releases.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+ at Retention(RetentionPolicy.SOURCE)
+ at Target({ElementType.TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE,
+      ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER})
+public @interface Experimental
+{
+}

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetChildrenNamesCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -5,7 +5,11 @@
 import org.jboss.cache.NodeSPI;
 import org.jboss.cache.commands.Visitor;
 
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * This command retrieves the names of children for a specific Fqn, as defined by {@link org.jboss.cache.Node#getChildrenNames()}
@@ -37,7 +41,7 @@
     */
    public Object perform(InvocationContext ctx)
    {
-      NodeSPI n = dataContainer.findNode(fqn);
+      NodeSPI n = dataContainer.peek(fqn);
       if (n == null) return null;
       Set childNames = new HashSet();
       Map childrenMap = n.getChildrenMapDirect();

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetDataMapCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -37,7 +37,7 @@
     */
    public Object perform(InvocationContext ctx)
    {
-      NodeSPI n = dataContainer.findNode(fqn);
+      NodeSPI n = dataContainer.peek(fqn);
       if (n == null) return null;
       return Collections.unmodifiableMap(n.getDataDirect());
    }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeyValueCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -2,10 +2,10 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.DataContainer;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.NodeSPI;
-import org.jboss.cache.DataContainer;
 import org.jboss.cache.commands.Visitor;
 import org.jboss.cache.notifications.Notifier;
 
@@ -59,7 +59,7 @@
                append(sendNodeEvent).append("\")"));
       }
       if (sendNodeEvent) notifier.notifyNodeVisited(fqn, true, ctx);
-      NodeSPI n = dataContainer.findNode(fqn);
+      NodeSPI n = dataContainer.peek(fqn);
       if (n == null)
       {
          log.trace("node not found");

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetKeysCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -39,7 +39,7 @@
    @SuppressWarnings("unchecked")
    public Object perform(InvocationContext ctx)
    {
-      NodeSPI n = dataContainer.findNode(fqn);
+      NodeSPI n = dataContainer.peek(fqn);
       if (n == null) return null;
       Set keys = n.getKeysDirect();
       return new HashSet(keys);

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GetNodeCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -34,7 +34,7 @@
     */
    public Object perform(InvocationContext ctx)
    {
-      return dataContainer.findNode(fqn);
+      return dataContainer.peek(fqn);
    }
 
    public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable

Modified: core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/read/GravitateDataCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -2,7 +2,13 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.RPCManager;
 import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.buddyreplication.GravitateResult;
@@ -80,7 +86,7 @@
          if (actualNode == null && searchSubtrees)
          {
             log.trace("Looking at backup trees.");
-            NodeSPI backupSubtree = dataContainer.findNode(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
+            NodeSPI backupSubtree = dataContainer.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
             if (backupSubtree != null)
             {
                // need to loop through backupSubtree's children
@@ -112,7 +118,8 @@
                            // break out of the inner loop searching through the dead node's various backups
                            if (actualNode != null) break;
                         }
-                     } else
+                     }
+                     else
                      {
                         backupNodeFqn = Fqn.fromRelativeFqn(backupRoot, fqn);
                         // use a get() call into the cache to make sure cache loading takes place.
@@ -134,7 +141,8 @@
          if (actualNode == null)
          {
             return GravitateResult.noDataFound();
-         } else
+         }
+         else
          {
             // make sure we LOAD data for this node!!
             actualNode.getData();
@@ -145,7 +153,7 @@
             backupNodeFqn = BuddyFqnTransformer.getBackupFqn(BuddyFqnTransformer.getGroupNameFromAddress(rpcManager.getLocalAddress()), fqn);
          }
 
-         List<NodeData> list = dataContainer.getNodeData(new LinkedList<NodeData>(), (NodeSPI) actualNode);
+         List<NodeData> list = dataContainer.buildNodeData(new LinkedList<NodeData>(), (NodeSPI) actualNode);
 
          return GravitateResult.subtreeResult(list, backupNodeFqn);
       }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/CreateNodeCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -82,7 +82,7 @@
    {
       if (newlyCreated != null)
       {
-         for (Fqn f : newlyCreated) dataContainer.realRemove(f, true);
+         for (Fqn f : newlyCreated) dataContainer.removeFromDataStructure(f, true);
       }
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -140,7 +140,7 @@
    {
       // Find the node. This will lock it (if <tt>locking</tt> is true) and
       // add the temporarily created parent nodes to the TX's node list if tx != null)
-      NodeSPI n = dataContainer.findNode(fqn, dataVersion);
+      NodeSPI n = dataContainer.peek(fqn, dataVersion);
       if (n == null)
       {
          log.warn("node " + fqn + " not found");

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -2,7 +2,11 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
+import org.jboss.cache.DataContainer;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeNotExistsException;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.commands.ReversibleCommand;
 import org.jboss.cache.commands.Visitor;
 import org.jboss.cache.commands.read.AbstractDataCommand;
@@ -87,14 +91,14 @@
    private void move(Fqn nodeToMoveFqn, Fqn newParentFqn, boolean skipNotifications, InvocationContext ctx)
    {
       // the actual move algorithm.
-      NodeSPI newParent = dataContainer.findNode(newParentFqn);
+      NodeSPI newParent = dataContainer.peek(newParentFqn);
 
       if (newParent == null)
       {
          throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
       }
 
-      NodeSPI node = dataContainer.findNode(nodeToMoveFqn);
+      NodeSPI node = dataContainer.peek(nodeToMoveFqn);
 
       if (node == null)
       {

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/PutDataMapCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -61,7 +61,7 @@
       {
          log.trace("perform(" + globalTransaction + ", \"" + fqn + "\", " + data + " undo=" + createUndoOps + " erase=" + eraseContents + ")");
       }
-      NodeSPI nodeSPI = dataContainer.findNodeCheck(globalTransaction, fqn, false);
+      NodeSPI nodeSPI = dataContainer.peekStrict(globalTransaction, fqn, false);
       Map dataDirect = nodeSPI.getDataDirect();
       if (!dataDirect.isEmpty())
       {
@@ -80,7 +80,7 @@
    {
       if (trace) log.trace("rollback(" + globalTransaction + ", " + fqn + ", " + data + ")");
 
-      NodeSPI n = dataContainer.findNode(fqn, null, true);
+      NodeSPI n = dataContainer.peek(fqn, null, true);
       if (n != null)
       {
          n.clearDataDirect();
@@ -118,7 +118,8 @@
       if (isVersioned())
       {
          return eraseContents ? ERASE_VERSIONED_METHOD_ID : VERSIONED_METHOD_ID;
-      } else
+      }
+      else
       {
          return eraseContents ? ERASE_METHOD_ID : METHOD_ID;
       }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/PutKeyValueCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -68,7 +68,7 @@
       // if this is a rollback then don't fire notifications.
       boolean isRollback = false;
 
-      NodeSPI n = dataContainer.findNodeCheck(globalTransaction, fqn, isRollback);
+      NodeSPI n = dataContainer.peekStrict(globalTransaction, fqn, isRollback);
       Map rawData = n.getDataDirect();
       notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, rawData, ctx);
       oldValue = n.putDirect(key, value);
@@ -82,14 +82,14 @@
    {
       if (this.oldValue == null)
       {
-         NodeSPI n = dataContainer.findNode(fqn);
+         NodeSPI n = dataContainer.peek(fqn);
          if (n == null) throw new CacheException("node " + fqn + " not found for rollback!");
          n.removeDirect(key);
       }
       else
       {
          log.trace("Rolling back, setting the old value : " + oldValue);
-         NodeSPI n = dataContainer.findNodeCheck(globalTransaction, fqn, false);
+         NodeSPI n = dataContainer.peekStrict(globalTransaction, fqn, false);
          n.putDirect(key, oldValue);
       }
    }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveDataCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveDataCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -55,7 +55,7 @@
    public Object perform(InvocationContext ctx)
    {
       if (trace) log.trace("perform(" + globalTransaction + ", \"" + fqn + "\")");
-      NodeSPI targetNode = dataContainer.findNode(fqn, dataVersion);
+      NodeSPI targetNode = dataContainer.peek(fqn, dataVersion);
       if (targetNode == null)
       {
          log.warn("node " + fqn + " not found");
@@ -118,7 +118,7 @@
    {
       if (trace) log.trace("rollback(" + globalTransaction + ", \"" + fqn + "\", " + originalData + ")");
       boolean isRollback = true;
-      NodeSPI nodeSPI = dataContainer.findNodeCheck(globalTransaction, fqn, isRollback);
+      NodeSPI nodeSPI = dataContainer.peekStrict(globalTransaction, fqn, isRollback);
       nodeSPI.putAllDirect(originalData);
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveKeyCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -54,7 +54,7 @@
    {
       if (trace) log.trace("perform(" + globalTransaction + ", \"" + fqn + "\", key=" + key + ")");
 
-      NodeSPI n = dataContainer.findNode(fqn);
+      NodeSPI n = dataContainer.peek(fqn);
       if (n == null)
       {
          log.warn("node " + fqn + " not found");
@@ -71,7 +71,7 @@
 
    public void rollback()
    {
-      NodeSPI targetNode = dataContainer.findNodeCheck(globalTransaction, fqn, true);
+      NodeSPI targetNode = dataContainer.peekStrict(globalTransaction, fqn, true);
       targetNode.putDirect(key, oldValue);
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -59,7 +59,7 @@
          log.trace("perform(" + globalTransaction + ", \"" + fqn + "\", undo=" + createUndoOps + ")");
 
       // Find the node. This will add the temporarily created parent nodes to the TX's node list if globalTransaction != null)
-      targetNode = dataContainer.findNode(fqn, dataVersion, true);
+      targetNode = dataContainer.peek(fqn, dataVersion, true);
       if (targetNode == null)
       {
          if (trace) log.trace("node " + fqn + " not found");
@@ -149,7 +149,7 @@
             log.error("parent fqn or childName or childNode was null");
             return;
          }
-         NodeSPI parentNode = dataContainer.findNode(parentFqn);
+         NodeSPI parentNode = dataContainer.peek(parentFqn);
          if (parentNode == null)
          {
             log.warn("node " + parentFqn + " not found");

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -138,7 +138,7 @@
          GlobalTransaction gtx = ctx.getGlobalTransaction();
          TransactionEntry entry = txTable.get(gtx);
          if (entry == null) throw new IllegalStateException("cannot find transaction entry for " + gtx);
-         List<ReversibleCommand> modifications = new LinkedList<ReversibleCommand>(entry.getModifications());
+         List<ReversibleCommand> modifications = new LinkedList<ReversibleCommand>(command.getModifications());
          if (modifications.size() > 0)
          {
             broadcastInvalidate(modifications, gtx, tx, ctx);
@@ -162,7 +162,7 @@
          GlobalTransaction gtx = ctx.getGlobalTransaction();
          TransactionEntry entry = txTable.get(gtx);
          if (entry == null) throw new IllegalStateException("cannot find transaction entry for " + gtx);
-         List<ReversibleCommand> modifications = new LinkedList<ReversibleCommand>(entry.getModifications());
+         List<ReversibleCommand> modifications = new LinkedList<ReversibleCommand>(command.getModifications());
          if (modifications.size() > 0)
          {
             txMods.put(gtx, modifications);

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -195,7 +195,7 @@
       {
          // Map method calls to data versioned equivalents.
          // See JBCACHE-843 and docs/design/DataVersioning.txt
-         //TODO: 2.2.0: make the interceptor a field
+         //TODO: 2.2.0: make the visitor a field
          DataVersionPopulator populator = new DataVersionPopulator(getTransactionWorkspace(gtx));
          List<ReversibleCommand> clonedModifications = new ArrayList<ReversibleCommand>(command.getModifications().size());
          for (ReversibleCommand command1 : command.getModifications())

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -154,7 +154,7 @@
       {
          for (Fqn fqn : entry.getRemovedNodes())
          {
-            dataContainer.realRemove(fqn, false);
+            dataContainer.removeFromDataStructure(fqn, false);
          }
          // 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !
          entry.undoOperations();
@@ -236,8 +236,8 @@
       //TODO: 2.2.0: [mmarkus] this logic should be moved within moveNodeCommand, as it is plain removal logic
       if (ctx.getGlobalTransaction() == null)
       {
-         for (NodeSPI nodeSPI : createdNodes) dataContainer.realRemove(nodeSPI.getFqn(), true);
-         dataContainer.realRemove(command.getFqn(), true);
+         for (NodeSPI nodeSPI : createdNodes) dataContainer.removeFromDataStructure(nodeSPI.getFqn(), true);
+         dataContainer.removeFromDataStructure(command.getFqn(), true);
 
          //TODO: 2.2.0: end of the logic that needs to be moved
          NodeSPI n = dataContainer.peek(command.getFqn(), true, false);
@@ -320,7 +320,7 @@
       // first remove nodes that should be deleted.
       for (Fqn fqn : entry.getRemovedNodes())
       {
-         dataContainer.realRemove(fqn, false);
+         dataContainer.removeFromDataStructure(fqn, false);
       }
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/FqnTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/FqnTest.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/test/java/org/jboss/cache/FqnTest.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -476,45 +476,4 @@
          }
       }
    }
-
-   @Test(enabled = false)
-   // TODO: 2.2.0: enable once String escaping is in place
-   public void testUnescapedString()
-   {
-
-      Fqn f1 = Fqn.fromString("/a/b/c/d"); // an Fqn containing elements "a", "b", "c", "d".
-      Fqn f2 = Fqn.fromElements("a", "b", "c", "d");
-
-      assert f1.equals(f2);
-      assert f2.equals(f1);
-
-      Fqn f3 = Fqn.fromElements("a", "b/c", "d");
-
-      assert !f1.equals(f3);
-      assert !f2.equals(f3);
-      assert !f3.equals(f1);
-      assert !f3.equals(f2);
-
-      System.out.println("F1: " + f1);
-      System.out.println("F2: " + f2);
-      System.out.println("F3: " + f3);
-   }
-
-   @Test(enabled = false)
-   // TODO 2.2.0: enable once String escaping is in place
-   public void testEscapedString()
-   {
-      String str = "/a/b" + '\\' + "/c/d"; // should result in a Fqn with elements "a", "b/c", "d".
-      Fqn f = Fqn.fromString(str);
-
-      assert f.toString().equals(str) : str + " and " + f + " should be equal";
-
-      assert f.size() == 3;
-
-      assert f.get(0).equals("a");
-      assert f.get(1).equals("b/c");
-      assert f.get(2).equals("d");
-
-      assert !f.equals(Fqn.fromString("/a/b/c/d"));
-   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -404,7 +404,7 @@
    @Test(groups = {"functional"})
    public void testConcurrency() throws InterruptedException
    {
-      // TODO: 2.2.0: investigate intermittent failure when in optimistic mode.
+      // FIXME: investigate intermittent failure when in optimistic mode.
       if (optimistic) return;
 
       final int N = 3;// number of threads

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-05-01 13:35:17 UTC (rev 5787)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -36,7 +36,7 @@
    /*
       Test configuration options
     */
-   protected static final long DURATION = 10 * 60 * 1000; // 15 mins
+   protected static final long DURATION = 5 * 60 * 1000; // 15 mins
    protected static final int NUM_THREADS = 15;
    protected static final int MAX_RANDOM_SLEEP_MILLIS = 25;
    protected static final int MAX_DEPTH = 3;

Added: core/trunk/src/test/java/org/jboss/cache/profiling/StringPerformanceTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/StringPerformanceTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/StringPerformanceTest.java	2008-05-01 16:15:04 UTC (rev 5788)
@@ -0,0 +1,107 @@
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.Fqn;
+import org.testng.annotations.Test;
+
+/**
+ * A micro benchmark that measures the performance of using the old Fqn constructors versus the new Factory methods.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+ at Test(groups = "manual")
+public class StringPerformanceTest
+{
+   private static final int WARMUP = 200000;
+   private static final int LOOPS = 2000000;
+
+   public void testConstruction()
+   {
+      // perform a series of warmp constructions first
+      for (int i = 0; i < WARMUP; i++)
+      {
+         new Fqn("Hello", "World", "How", "Are", "You");
+         Fqn.fromElements("Hello", "World", "How", "Are", "You");
+//         Fqn.fromString("/Hello/World/How/Are/You");
+      }
+
+      // now do the actual microbench
+      long start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         new Fqn("Hello", "World", "How", "Are", "You");
+      }
+      long oldTime = System.currentTimeMillis() - start;
+
+      start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         Fqn.fromElements("Hello", "World", "How", "Are", "You");
+//         Fqn.fromString("/Hello/World/How/Are/You");
+      }
+      long newTime = System.currentTimeMillis() - start;
+
+      System.out.println("Old Constructors: " + oldTime + ", new factory: " + newTime);
+   }
+
+   public void testHashcode()
+   {
+      // perform a series of warmp constructions first
+      for (int i = 0; i < WARMUP; i++)
+      {
+         new Fqn("Hello", "World", "How", "Are", "You").hashCode();
+         Fqn.fromElements("Hello", "World", "How", "Are", "You").hashCode();
+      }
+
+      // now do the actual microbench
+      long start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         new Fqn("Hello", "World", "How", "Are", "You").hashCode();
+      }
+      long oldTime = System.currentTimeMillis() - start;
+
+      start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         Fqn.fromElements("Hello", "World", "How", "Are", "You").hashCode();
+      }
+      long newTime = System.currentTimeMillis() - start;
+
+      System.out.println("Old Constructors: " + oldTime + ", new factory: " + newTime);
+   }
+
+   public void testEquals()
+   {
+      // perform a series of warmp constructions first
+      for (int i = 0; i < WARMUP; i++)
+      {
+         Fqn f1 = new Fqn("Hello", "World", "How", "Are", "You");
+         Fqn f2 = Fqn.fromElements("Hello", "World", "How", "Are", "You");
+         f1.equals(f2);
+         f2.equals(f1);
+      }
+
+      Fqn compareTo = new Fqn("Hello", "World", "How", "Are", "You");
+      Fqn toTest = new Fqn("Hello", "World", "How", "Are", "You");
+      // now do the actual microbench
+      long start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         toTest.equals(compareTo);
+      }
+      long oldTime = System.currentTimeMillis() - start;
+
+      compareTo = Fqn.fromElements("Hello", "World", "How", "Are", "You");
+      toTest = Fqn.fromElements("Hello", "World", "How", "Are", "You");
+
+      start = System.currentTimeMillis();
+      for (int i = 0; i < LOOPS; i++)
+      {
+         toTest.equals(compareTo);
+      }
+      long newTime = System.currentTimeMillis() - start;
+
+      System.out.println("Old Constructors: " + oldTime + ", new factory: " + newTime);
+   }
+}




More information about the jbosscache-commits mailing list