Author: manik.surtani(a)jboss.com
Date: 2008-04-15 07:58:33 -0400 (Tue, 15 Apr 2008)
New Revision: 5568
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheData.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java
Log:
fixed a bunch of cache loader issues
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -495,12 +495,13 @@
return n;
}
-
+ @SuppressWarnings("unchecked")
private NodeSPI createNodes(Fqn fqn, TransactionEntry entry) throws Exception
{
- List<NodeSPI> createdNodes = cacheData.createNodes(fqn);
+ Object[] results = cacheData.createNodes(fqn);
+ List<NodeSPI> createdNodes = (List<NodeSPI>) results[0];
- // root node
+ NodeSPI lastCreated = null;
for (NodeSPI node : createdNodes)
{
node.setDataLoaded(false);
@@ -508,14 +509,14 @@
{
entry.loadUninitialisedNode(node.getFqn());
}
+ lastCreated = node;
}
- if (createdNodes.size() > 0)
- {
- NodeSPI last = createdNodes.get(createdNodes.size() - 1);
- last.setDataLoaded(true);
- return last;
- }
- return null;
+
+ // mark the leaf node as data loaded since that is what we are doing in this
interceptor.
+ if (lastCreated != null) lastCreated.setDataLoaded(true);
+
+ // regardless of whether the last node was created, return it.
+ return (NodeSPI) results[1];
}
private Map loadData(Fqn fqn) throws Exception
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -20,9 +20,11 @@
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.base.SkipCheckChainedInterceptor;
import org.jboss.cache.invocation.CacheData;
import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -55,6 +57,7 @@
private CacheLoader loader;
private Configuration configuration;
private CacheData cacheData;
+ private CacheLoaderManager loaderManager;
public CacheStoreInterceptor()
{
@@ -63,9 +66,10 @@
}
@Inject
- protected void init(CacheData cacheData, CacheLoader loader, TransactionManager
txManager, TransactionTable txTable, CacheLoaderConfig clConfig, Configuration
configuration)
+ protected void init(CacheData cacheData, CacheLoaderManager loaderManager,
TransactionManager txManager, TransactionTable txTable, CacheLoaderConfig clConfig,
Configuration configuration)
{
- this.loader = loader;
+ // never inject a CacheLoader at this stage - only a CacheLoaderManager, since the
CacheLoaderManager only creates a CacheLoader instance when it @Starts.
+ this.loaderManager = loaderManager;
this.loaderConfig = clConfig;
txMgr = txManager;
this.txTable = txTable;
@@ -73,6 +77,13 @@
this.cacheData = cacheData;
}
+ @Start
+ protected void start()
+ {
+ // this should only happen after the CacheLoaderManager has started, since the
CacheLoaderManager only creates the CacheLoader instance in it's @Start method.
+ loader = loaderManager.getCacheLoader();
+ }
+
/**
* if this is a shared cache loader and the call is of remote origin, pass up the
chain
*/
@@ -184,7 +195,7 @@
if (inTransaction())
{
if (trace) log.trace("transactional so don't put stuff in the cloader
yet.");
- prepareCacheLoader(command.getGlobalTransaction(),
ctx.getMethodCall().isOnePhaseCommitPrepareMehod());
+ prepareCacheLoader(command.getGlobalTransaction(), command.isOnePhaseCommit());
}
return invokeNextInterceptor(ctx, command);
}
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -37,7 +37,7 @@
* Used by the interceptor chain factory to inject dependencies.
*/
@Inject
- public void initialise(Configuration configuration, InvocationContextContainer
invocationContextContainer,
+ public void initialize(Configuration configuration, InvocationContextContainer
invocationContextContainer,
CacheLifecycleManager lifecycleManager, InterceptorChain
interceptorChain)
{
this.configuration = configuration;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheData.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheData.java 2008-04-15 02:09:13
UTC (rev 5567)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheData.java 2008-04-15 11:58:33
UTC (rev 5568)
@@ -214,7 +214,7 @@
private void buildNodesForEviction(Node node, List<Fqn> nodes)
{
- if (node != null && node.isResident())
+ if (node == null || node.isResident())
{
return;
}
@@ -223,7 +223,7 @@
{
for (Object childName : node.getChildrenNames())
{
- if (node != null && node.isResident())
nodes.add(Fqn.fromRelativeElements(fqn, childName));
+ if (!node.isResident()) nodes.add(Fqn.fromRelativeElements(fqn, childName));
}
}
else
@@ -489,9 +489,22 @@
n.setDataLoaded(false);
}
- public List<NodeSPI> createNodes(Fqn fqn)
+ /**
+ * Traverses the tree to the given Fqn, creating nodes if needed. Returns a list of
nodes created, as well as a reference to the last node.
+ * <p/>
+ * E.g.,
+ * <code>
+ * Object[] results = createNode(myFqn);
+ * results[0] // this is a List<NodeSPI> of nodes
<i>created</i> in getting to the target node.
+ * results[1] // is a NodeSPI reference to the target node, regardless of whether it
was <i>created</i> or just <i>found</i>.
+ * </code>
+ *
+ * @param fqn fqn to find
+ * @return see above.
+ */
+ public Object[] createNodes(Fqn fqn)
{
- List result = new ArrayList();
+ List<NodeSPI> result = new ArrayList<NodeSPI>(fqn.size());
Fqn tmpFqn = Fqn.ROOT;
int size = fqn.size();
@@ -505,24 +518,17 @@
NodeSPI childNode;
Map children = n.getChildrenMapDirect();
- if (children == null)
- {
- childNode = null;
- }
- else
- {
- childNode = (NodeSPI) children.get(childName);
- }
+ childNode = children == null ? null : (NodeSPI) children.get(childName);
if (childNode == null)
{
+ childNode = n.addChildDirect(Fqn.fromElements(childName));
+ result.add(childNode);
+ }
- result.add(n.addChildDirect(Fqn.fromElements(childName)));
-
- }
n = childNode;
}
- return result;
+ return new Object[]{result, n};
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -123,6 +123,7 @@
}
catch (Throwable t)
{
+// if (log.isTraceEnabled()) log.trace("InternalStart had problems: ",
t);
handleLifecycleTransitionFailure(t);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-04-15
02:09:13 UTC (rev 5567)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -59,14 +59,22 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheSPI<Object, Object>) new
DefaultCacheFactory().createCache(false);
- Configuration c = cache.getConfiguration();
- c.setCacheMode(Configuration.CacheMode.LOCAL);
- c.setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
- configureCache();
- cache.start();
- loader = cache.getCacheLoaderManager().getCacheLoader();
- postConfigure();
+ try
+ {
+ cache = (CacheSPI<Object, Object>) new
DefaultCacheFactory().createCache(false);
+ Configuration c = cache.getConfiguration();
+ c.setCacheMode(Configuration.CacheMode.LOCAL);
+ c.setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
+ configureCache();
+ cache.start();
+ loader = cache.getCacheLoaderManager().getCacheLoader();
+ postConfigure();
+ }
+ catch (Exception e)
+ {
+// e.printStackTrace();
+ throw e;
+ }
}
protected void postConfigure()
Modified: core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -6,6 +6,13 @@
*/
package org.jboss.cache.loader;
+import net.jcip.annotations.ThreadSafe;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -13,14 +20,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import net.jcip.annotations.ThreadSafe;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Modification;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-
/**
* Dummy cache loader that stores data in memory
*
@@ -36,12 +35,14 @@
protected boolean debug; // whether to dump System.out messages as well as log
messages or not
protected final Object NULL = new Object()
{
+ @Override
public String toString()
{
return "NULL placeholder";
}
};
protected IndividualCacheLoaderConfig config;
+
public void setConfig(IndividualCacheLoaderConfig config)
{
this.config = config;
@@ -253,21 +254,22 @@
this.fqn = fqn;
}
+ @Override
public String toString()
{
return "Node{" +
- "data=" + data +
- ", fqn=" + fqn +
- '}';
+ "data=" + data +
+ ", fqn=" + fqn +
+ '}';
}
}
-
+ @Override
public String toString()
{
return "DummyInMemoryCacheLoader{" +
- "getNodesMap()=" + getNodesMap() +
- '}';
+ "getNodesMap()=" + getNodesMap() +
+ '}';
}
protected void debugMessage(String msg)
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java 2008-04-15
02:09:13 UTC (rev 5567)
+++
core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java 2008-04-15
11:58:33 UTC (rev 5568)
@@ -4,13 +4,12 @@
import org.jboss.cache.config.CacheLoaderConfig;
import java.util.Map;
-import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
/**
* An extension of the {@link org.jboss.cache.loader.DummyInMemoryCacheLoader} that uses
static maps for data, children,
* etc. so it can be shared across instances, emulating a shared database or filesystem
cache loader.
- *
+ * <p/>
* Since 2.1.0, this dummy cache loader will take an optional parameter, "bin",
which contains the name of the "bin" to use
* in the static field to store the content. This allows for tests to mimic multiple
shared cache loaders in the same cache.
*
@@ -42,6 +41,7 @@
return BINS.get(bin);
}
+ @Override
public void wipe()
{
BINS.clear();