Author: manik.surtani(a)jboss.com
Date: 2009-08-26 07:12:12 -0400 (Wed, 26 Aug 2009)
New Revision: 8206
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionRegistry.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 10:52:18
UTC (rev 8205)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2009-08-26 11:12:12
UTC (rev 8206)
@@ -222,12 +222,19 @@
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;
// first see if a region for this specific Fqn exists
- if (regionsRegistry.containsKey(fqnToUse))
+ Region r = regionsRegistry.get(fqnToUse);
+ if (r != null)
{
- Region r = regionsRegistry.get(fqnToUse);
-
// this is a very poor way of telling whether a region is a marshalling one or
an eviction one. :-(
// mandates that class loaders be registered for marshalling regions.
if (type == ANY
@@ -241,7 +248,7 @@
// if not, attempt to create one ...
if (createIfAbsent)
{
- Region r = new RegionImpl(fqnToUse, this);
+ r = new RegionImpl(fqnToUse, this);
// could be created concurrently; so make sure we use appropriate methods on
regionsRegistry for this.
Region previous = regionsRegistry.putIfAbsent(fqnToUse, r);
@@ -261,9 +268,9 @@
while (nextBestThing == null)
{
nextFqn = nextFqn.getParent();
- if (regionsRegistry.containsKey(nextFqn))
+ r = regionsRegistry.get(nextFqn);
+ if (r != null)
{
- Region r = regionsRegistry.get(nextFqn);
if (trace) log.trace("Trying next region " + nextFqn + " and
got " + r);
// this is a very poor way of telling whether a region is a marshalling one
or an eviction one. :-(
Modified: core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java 2009-08-26 10:52:18 UTC
(rev 8205)
+++ core/trunk/src/main/java/org/jboss/cache/RegionRegistry.java 2009-08-26 11:12:12 UTC
(rev 8206)
@@ -34,9 +34,23 @@
@NonVolatile
public class RegionRegistry extends ConcurrentHashMap<Fqn, Region>
{
+ private volatile int largestFqnLength;
+
public RegionRegistry()
{
// default CHM constructor. Potentially fine-tune later?
super();
}
+
+ @Override
+ public Region put(Fqn f, Region r)
+ {
+ largestFqnLength = Math.max(largestFqnLength, f.size());
+ return super.put(f, r);
+ }
+
+ public int getLargestFqnLength()
+ {
+ return largestFqnLength;
+ }
}
Show replies by date