[jbosscache-dev] Cache.getRegion() implementation

Manik Surtani manik at jboss.org
Tue Oct 10 09:39:51 EDT 2006


Hi,

I see this in HEAD, in TreeCacheProxyImpl.getRegion():

  for(int i=0; i < fqn.size(); i++)
       {
          Fqn f = fqn.getFqnChild(i);
          if (treeCache.regionsRegistry.containsKey(f))
          {
             // first match is returned
             return treeCache.regionsRegistry.get(f);
          }
       }

What is the purpose of this?  If someone sets a region at Fqn.ROOT,  
no other regions will be recognised or created.  Is this the expected  
behaviour?

Do you perhaps mean to start with the leaf, and if a region exists,  
return it, if createIfAbsent is true, create it, else look higher up?

I.e.,

// first try and see if a region specific to the Fqn exists
if (treeCache.regionsRegistry.containsKey(fqn) return  
treeCache.regionsRegistry.get(fqn);

// else attempt to create one
if (createIfAbsent)
{
	Region r = new RegionImpl(treeCache, fqn);
	treeCache.regionsRegistry.put(fqn, r);
	return r;
}

// else look at parents, direct parents first.
Region r = null;
Fqn nextFqn = fqn;

while (r == null)
{
	Fqn nextFqn = nextFqn.getParent();
	r = treeCache.regionsRegistry.get(nextFqn);
	if (nextFqn.isRoot()) break;
}
return r;

--
Manik Surtani

Lead, JBoss Cache
JBoss, a division of Red Hat

Email: manik at jboss.org
Telephone: +44 7786 702 706
MSN: manik at surtani.org
Yahoo/AIM/Skype: maniksurtani





More information about the jbosscache-dev mailing list