[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Fri Aug 18 11:40:40 EDT 2006
User: msurtani
Date: 06/08/18 11:40:40
Modified: src/org/jboss/cache CacheSPI.java InvocationContext.java
TreeCache.java TreeCacheProxyImpl.java
Log:
Habanero stabilisation efforts - scoping problems with more than one cache instance in the same thread/namespace.
Revision Changes Path
1.9 +8 -0 JBossCache/src/org/jboss/cache/CacheSPI.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheSPI.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheSPI.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- CacheSPI.java 17 Aug 2006 17:34:59 -0000 1.8
+++ CacheSPI.java 18 Aug 2006 15:40:40 -0000 1.9
@@ -134,6 +134,14 @@
List _gravitateData(Fqn fqn, boolean b, boolean b1);
+ /**
+ * Retrieves the notifier attached with this instance of the cache. See {@link Notifier}, a class
+ * that is responsible for emitting notifications to registered {@link CacheListener}s.
+ */
Notifier getNotifier();
+ /**
+ * Retrieves the current invocation context for the current invocation.
+ */
+ InvocationContext getInvocationContext();
}
1.7 +19 -33 JBossCache/src/org/jboss/cache/InvocationContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InvocationContext.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/InvocationContext.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- InvocationContext.java 14 Aug 2006 17:20:35 -0000 1.6
+++ InvocationContext.java 18 Aug 2006 15:40:40 -0000 1.7
@@ -17,7 +17,6 @@
*/
public class InvocationContext
{
- private static ThreadLocal<InvocationContext> container = new ThreadLocal<InvocationContext>();
private Transaction transaction;
private GlobalTransaction globalTransaction;
private Option optionOverrides;
@@ -26,30 +25,7 @@
private boolean txHasMods;
private boolean localRollbackOnly;
- /**
- * @return the current invocation context associated with the current thread.
- */
- public static InvocationContext getCurrent()
- {
- InvocationContext i = container.get();
- if (i == null)
- {
- i = new InvocationContext();
- container.set(i);
- }
- return i;
- }
-
- /**
- * Associates the given invocation context with the current thread.
- * @param i
- */
- public static void setCurrent(InvocationContext i)
- {
- container.set(i);
- }
-
- private InvocationContext()
+ InvocationContext()
{
}
@@ -99,24 +75,22 @@
* Retrieves the option overrides associated with this invocation
* @return the option overrides associated with this invocation
*/
- public static Option getOptionOverrides()
+ public Option getOptionOverrides()
{
- Option o = getCurrent().optionOverrides;
- if (o == null)
+ if (optionOverrides == null)
{
- o = new Option();
- setOptionOverrides(o);
+ optionOverrides = new Option();
}
- return o;
+ return optionOverrides;
}
/**
* Sets the option overrides associated with this invocation
* @param optionOverrides
*/
- public static void setOptionOverrides(Option optionOverrides)
+ public void setOptionOverrides(Option optionOverrides)
{
- getCurrent().optionOverrides = optionOverrides;
+ this.optionOverrides = optionOverrides;
}
/**
@@ -164,4 +138,16 @@
{
return localRollbackOnly;
}
+
+ /**
+ * Resets this to the defaults used when constructing an invocation context object
+ */
+ public void reset()
+ {
+ transaction = null;
+ globalTransaction = null;
+ optionOverrides = null;
+ originLocal = true;
+ txHasMods = false;
+ }
}
1.219 +35 -21 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -b -r1.218 -r1.219
--- TreeCache.java 17 Aug 2006 21:57:58 -0000 1.218
+++ TreeCache.java 18 Aug 2006 15:40:40 -0000 1.219
@@ -74,7 +74,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.218 2006/08/17 21:57:58 msurtani Exp $
+ * @version $Id: TreeCache.java,v 1.219 2006/08/18 15:40:40 msurtani Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
@@ -244,6 +244,8 @@
private long stateFetchTimeout;
+ private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>();
+
/**
* Set of Fqns of nodes that are currently being processed by
* activateReqion or inactivateRegion. Requests for these fqns
@@ -539,13 +541,14 @@
protected void _createService() throws Exception
{
- notifier = new Notifier();
stateFetchTimeout = configuration.getLockAcquisitionTimeout() + 5000;
if (configuration.isNodeLockingOptimistic()) root = NodeFactory.getInstance().createRootDataNode(NodeFactory.NODE_TYPE_OPTIMISTIC_NODE, this);
// prepare an SPI interface to the root node
rootSpi = new TreeCacheProxyImpl(this, (NodeImpl) root);
+ notifier = new Notifier(getCacheSPI());
+
setUseReplQueue(configuration.isUseReplQueue());
setIsolationLevel(configuration.getIsolationLevel());
if (this.tm_lookup == null && configuration.getTransactionManagerLookupClass() != null)
@@ -1403,7 +1406,7 @@
finally
{
// Clear any invocation context from this thread
- InvocationContext.setCurrent(null);
+ getInvocationContext().reset();
}
}
}
@@ -1586,7 +1589,7 @@
*/
public DataNode get(Fqn fqn, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
@@ -1594,7 +1597,7 @@
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1609,14 +1612,14 @@
*/
public Object get(Fqn fqn, Object key, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
return get(fqn, key);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1626,14 +1629,14 @@
*/
public Object get(Fqn fqn, Object key, boolean sendNodeEvent, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
return get(fqn, key, sendNodeEvent);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1643,14 +1646,14 @@
*/
public void remove(Fqn fqn, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
remove(fqn);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1660,14 +1663,14 @@
*/
public Object remove(Fqn fqn, Object key, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
return remove(fqn, key);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1677,14 +1680,14 @@
*/
public Set getChildrenNames(Fqn fqn, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
return getChildrenNames(fqn);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1695,14 +1698,14 @@
*/
public void put(Fqn fqn, Map data, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
put(fqn, data);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -1712,14 +1715,14 @@
*/
public void put(Fqn fqn, Object key, Object value, Option option) throws CacheException
{
- InvocationContext.getCurrent().setOptionOverrides(option);
+ getInvocationContext().setOptionOverrides(option);
try
{
put(fqn, key, value);
}
finally
{
- InvocationContext.getCurrent().setOptionOverrides(null);
+ getInvocationContext().setOptionOverrides(null);
}
}
@@ -3189,7 +3192,7 @@
{
try
{
- InvocationContext.getCurrent().setOriginLocal(false);
+ getInvocationContext().setOriginLocal(false);
return invokeMethod(method_call);
}
catch (Exception ex)
@@ -3199,7 +3202,7 @@
}
finally
{
- InvocationContext.getCurrent().setOriginLocal(true);
+ getInvocationContext().setOriginLocal(true);
}
}
@@ -3557,6 +3560,17 @@
return notifier;
}
+ public InvocationContext getInvocationContext()
+ {
+ InvocationContext ctx = invocationContextContainer.get();
+ if (ctx == null)
+ {
+ ctx = new InvocationContext();
+ invocationContextContainer.set(ctx);
+ }
+ return ctx;
+ }
+
/*-------------------- MessageListener ----------------------*/
class MessageListenerAdaptor implements MessageListener
1.13 +14 -9 JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheProxyImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- TreeCacheProxyImpl.java 17 Aug 2006 17:34:59 -0000 1.12
+++ TreeCacheProxyImpl.java 18 Aug 2006 15:40:40 -0000 1.13
@@ -39,8 +39,8 @@
*/
public class TreeCacheProxyImpl implements CacheSPI, NodeSPI
{
- TreeCache treeCache;
- NodeImpl currentNode;
+ public TreeCache treeCache;
+ public NodeImpl currentNode;
Log log = LogFactory.getLog(TreeCacheProxyImpl.class);
public TreeCacheProxyImpl(TreeCache treeCache, NodeImpl currentNode)
@@ -300,11 +300,11 @@
public Node addChild(Fqn f)
{
- if (InvocationContext.getOptionOverrides().isBypassInterceptorChain())
+ if (treeCache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
{
TreeCacheProxyImpl retval = null;
NodeImpl newNode;
- GlobalTransaction gtx = InvocationContext.getCurrent().getGlobalTransaction();
+ GlobalTransaction gtx = treeCache.getInvocationContext().getGlobalTransaction();
if (f.size() == 1)
{
@@ -326,7 +326,7 @@
retval = new TreeCacheProxyImpl(treeCache, currentParent);
}
- InvocationContext.getOptionOverrides().setBypassInterceptorChain(false);
+ treeCache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
return retval;
}
else
@@ -344,10 +344,10 @@
public Node getChild(Fqn f)
{
NodeImpl child = null;
- if (InvocationContext.getOptionOverrides().isBypassInterceptorChain())
+ if (treeCache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
{
if (currentNode.getChildren() != null) child = (NodeImpl) currentNode.getChildren().get(f.getLast());
- InvocationContext.getOptionOverrides().setBypassInterceptorChain(false);
+ treeCache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
}
else
{
@@ -358,10 +358,10 @@
public void put(Object k, Object v)
{
- if (InvocationContext.getOptionOverrides().isBypassInterceptorChain())
+ if (treeCache.getInvocationContext().getOptionOverrides().isBypassInterceptorChain())
{
currentNode.put(k, v);
- InvocationContext.getOptionOverrides().setBypassInterceptorChain(false);
+ treeCache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(false);
}
else
{
@@ -504,6 +504,11 @@
return treeCache.getNotifier();
}
+ public InvocationContext getInvocationContext()
+ {
+ return treeCache.getInvocationContext();
+ }
+
public GlobalTransaction getCurrentTransaction(Transaction tx)
{
return treeCache.getCurrentTransaction(tx);
More information about the jboss-cvs-commits
mailing list