[jbosscache-commits] JBoss Cache SVN: r8208 - in core/trunk/src: test/java/org/jboss/cache/eviction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Aug 26 09:15:46 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-08-26 09:15:46 -0400 (Wed, 26 Aug 2009)
New Revision: 8208

Modified:
   core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
   core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java
   core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
Log:
[JBCACHE-1536]  (Improve efficiency of RegionManagerImpl.getRegion)

Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java	2009-08-26 12:01:23 UTC (rev 8207)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java	2009-08-26 13:15:46 UTC (rev 8208)
@@ -221,18 +221,10 @@
       }
 
       if (trace) log.trace("Contents of RegionsRegistry: " + regionsRegistry);
-      Fqn fqnToUse = fqn;
 
-      if (fqnToUse != null)
-      {
-         // Truncate Fqn as an optimization
-         int largestFqnLength = regionsRegistry.getLargestFqnLength();
-         if (fqnToUse.size() > largestFqnLength) fqnToUse = fqnToUse.getSubFqn(0, largestFqnLength);
-      }
-
-      if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;
+      if (DEFAULT_REGION.equals(fqn)) fqn = Fqn.ROOT;
       // first see if a region for this specific Fqn exists
-      Region r = regionsRegistry.get(fqnToUse);
+      Region r = regionsRegistry.get(fqn);
       if (r != null)
       {
          // this is a very poor way of telling whether a region is a marshalling one or an eviction one.  :-(
@@ -248,10 +240,10 @@
       // if not, attempt to create one ...
       if (createIfAbsent)
       {
-         r = new RegionImpl(fqnToUse, this);
+         r = new RegionImpl(fqn, this);
 
          // could be created concurrently; so make sure we use appropriate methods on regionsRegistry for this.
-         Region previous = regionsRegistry.putIfAbsent(fqnToUse, r);
+         Region previous = regionsRegistry.putIfAbsent(fqn, r);
          if (previous != null) r = previous;
          if (type == MARSHALLING)
          {
@@ -263,11 +255,16 @@
 
       // else try and find a parent which has a defined region, may return null if nothing is defined.
       Region nextBestThing = null;
-      Fqn nextFqn = fqnToUse;
+      if (fqn == null || fqn.isRoot()) return null;
+      Fqn nextFqn = fqn;
 
+      // Truncate Fqn as an optimization
+      int largestFqnLength = regionsRegistry.getLargestFqnLength();
+      if (nextFqn.size() > largestFqnLength) nextFqn = nextFqn.getSubFqn(0, largestFqnLength);
+
+
       while (nextBestThing == null)
       {
-         nextFqn = nextFqn.getParent();
          r = regionsRegistry.get(nextFqn);
          if (r != null)
          {
@@ -283,6 +280,7 @@
             }
          }
          if (nextFqn.isRoot()) break;
+         nextFqn = nextFqn.getParent();
       }
 
       // test if the default region has been defined.  If not, and if the request

Modified: core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java	2009-08-26 12:01:23 UTC (rev 8207)
+++ core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java	2009-08-26 13:15:46 UTC (rev 8208)
@@ -49,6 +49,30 @@
       return super.put(f, r);
    }
 
+   @Override
+   public Region putIfAbsent(Fqn f, Region r)
+   {
+      Region rV = super.putIfAbsent(f, r);
+      if (rV == null) largestFqnLength = Math.max(largestFqnLength, f.size());
+      return rV;
+   }
+
+   @Override
+   public Region replace(Fqn f, Region r)
+   {
+      Region rV = super.replace(f, r);
+      if (rV != null) largestFqnLength = Math.max(largestFqnLength, f.size());
+      return rV;
+   }
+
+   @Override
+   public boolean replace(Fqn f, Region oldR, Region newR)
+   {
+      boolean rV = super.replace(f, oldR, newR);
+      if (rV) largestFqnLength = Math.max(largestFqnLength, f.size());
+      return rV;
+   }
+
    public int getLargestFqnLength()
    {
       return largestFqnLength;

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java	2009-08-26 12:01:23 UTC (rev 8207)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/RegionManagerTest.java	2009-08-26 13:15:46 UTC (rev 8208)
@@ -32,7 +32,8 @@
    public void testCreateRegion()
    {
       RegionManager regionManager = new RegionManagerImpl();
-      ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null, null, new RegionRegistry());
+      RegionRegistry rr = new RegionRegistry();
+      ((RegionManagerImpl) regionManager).injectDependencies(null, null, null, null, null, rr);
       regionManager.setUsingEvictions(true);
       regionManager.getRegion(DEFAULT_REGION, true).setEvictionRegionConfig(config);
       regionManager.getRegion(A_B_C, true).setEvictionRegionConfig(config);
@@ -40,6 +41,7 @@
       regionManager.getRegion(AOP, true).setEvictionRegionConfig(config);
 
       List<Region> regions = regionManager.getAllRegions(Region.Type.ANY);
+      System.out.println("RegionRegistry: " + rr);
       assertEquals("Region size ", 4, regions.size());
    }
 



More information about the jbosscache-commits mailing list