Author: manik.surtani(a)jboss.com
Date: 2007-10-01 09:13:24 -0400 (Mon, 01 Oct 2007)
New Revision: 4523
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
Log:
JBCACHE-910 - code repetition in CacheImpl.createSubtreeRootNode() could be replaced with
Node.addChild(Fqn)
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-01 12:26:52 UTC (rev
4522)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-01 13:13:24 UTC (rev
4523)
@@ -753,18 +753,18 @@
if (shouldFetchStateOnStartup())
{
try
- {
+ {
long start = System.currentTimeMillis();
- channel.connect(configuration.getClusterName(),null, null,
configuration.getStateRetrievalTimeout());
- if(!isCoordinator())
+ channel.connect(configuration.getClusterName(), null, null,
configuration.getStateRetrievalTimeout());
+ if (!isCoordinator())
{
ml.waitForState();
}
-
+
if (log.isDebugEnabled())
{
log.debug("connected, state was retrieved successfully (in
" + (System.currentTimeMillis() - start)
- + " milliseconds)");
+ + " milliseconds)");
}
}
catch (StateTransferException ste)
@@ -778,27 +778,28 @@
catch (ChannelException e)
{
throw new CacheException("Unable to connect to JGroups
channel", e);
- }
- catch (Exception ex){
- throw new CacheException("Unable to fetch state on startup",
ex);
}
+ catch (Exception ex)
+ {
+ throw new CacheException("Unable to fetch state on startup",
ex);
+ }
}
//otherwise just connect
else
{
try
{
- channel.connect(configuration.getClusterName());
+ channel.connect(configuration.getClusterName());
}
catch (ChannelException e)
{
- throw new CacheException("Unable to connect to JGroups
channel", e);
+ throw new CacheException("Unable to connect to JGroups
channel", e);
}
}
if (log.isInfoEnabled())
{
log.info("CacheImpl local address is " +
channel.getLocalAddress());
- }
+ }
if (buddyManager != null)
{
buddyManager.init(this);
@@ -818,7 +819,7 @@
if (cacheLoaderManager != null)
{
cacheLoaderManager.preloadCache();
- }
+ }
// start any eviction threads.
if (regionManager.isUsingEvictions())
@@ -1123,69 +1124,7 @@
}
}
- // ----------- Marshalling and State Transfer -----------------------
-
/**
- * Creates a subtree in the local cache.
- * Returns the DataNode created.
- */
- protected Node createSubtreeRootNode(Fqn<?> subtree) throws CacheException
- {
- NodeSPI<K, V> parent = root;
- NodeSPI<K, V> child = null;
- Object owner = getOwnerForLock();
- Object name;
- NodeFactory<K, V> factory =
configuration.getRuntimeConfig().getNodeFactory();
-
- for (int i = 0; i < subtree.size(); i++)
- {
- name = subtree.get(i);
- child = parent.getChildDirect(name);
- if (child == null)
- {
- // Lock the parent, create and add the child
- try
- {
- Option o = getInvocationContext().getOptionOverrides();
- parent.getLock().acquire(owner, o.getSyncReplTimeout() < 0 ?
configuration.getSyncReplTimeout() : o.getSyncReplTimeout(), NodeLock.LockType.WRITE);
- }
- catch (InterruptedException e)
- {
- log.error("Interrupted while locking" + parent.getFqn(), e);
- throw new CacheException(e.getLocalizedMessage(), e);
- }
-
- try
- {
- child = factory.createDataNode(name,
- subtree.getAncestor(i + 1),
- parent, null, true);
- parent.addChild(name, child);
- }
- finally
- {
- if (log.isDebugEnabled())
- {
- log.debug("forcing release of locks in " + parent.getFqn());
- }
- try
- {
- parent.getLock().releaseAll();
- }
- catch (Throwable t)
- {
- log.error("failed releasing locks", t);
- }
- }
- }
-
- parent = child;
- }
-
- return child;
- }
-
- /**
* Evicts the node at <code>subtree</code> along with all descendant
nodes.
*
* @param subtree Fqn indicating the uppermost node in the
@@ -2079,7 +2018,7 @@
if (channel.flushSupported())
{
- if (! flushBlockGate.await(configuration.getStateRetrievalTimeout()))
+ if (!flushBlockGate.await(configuration.getStateRetrievalTimeout()))
throw new TimeoutException("State retrieval timed out waiting for flush
unblock.");
}
rsps = rspFilter == null
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-10-01 12:26:52 UTC
(rev 4522)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-10-01 13:13:24 UTC
(rev 4523)
@@ -43,7 +43,7 @@
private Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn,
Region>();
private boolean defaultInactive;
private Log log = LogFactory.getLog(RegionManager.class);
- private CacheImpl<?,?> cache;
+ private CacheImpl<?, ?> cache;
private boolean usingEvictions;
private EvictionConfig evictionConfig;
private EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
@@ -147,8 +147,8 @@
// 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 == Region.Type.ANY
- || (type == Region.Type.MARSHALLING && r.getClassLoader() != null)
- || (type == Region.Type.EVICTION && r.getEvictionPolicyConfig() !=
null))
+ || (type == Region.Type.MARSHALLING && r.getClassLoader() !=
null)
+ || (type == Region.Type.EVICTION && r.getEvictionPolicyConfig()
!= null))
{
return r;
}
@@ -181,8 +181,8 @@
// 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 == Region.Type.ANY
- || (type == Region.Type.MARSHALLING && r.getClassLoader() !=
null)
- || (type == Region.Type.EVICTION && r.getEvictionPolicyConfig()
!= null))
+ || (type == Region.Type.MARSHALLING && r.getClassLoader() !=
null)
+ || (type == Region.Type.EVICTION &&
r.getEvictionPolicyConfig() != null))
{
nextBestThing = r;
}
@@ -193,7 +193,7 @@
// test if the default region has been defined. If not, and if eviction regions
// are in use, throw an exception since it is required.
if ((nextBestThing == null || nextBestThing.getFqn().isRoot() &&
!regionsRegistry.containsKey(Fqn.ROOT))
- && isUsingEvictions())
+ && isUsingEvictions())
{
throw new RuntimeException("No default eviction region defined!");
}
@@ -375,7 +375,8 @@
if (subtreeRoot == null)
{
// We'll update this node with the state we receive
- subtreeRoot = cache.createSubtreeRootNode(fqn);
+ // need to obtain all necessary locks.
+ subtreeRoot = cache.getRoot().addChild(fqn);
}
List<Address> members = cache.getMembers();
@@ -396,7 +397,8 @@
if (subtreeRoot == null)
{
// We'll update this node with the state we receive
- subtreeRoot = cache.createSubtreeRootNode(buddyRoot);
+ // need to obtain all necessary locks.
+ subtreeRoot = cache.getRoot().addChild(buddyRoot);
}
cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
}
@@ -429,7 +431,7 @@
else
{
throw new CacheException(t.getClass().getName() + " " +
- t.getLocalizedMessage(), t);
+ t.getLocalizedMessage(), t);
}
}
finally
@@ -715,7 +717,7 @@
for (Region r : regionsRegistry.values())
{
if ((type == Region.Type.EVICTION && r.getEvictionPolicy() != null
&& evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
- (type == Region.Type.MARSHALLING && r.isActive() &&
r.getClassLoader() != null))
+ (type == Region.Type.MARSHALLING && r.isActive() &&
r.getClassLoader() != null))
regions.add(r);
}
}
@@ -823,7 +825,7 @@
{
if (cache == null)
{
- return false;
+ return false;
}
NodeSPI theNode = cache.getRoot().getChildDirect(fqn);
return theNode == null ? false : theNode.isResidentDirect();