JBoss Cache SVN: r5663 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 09:59:14 -0400 (Thu, 24 Apr 2008)
New Revision: 5663
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
Log:
Updated calls to broken getMethodCall()
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-24 13:54:41 UTC (rev 5662)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-24 13:59:14 UTC (rev 5663)
@@ -361,6 +361,7 @@
/**
* @return the method call associated with this invocation
*/
+ @Deprecated
public MethodCall getMethodCall()
{
if (methodCall == null)
@@ -384,8 +385,9 @@
* Sets the method call associated with this invocation.
*
* @param methodCall methodcall to set
- * @deprecated not used anymore, use {@link #getExecutingCommand()}
+ * @deprecated not used anymore. Interceptors will get a {@link org.jboss.cache.commands.CacheCommand} instance passed in along with an InvocationContext.
*/
+ @Deprecated
public void setMethodCall(MethodCall methodCall)
{
this.methodCall = methodCall;
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-24 13:54:41 UTC (rev 5662)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-04-24 13:59:14 UTC (rev 5663)
@@ -17,7 +17,6 @@
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.LockManager;
import org.jboss.cache.lock.NodeLock;
-import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
@@ -86,7 +85,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, true, false, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, true, false, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -96,7 +95,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, useCacheStore, !useCacheStore, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, useCacheStore, !useCacheStore, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -108,9 +107,9 @@
{
if (command.getTo() != null)
{
- loadIfNeeded(ctx, command.getTo(), null, false, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, true, false);
+ loadIfNeeded(ctx, command.getTo(), null, false, false, true, txTable.get(ctx.getGlobalTransaction()), false, true, false);
}
- loadIfNeeded(ctx, command.getFqn(), null, false, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), true, true, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, true, txTable.get(ctx.getGlobalTransaction()), true, true, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -120,7 +119,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, true, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -131,7 +130,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, !usingOptimisticInvalidation);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, true, txTable.get(ctx.getGlobalTransaction()), false, false, !usingOptimisticInvalidation);
}
return invokeNextInterceptor(ctx, command);
}
@@ -142,7 +141,7 @@
Fqn fqn = command.getFqn();
if (fqn != null)
{
- loadIfNeeded(ctx, fqn, null, false, false, false, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, true);
+ loadIfNeeded(ctx, fqn, null, false, false, false, txTable.get(ctx.getGlobalTransaction()), false, false, true);
NodeSPI n = cacheData.peek(fqn, true, true);
loadChildren(fqn, n, false, false, ctx);
}
@@ -155,7 +154,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, true, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, true, false, true, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -165,7 +164,7 @@
{
if (command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, true, false, true, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, true, false, true, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -202,7 +201,7 @@
{
if (config.isNodeLockingOptimistic() && command.getFqn() != null)
{
- loadIfNeeded(ctx, command.getFqn(), null, false, false, false, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), null, false, false, false, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -212,7 +211,7 @@
{
if (command.getFqn() != null && !useCacheStore)
{
- loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, false, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, command.getFqn(), command.getKey(), false, false, false, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
@@ -223,12 +222,12 @@
Fqn fqn = command.getFqn();
if (fqn != null && !useCacheStore)
{
- loadIfNeeded(ctx, fqn, null, false, true, false, ctx.getMethodCall(), txTable.get(ctx.getGlobalTransaction()), false, false, false);
+ loadIfNeeded(ctx, fqn, null, false, true, false, txTable.get(ctx.getGlobalTransaction()), false, false, false);
}
return invokeNextInterceptor(ctx, command);
}
- private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys, boolean initNode, boolean acquireLock, MethodCall m, TransactionEntry entry, boolean recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
+ private void loadIfNeeded(InvocationContext ctx, Fqn fqn, Object key, boolean allKeys, boolean initNode, boolean acquireLock, TransactionEntry entry, boolean recursive, boolean isMove, boolean bypassLoadingData) throws Throwable
{
NodeSPI n = cacheData.peek(fqn, true, true);
16 years, 2 months
JBoss Cache SVN: r5662 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 09:54:41 -0400 (Thu, 24 Apr 2008)
New Revision: 5662
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java
Log:
Added async cleanup delay
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java 2008-04-24 12:20:44 UTC (rev 5661)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithTransactionsTest.java 2008-04-24 13:54:41 UTC (rev 5662)
@@ -7,6 +7,7 @@
package org.jboss.cache.buddyreplication;
import org.jboss.cache.Fqn;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
@@ -49,6 +50,7 @@
txman.begin();
dumpCacheContents(caches);
+ // will cause gravitation
caches.get(2).get(fqn, key);
dumpCacheContents(caches);
@@ -63,6 +65,7 @@
assertTrue(!caches.get(2).exists(newBackupFqn));
txman.commit();
+ cleanupDelay(); // cleanup commands are async
dumpCacheContents(caches);
@@ -81,6 +84,11 @@
assertNoLocks(caches);
}
+ private void cleanupDelay()
+ {
+ TestingUtil.sleepThread(250);
+ }
+
public void testTransactionsRollback() throws Exception
{
caches = createCaches(3, false, true, false);
16 years, 2 months
JBoss Cache SVN: r5661 - in core/trunk/src: test/java/org/jboss/cache/replicated and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 08:20:44 -0400 (Thu, 24 Apr 2008)
New Revision: 5661
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
Log:
Fixed proper cleanup after a rollback
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-24 12:05:19 UTC (rev 5660)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-24 12:20:44 UTC (rev 5661)
@@ -215,6 +215,9 @@
if (ltx == null)
{
log.warn("No local transaction for this remotely originating rollback. Possibly rolling back before a prepare call was broadcast?");
+ txTable.remove(gtx);
+ scrubOnExist(ctx, true);
+ return null;
}
// disconnect if we have a current tx associated
Transaction currentTx = txManager.getTransaction();
@@ -251,7 +254,6 @@
}
catch (Throwable throwable)
{
- boolean result;
ctx.throwIfNeeded(throwable);
}
finally
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2008-04-24 12:05:19 UTC (rev 5660)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2008-04-24 12:20:44 UTC (rev 5661)
@@ -334,8 +334,8 @@
public void testSyncReplWithModficationsOnBothCachesWithRollback() throws Exception
{
TransactionManager tm;
- final Fqn NODE1 = Fqn.fromString("/one/two/three");
- final Fqn NODE2 = Fqn.fromString("/eins/zwei/drei");
+ final Fqn fqn1 = Fqn.fromString("/one/two/three");
+ final Fqn fqn2 = Fqn.fromString("/eins/zwei/drei");
initCaches(Configuration.CacheMode.REPL_SYNC);
@@ -343,8 +343,8 @@
cache2.getConfiguration().setSyncRollbackPhase(true);
tm = beginTransaction();
- cache1.put(NODE1, "age", 38);
- cache2.put(NODE2, "age", 39);
+ cache1.put(fqn1, "age", 38);
+ cache2.put(fqn2, "age", 39);
System.out.println("cache1 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache1));
System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
16 years, 2 months
JBoss Cache SVN: r5660 - in core/trunk/src/test/java/org/jboss/cache: transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 08:05:19 -0400 (Thu, 24 Apr 2008)
New Revision: 5660
Modified:
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
core/trunk/src/test/java/org/jboss/cache/transaction/PrepareCommitContentionTest.java
Log:
Added test
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-24 11:10:33 UTC (rev 5659)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2008-04-24 12:05:19 UTC (rev 5660)
@@ -20,6 +20,7 @@
import org.jboss.cache.invocation.InterceptorChain;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
+import org.jgroups.JChannel;
import java.io.File;
import java.lang.reflect.Field;
@@ -559,4 +560,30 @@
{
return (CommandsFactory) extractField(cache, "commandsFactory");
}
+
+ public static String getJGroupsAttribute(Cache cache, String protocol, String attribute)
+ {
+ String s = ((JChannel) ((CacheSPI) cache).getRPCManager().getChannel()).getProperties();
+ String[] protocols = s.split(":");
+ String attribs = null;
+ for (String p : protocols)
+ {
+ boolean hasAttribs = p.contains("(");
+ String name = hasAttribs ? p.substring(0, p.indexOf('(')) : p;
+ attribs = hasAttribs ? p.substring(p.indexOf('(') + 1, p.length() - 1) : null;
+
+ if (name.equalsIgnoreCase(protocol)) break;
+ }
+
+ if (attribs != null)
+ {
+ String[] attrArray = attribs.split(";");
+ for (String a : attrArray)
+ {
+ String[] kvPairs = a.split("=");
+ if (kvPairs[0].equalsIgnoreCase(attribute)) return kvPairs[1];
+ }
+ }
+ return null;
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/PrepareCommitContentionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/PrepareCommitContentionTest.java 2008-04-24 11:10:33 UTC (rev 5659)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/PrepareCommitContentionTest.java 2008-04-24 12:05:19 UTC (rev 5660)
@@ -4,24 +4,24 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.RPCManager;
-import org.jboss.cache.RPCManagerImpl;
import org.jboss.cache.commands.CacheCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.config.Configuration;
+import static org.jboss.cache.config.Configuration.CacheMode.REPL_SYNC;
import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.misc.TestingUtil;
import org.jgroups.Address;
+import org.jgroups.Channel;
import org.jgroups.blocks.RspFilter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import javax.transaction.TransactionManager;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
+import java.util.Map;
/**
* This is to test the scenario described in http://jira.jboss.org/jira/browse/JBCACHE-1270
@@ -40,186 +40,118 @@
@Test(groups = "functional")
public class PrepareCommitContentionTest
{
- CacheSPI<Object, Object> c1, c2;
+ CacheSPI<Object, Object> c1;
@BeforeMethod
public void setUp() throws CloneNotSupportedException
{
- c1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
- c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- c1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- c1.getConfiguration().setLockAcquisitionTimeout(5000);
- c2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(c1.getConfiguration().clone(), false);
+ c1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(REPL_SYNC));
}
@AfterMethod
public void tearDown()
{
- TestingUtil.killCaches(c1, c2);
+ TestingUtil.killCaches(c1);
}
- public void testWithSyncCommitPhase() throws Exception
+ public void testOOBFlag() throws Exception
{
- doTest(true, false);
- }
+ DelegatingRPCManager delegatingRPCManager = new DelegatingRPCManager();
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(c1);
+ RPCManager origRpcManager = cr.getComponent(RPCManager.class);
+ delegatingRPCManager.delegate = origRpcManager;
+ cr.registerComponent(delegatingRPCManager, RPCManager.class);
- public void testWithDefautCommitPhase() throws Exception
- {
- doTest(false, false);
+ c1.getTransactionManager().begin();
+ c1.put("/a", "k", "v");
+ c1.getTransactionManager().commit();
+
+ // now check what we have gathered:
+
+ assert delegatingRPCManager.log.get(CommitCommand.class) : "Commit commands should be sent using OOB!";
+ assert !delegatingRPCManager.log.get(PrepareCommand.class) : "Prepare commands should NOT be sent using OOB!";
}
- public void testControl() throws Exception
+ private static class DelegatingRPCManager implements RPCManager
{
- try
+ RPCManager delegate;
+ Map<Class<? extends CacheCommand>, Boolean> log = new HashMap<Class<? extends CacheCommand>, Boolean>();
+
+ public void disconnect()
{
- doTest(false, true);
- assert false : "Should fail if we don't use out of band messages for non-sync commits";
+ delegate.disconnect();
}
- catch (AssertionError expected)
+
+ public void stop()
{
- // should fail
+ delegate.stop();
}
- }
- private void doTest(final boolean syncCommit, boolean noOutOfBandMessages) throws Exception
- {
- c1.getConfiguration().setSyncCommitPhase(syncCommit);
- c2.getConfiguration().setSyncCommitPhase(syncCommit);
+ public void start()
+ {
+ delegate.start();
+ }
- final CountDownLatch mainThreadCommitLatch = new CountDownLatch(1);
- final CountDownLatch secondThreadPrepareLatch = new CountDownLatch(1);
- final Fqn fqn = Fqn.fromString("/a/b/c");
-
- DelayingRPCManager delayingRPCManager = new DelayingRPCManager(mainThreadCommitLatch, secondThreadPrepareLatch, syncCommit, noOutOfBandMessages);
- ComponentRegistry cr = TestingUtil.extractComponentRegistry(c1);
- cr.registerComponent(RPCManager.class.getName(), delayingRPCManager, RPCManager.class);
-
- c1.start();
- c2.start();
-
- TestingUtil.blockUntilViewsReceived(60000, c1, c2);
-
- TransactionManager tm = c1.getTransactionManager();
-
- Thread secondTransaction = new Thread("SecondThread")
+ void logCall(CacheCommand command, boolean oob)
{
- public void run()
+ if (command instanceof ReplicateCommand)
{
- // wait until thread1 finishes the prepare.
- try
- {
- secondThreadPrepareLatch.await();
- }
- catch (InterruptedException e)
- {
- // do nothing
- }
-
- try
- {
- // now replicate a put on the SAME node so there is lock contention
- TransactionManager tm = c1.getTransactionManager();
- if (syncCommit)
- mainThreadCommitLatch.countDown(); // we need to release the main thread commit latch first otherwise it will deadlock!
-
- tm.begin();
- c1.put(fqn, "k", "v2");
- tm.commit();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ CacheCommand cmd = ((ReplicateCommand) command).getSingleModification();
+ log.put(cmd.getClass(), oob);
}
- };
- secondTransaction.start();
+ }
+ public List<Object> callRemoteMethods(List<Address> recipients, CacheCommand cacheCommand, int mode, boolean excludeSelf, long timeout, RspFilter responseFilter, boolean useOutOfBandMessage) throws Exception
+ {
+ logCall(cacheCommand, useOutOfBandMessage);
+ return delegate.callRemoteMethods(recipients, cacheCommand, mode, excludeSelf, timeout, responseFilter, useOutOfBandMessage);
+ }
- tm.begin();
- c1.put(fqn, "k", "v");
- tm.commit();
+ public List<Object> callRemoteMethods(List<Address> recipients, CacheCommand cacheCommand, int mode, boolean excludeSelf, long timeout, boolean useOutOfBandMessage) throws Exception
+ {
+ logCall(cacheCommand, useOutOfBandMessage);
+ return delegate.callRemoteMethods(recipients, cacheCommand, mode, excludeSelf, timeout, useOutOfBandMessage);
+ }
- secondTransaction.join();
+ public List<Object> callRemoteMethods(List<Address> recipients, CacheCommand command, boolean synchronous, boolean excludeSelf, int timeout, boolean useOutOfBandMessage) throws Exception
+ {
+ logCall(command, useOutOfBandMessage);
+ return delegate.callRemoteMethods(recipients, command, synchronous, excludeSelf, timeout, useOutOfBandMessage);
+ }
- // now assert that both transactions have succeeded
- assert c1.get(fqn, "k").equals("v2");
- assert c2.get(fqn, "k").equals("v2");
- }
+ public boolean isCoordinator()
+ {
+ return delegate.isCoordinator();
+ }
- public static class DelayingRPCManager extends RPCManagerImpl
- {
- CountDownLatch mainThreadLatch, secondThreadLatch;
- boolean syncCommit;
- boolean noOOBMessages = false;
+ public Address getCoordinator()
+ {
+ return delegate.getCoordinator();
+ }
- public DelayingRPCManager(CountDownLatch latch1, CountDownLatch latch2, boolean syncCommit, boolean noOOBMessages)
+ public Address getLocalAddress()
{
- mainThreadLatch = latch1;
- secondThreadLatch = latch2;
- this.syncCommit = syncCommit;
- this.noOOBMessages = noOOBMessages;
+ return delegate.getLocalAddress();
}
- @Override
- public List<Object> callRemoteMethods(final List<Address> recipients, final CacheCommand command, final int mode, final boolean excludeSelf, final long timeout, final RspFilter responseFilter, final boolean oob) throws Exception
+ public List<Address> getMembers()
{
- if (isPrepareMethod(command) && Thread.currentThread().getName().equals("SecondThread"))
- {
- if (!syncCommit) mainThreadLatch.countDown();
- }
- else if (isCommitMethod(command) && !Thread.currentThread().getName().equals("SecondThread"))
- {
- Thread th = new Thread()
- {
- public void run()
- {
- try
- {
- secondThreadLatch.countDown(); // let the secondTransaction start it's prepapre
- mainThreadLatch.await(); // and block arbitrarily until the secondTransaction informs us to proceed
- Thread.sleep(1000);
- DelayingRPCManager.super.callRemoteMethods(recipients, command, mode, excludeSelf, timeout, responseFilter, !noOOBMessages && oob);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- };
- th.start();
- if (syncCommit) th.join();
+ return delegate.getMembers();
+ }
- return Collections.emptyList();
- }
- return super.callRemoteMethods(recipients, command, mode, excludeSelf, timeout, responseFilter, !noOOBMessages && oob);
+ public void fetchPartialState(List<Address> sources, Fqn sourceTarget, Fqn integrationTarget) throws Exception
+ {
+ delegate.fetchPartialState(sources, sourceTarget, integrationTarget);
}
- private boolean isCommitMethod(CacheCommand call)
+ public void fetchPartialState(List<Address> sources, Fqn subtree) throws Exception
{
- if (call instanceof CommitCommand) return true;
- if (call instanceof ReplicateCommand)
- {
- ReplicateCommand rCom = (ReplicateCommand) call;
- if (rCom.isSingleCommand())
- {
- return rCom.getSingleModification() instanceof CommitCommand;
- }
- }
- return false;
+ delegate.fetchPartialState(sources, subtree);
}
- private boolean isPrepareMethod(CacheCommand call)
+ public Channel getChannel()
{
- if (call instanceof PrepareCommand) return true;
- if (call instanceof ReplicateCommand)
- {
- ReplicateCommand rCom = (ReplicateCommand) call;
- if (rCom.isSingleCommand())
- {
- return rCom.getSingleModification() instanceof PrepareCommand;
- }
- }
- return false;
+ return delegate.getChannel();
}
}
}
16 years, 2 months
JBoss Cache SVN: r5659 - in core/trunk/src: test/java/org/jboss/cache/transaction and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 07:10:33 -0400 (Thu, 24 Apr 2008)
New Revision: 5659
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/cachedata/RemoveNodeCommand.java
core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
Log:
Fixed rollbacks
Modified: core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java 2008-04-24 10:44:47 UTC (rev 5658)
+++ core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java 2008-04-24 11:10:33 UTC (rev 5659)
@@ -13,6 +13,7 @@
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -62,7 +63,11 @@
log.trace("perform(" + globalTransaction + ", \"" + fqn + "\", " + data + " undo=" + createUndoOps + " erase=" + eraseContents + ")");
}
NodeSPI nodeSPI = cacheData.findNodeCheck(globalTransaction, fqn, false);
- oldData = nodeSPI.getDataDirect();
+ Map dataDirect = nodeSPI.getDataDirect();
+ if (!dataDirect.isEmpty())
+ {
+ oldData = new HashMap(dataDirect); // defensive copy
+ }
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, oldData, ctx);
if (eraseContents) nodeSPI.clearDataDirect();
@@ -74,13 +79,14 @@
public void rollback()
{
- if (trace)
+ if (trace) log.trace("rollback(" + globalTransaction + ", " + fqn + ", " + data + ")");
+
+ NodeSPI n = cacheData.findNode(fqn, null, true);
+ if (n != null)
{
- log.trace("rollback(" + globalTransaction + ", \"" + fqn + "\", " + data + ")");
+ n.clearDataDirect();
+ if (oldData != null) n.putAllDirect(oldData);
}
- NodeSPI n = cacheData.findNodeCheck(globalTransaction, fqn, true);
- n.clearDataDirect();
- n.putAllDirect(oldData);
}
public Object accept(InvocationContext ctx, CommandsVisitor handler) throws Throwable
Modified: core/trunk/src/main/java/org/jboss/cache/commands/cachedata/RemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/cachedata/RemoveNodeCommand.java 2008-04-24 10:44:47 UTC (rev 5658)
+++ core/trunk/src/main/java/org/jboss/cache/commands/cachedata/RemoveNodeCommand.java 2008-04-24 11:10:33 UTC (rev 5659)
@@ -14,6 +14,9 @@
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Implements functionality defined by {@link org.jboss.cache.CacheSPI#removeNode(org.jboss.cache.Fqn)}
*
@@ -36,6 +39,7 @@
private boolean eviction;
private Fqn parentFqn;
private NodeSPI targetNode;
+ private Map originalData;
public RemoveNodeCommand()
{
@@ -99,6 +103,11 @@
if (globalTransaction != null && createUndoOps && !eviction && found)
{
parentFqn = parentNode.getFqn();
+ Map targetData = targetNode.getDataDirect();
+ if (!targetData.isEmpty())
+ {
+ originalData = new HashMap(targetNode.getDataDirect());
+ }
}
notifyAfterEviction(ctx);
@@ -137,26 +146,31 @@
public void rollback()
{
- String childName = (String) targetNode.getFqn().getLastElement();
- if (trace)
+ if (targetNode != null)
{
- log.trace("rollback(\"" + parentFqn + "\", \"" + childName + "\", node=" + targetNode + ")");
- }
+ Object childName = targetNode.getFqn().getLastElement();
+ if (trace)
+ {
+ log.trace("rollback(parent: " + parentFqn + ", child: " + childName + ", node=" + targetNode + ")");
+ }
- if (parentFqn == null || childName == null || targetNode == null)
- {
- log.error("parent_fqn or childName or childNode was null");
- return;
+ if (parentFqn == null || childName == null)
+ {
+ log.error("parent fqn or childName or childNode was null");
+ return;
+ }
+ NodeSPI parentNode = cacheData.findNode(parentFqn);
+ if (parentNode == null)
+ {
+ log.warn("node " + parentFqn + " not found");
+ return;
+ }
+ parentNode.addChild(childName, targetNode);
+ targetNode.markAsDeleted(false, true);
+ targetNode.clearDataDirect();
+ if (originalData != null) targetNode.putAllDirect(originalData);
+ targetNode.setValid(true, true);
}
- NodeSPI parentNode = cacheData.findNode(parentFqn);
- if (parentNode == null)
- {
- log.warn("node " + parentFqn + " not found");
- return;
- }
- parentNode.addChild(childName, targetNode);
- targetNode.markAsDeleted(false, true);
- targetNode.setValid(true, true);
}
public Object accept(InvocationContext ctx, CommandsVisitor handler) throws Throwable
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-04-24 10:44:47 UTC (rev 5658)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-04-24 11:10:33 UTC (rev 5659)
@@ -17,6 +17,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.util.CachePrinter;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -709,26 +710,18 @@
}
}
- public void testDoubleRemovalOfSameData()
+ public void testDoubleRemovalOfSameData() throws Exception
{
- try
- {
- tx.begin();
- cache.put("/foo/1", "item", 1);
- assertEquals(cache.get("/foo/1", "item"), 1);
- cache.removeNode("/foo/1");
- assertNull(cache.get("/foo/1", "item"));
- cache.removeNode("/foo/1");
- assertNull(cache.get("/foo/1", "item"));
- tx.rollback();
- assertFalse(cache.exists("/foo/1"));
- assertNull(cache.get("/foo/1", "item"));
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- fail(t.toString());
- }
+ tx.begin();
+ cache.put("/foo/1", "item", 1);
+ assertEquals(cache.get("/foo/1", "item"), 1);
+ cache.removeNode("/foo/1");
+ assertNull(cache.get("/foo/1", "item"));
+ cache.removeNode("/foo/1");
+ assertNull(cache.get("/foo/1", "item"));
+ tx.rollback();
+ assertFalse(cache.exists("/foo/1"));
+ assertNull(cache.get("/foo/1", "item"));
}
/**
@@ -761,7 +754,7 @@
/**
* put(Fqn, Map) with a previous non-null map
*/
- public void testputDataRollback2()
+ public void testputDataRollback2() throws Exception
{
Map<String, Comparable> m1, m2;
m1 = new HashMap<String, Comparable>();
@@ -771,29 +764,21 @@
m2.put("other", "bla");
m2.put("name", "Michelle");
- try
- {
- cache.put("/bela/ban", m1);
- tx.begin();
+ cache.put("/bela/ban", m1);
+ tx.begin();
- cache.put("/bela/ban", m2);
- Map tmp = cache.getNode("/bela/ban").getData();
- assertEquals(3, tmp.size());
- assertEquals("Michelle", tmp.get("name"));
- assertEquals(tmp.get("id"), 322649);
- assertEquals("bla", tmp.get("other"));
- tx.rollback();
+ cache.put("/bela/ban", m2);
+ Map tmp = cache.getNode("/bela/ban").getData();
+ assertEquals(3, tmp.size());
+ assertEquals("Michelle", tmp.get("name"));
+ assertEquals(tmp.get("id"), 322649);
+ assertEquals("bla", tmp.get("other"));
+ tx.rollback();
- tmp = cache.getNode("/bela/ban").getData();
- assertEquals(2, tmp.size());
- assertEquals("Bela", tmp.get("name"));
- assertEquals(tmp.get("id"), 322649);
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- fail(t.toString());
- }
+ tmp = cache.getNode("/bela/ban").getData();
+ assertEquals(2, tmp.size());
+ assertEquals("Bela", tmp.get("name"));
+ assertEquals(tmp.get("id"), 322649);
}
public void testPutRollback()
@@ -834,22 +819,25 @@
public void testSimpleRollbackTransactions() throws Exception
{
- final Fqn<String> FQN = Fqn.fromString("/a/b/c");
+ final Fqn<String> fqn = Fqn.fromString("/a/b/c");
tx.begin();
- cache.put(FQN, "entry", "commit");
+ cache.put(fqn, "entry", "commit");
tx.commit();
tx.begin();
- cache.put(FQN, "entry", "rollback");
- cache.removeNode(FQN);
+ cache.put(fqn, "entry", "rollback");
+ cache.removeNode(fqn);
tx.rollback();
- assertEquals("Node should keep the commited value", "commit", cache.getNode(FQN).get("entry"));
+ assertEquals("Node should keep the commited value", "commit", cache.getNode(fqn).get("entry"));
tx.begin();
- cache.removeNode(FQN);
- cache.put(FQN, "entry", "rollback");
+ cache.removeNode(fqn);
+ cache.put(fqn, "entry", "rollback");
tx.rollback();
- assertEquals("Node should keep the commited value", "commit", cache.getNode(FQN).get("entry"));// THIS FAILS
+
+ System.out.println("Cache: " + CachePrinter.printCacheDetails(cache));
+
+ assertEquals("Node should keep the commited value", "commit", cache.getNode(fqn).get("entry"));// THIS FAILS
}
private TransactionManager startTransaction() throws Exception
16 years, 2 months
JBoss Cache SVN: r5658 - core/trunk/src/main/java/org/jboss/cache/transaction.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 06:44:47 -0400 (Thu, 24 Apr 2008)
New Revision: 5658
Modified:
core/trunk/src/main/java/org/jboss/cache/transaction/TxUtil.java
Log:
Added todo
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TxUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TxUtil.java 2008-04-24 10:38:05 UTC (rev 5657)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TxUtil.java 2008-04-24 10:44:47 UTC (rev 5658)
@@ -1,16 +1,17 @@
package org.jboss.cache.transaction;
+import org.jboss.cache.CacheException;
import org.jboss.cache.InvocationContext;
-import org.jboss.cache.CacheException;
-import javax.transaction.Transaction;
import javax.transaction.Status;
import javax.transaction.SystemException;
+import javax.transaction.Transaction;
/**
* @author Mircea.Markus(a)jboss.com
* @since 2.2
*/
+// TODO: Can this stuff be moved into CacheTransactionHelper ?
public class TxUtil
{
/**
16 years, 2 months
JBoss Cache SVN: r5657 - in core/trunk/src/main/java/org/jboss/cache: commands/tx and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-04-24 06:38:05 -0400 (Thu, 24 Apr 2008)
New Revision: 5657
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/tx/BaseGlobalTransactionCommand.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
Log:
Fixed stuff
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -200,7 +200,7 @@
public String toString()
{
return "ReplicateCommand{" +
- "modifications=" + (isSingleCommand() ? singleModification : modifications) +
+ "cmds=" + (isSingleCommand() ? singleModification : modifications) +
'}';
}
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/commands/tx/BaseGlobalTransactionCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/tx/BaseGlobalTransactionCommand.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/commands/tx/BaseGlobalTransactionCommand.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -69,7 +69,7 @@
public String toString()
{
return getClass().getSimpleName() + "{" +
- "globalTransaction=" + globalTransaction +
+ "gtx=" + globalTransaction +
'}';
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -168,17 +168,17 @@
}
/**
- * It does not make sense replicating a transaction method(commit, rollback, prepare) if one of the following:
+ * It does not make sense replicating a transaction method(commit, rollback, prepare) if one of the following is true:
* <pre>
* - call was not initiated here, but on other member of the cluster
- * - there is no transaction. Why calling a commit if no transaction going on?
- * - the current transaction did not modufy any data, so other members are not aware of it
+ * - there is no transaction. Why broadcast a commit or rollback if there is no transaction going on?
+ * - the current transaction did not modify any data
* </pre>
*/
protected boolean skipReplicationOfTransactionMethod(InvocationContext ctx)
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
- return gtx == null || gtx.isRemote() || ctx.getOptionOverrides().isCacheModeLocal();
+ return ctx.getTransaction() == null || gtx == null || gtx.isRemote() || ctx.getOptionOverrides().isCacheModeLocal() || !ctx.isTxHasMods();
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -6,6 +6,7 @@
import org.jboss.cache.commands.cachedata.PutDataMapCommand;
import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
import org.jboss.cache.commands.cachedata.RemoveDataCommand;
+import org.jboss.cache.commands.cachedata.RemoveKeyCommand;
import org.jboss.cache.commands.cachedata.RemoveNodeCommand;
import org.jboss.cache.commands.functional.TxCacheCommand;
import org.jboss.cache.commands.tx.CommitCommand;
@@ -137,6 +138,12 @@
}
@Override
+ public Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ return handleAlterCacheMethod(ctx, command);
+ }
+
+ @Override
public Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
{
return handleAlterCacheMethod(ctx, command);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -12,6 +12,7 @@
import org.jboss.cache.ReplicationException;
import org.jboss.cache.commands.CacheCommand;
import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.cachedata.CreateNodeCommand;
import org.jboss.cache.commands.cachedata.InvalidateCommand;
import org.jboss.cache.commands.channel.BlockChannelCommand;
import org.jboss.cache.commands.channel.UnblockChannelCommand;
@@ -41,7 +42,9 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -846,13 +849,32 @@
}
/**
+ * An optimisation of commands to be broadcast in a prepare call, which involves removing of unnecessary commands
+ * as well as the "aggregation" of commands that can be aggregated.
+ *
+ * @param mods list of modifications
+ * @return compacted list of modifications
+ */
+ private List<TxCacheCommand> compact(List<TxCacheCommand> mods)
+ {
+ // TODO: Make this more sophisticated, so it aggregates multiple puts on the same node, puts followed by a remove, etc.
+ // for now this just removes the redundant CreateNodeCommands from the list.
+ List<TxCacheCommand> newList = new LinkedList<TxCacheCommand>();
+ for (TxCacheCommand cmd : mods)
+ {
+ if (!(cmd instanceof CreateNodeCommand)) newList.add(cmd);
+ }
+ return newList;
+ }
+
+ /**
* Handles a local prepare - invoked by the sync handler. Tests if the current tx matches the gtx passed in to the
* method call and passes the prepare() call up the chain.
*
* @return
* @throws Throwable
*/
- public Object runPreparePhase(InvocationContext ctx, GlobalTransaction gtx, List modifications) throws Throwable
+ public Object runPreparePhase(InvocationContext ctx, GlobalTransaction gtx, List<TxCacheCommand> modifications) throws Throwable
{
// build the method call
CacheCommand prepareCommand;
@@ -888,6 +910,8 @@
if (txManager.getTransaction() != null && ltx != null && txManager.getTransaction().equals(ltx))
{
ctx.setExecutingCommand(prepareCommand);
+ // set the hasMods flag in the invocation ctx. This should not be replicated, just used locally by the interceptors.
+ ctx.setTxHasMods(modifications != null && modifications.size() > 0);
result = invokeNextInterceptor(ctx, prepareCommand);
}
else
@@ -1029,12 +1053,10 @@
{
Transaction tx = null;
GlobalTransaction gtx = null;
- // CacheSPI cache = null;
- List modifications = null;
+ List<TxCacheCommand> modifications = null;
TransactionEntry entry = null;
protected InvocationContext ctx; // the context for this call.
-
RemoteSynchronizationHandler(GlobalTransaction gtx, Transaction tx)
{
this.gtx = gtx;
@@ -1099,7 +1121,8 @@
// set any transaction wide options as current for this thread.
if (entry != null)
{
- modifications = entry.getModifications();
+ // this should ideally be set in beforeCompletion(), after compacting the list.
+ if (modifications == null) modifications = entry.getModifications();
cacheLoaderModifications = entry.getCacheLoaderModifications();
ctx.setOptionOverrides(entry.getOption());
}
@@ -1208,9 +1231,10 @@
// fetch the modifications before the transaction is committed
// (and thus removed from the txTable)
setTransactionalContext(tx, gtx, ctx);
- if (!entry.existModifications())
+ if (!entry.hasModifications())
{
if (trace) log.trace("No modifications in this tx. Skipping beforeCompletion()");
+ modifications = Collections.emptyList();
return;
}
@@ -1227,6 +1251,7 @@
case Status.STATUS_ACTIVE:
case Status.STATUS_PREPARING:
// run a prepare call.
+ modifications = compact(modifications);
Object result = runPreparePhase(ctx, gtx, modifications);
if (result instanceof Throwable)
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-24 10:36:20 UTC (rev 5656)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2008-04-24 10:38:05 UTC (rev 5657)
@@ -390,7 +390,7 @@
/**
* Returns true if modifications were registered to either modificationList or to class loader modifications list.
*/
- public boolean existModifications()
+ public boolean hasModifications()
{
return !modificationList.isEmpty() || !classLoadeModList.isEmpty();
}
16 years, 2 months
JBoss Cache SVN: r5656 - in core/trunk/src: test/java/org/jboss/cache/factories and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-04-24 06:36:20 -0400 (Thu, 24 Apr 2008)
New Revision: 5656
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
Log:
JBCACHE-1222 - fixed interceptor chain tests
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java 2008-04-24 10:22:15 UTC (rev 5655)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java 2008-04-24 10:36:20 UTC (rev 5656)
@@ -50,7 +50,7 @@
/**
* Inserts the given interceptor at the specified position in the chain (o based indexing).
- * If the position is invalid (e.g. 5 and there are only 2 interceptors in the chain) this is a no-op.
+ * @throws IllegalArgumentException if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)
*/
public synchronized void addInterceptor(ChainedInterceptor interceptor, int position)
{
@@ -72,13 +72,13 @@
return;
}
it = it.getNext();
-
}
+ throw new IllegalArgumentException("Invalid index: " + index + " !");
}
/**
* Removes the interceptor at the given postion.
- * If the position is invalid (e.g. 5 and there are only 2 interceptors in the chain) this is a no-op.
+ * @throws IllegalArgumentException if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)
*/
public synchronized void removeInterceptor(int position)
{
@@ -96,9 +96,11 @@
{
if (it.getNext() == null) return; //nothing to remove
it.setNext(it.getNext().getNext());
+ return;
}
it = it.getNext();
}
+ throw new IllegalArgumentException("Invalid position: " + position + " !");
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java 2008-04-24 10:22:15 UTC (rev 5655)
+++ core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java 2008-04-24 10:36:20 UTC (rev 5656)
@@ -111,7 +111,7 @@
cache.addInterceptor(x, 9);
fail("Should throw an exception");
}
- catch (IndexOutOfBoundsException e)
+ catch (IllegalArgumentException e)
{
// expected
}
@@ -176,7 +176,7 @@
cache.removeInterceptor(9);
fail("Should throw an exception");
}
- catch (IndexOutOfBoundsException e)
+ catch (IllegalArgumentException e)
{
// expected
}
16 years, 2 months
JBoss Cache SVN: r5655 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-04-24 06:22:15 -0400 (Thu, 24 Apr 2008)
New Revision: 5655
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
Log:
JBCACHE-1222 - fixed invocation context tests
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-24 09:41:31 UTC (rev 5654)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-04-24 10:22:15 UTC (rev 5655)
@@ -9,6 +9,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.commands.CacheCommand;
+import org.jboss.cache.commands.functional.MarshallableCommand;
import org.jboss.cache.config.Option;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
@@ -38,6 +39,7 @@
private boolean cacheLoaderHasMods;
private boolean localRollbackOnly;
private MethodCall methodCall;
+ @Deprecated
private CacheCommand executingCommand;
// used to store cache peeks within the scope of a single context. Performing a cache peek can be a huge bottle neck.
@@ -361,9 +363,23 @@
*/
public MethodCall getMethodCall()
{
+ if (methodCall == null)
+ {
+ methodCall = createMethodCall((MarshallableCommand) getExecutingCommand());
+ }
return methodCall;
}
+ @SuppressWarnings("deprecated")
+ private MethodCall createMethodCall(MarshallableCommand command)
+ {
+ MethodCall call = new MethodCall();
+ call.setMethodId(command.getCommandId());
+ call.setArgs(command.getParameters());
+ return call;
+ }
+
+
/**
* Sets the method call associated with this invocation.
*
@@ -402,11 +418,21 @@
return timeout;
}
+ /**
+ * This is only used for backward compatibility with old interceptors implementation and should <b>NOT</b> be
+ * use by any new custom interceptors. The commands is now passed in as the second param in each implementing
+ * handlers (handler = method in ChainedInterceptor class)
+ */
+ @Deprecated
public void setExecutingCommand(CacheCommand cacheCommand)
{
this.executingCommand = cacheCommand;
}
+ /**
+ * @see #setExecutingCommand(org.jboss.cache.commands.CacheCommand)
+ */
+ @Deprecated
public CacheCommand getExecutingCommand()
{
return executingCommand;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-04-24 09:41:31 UTC (rev 5654)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-04-24 10:22:15 UTC (rev 5655)
@@ -142,24 +142,6 @@
public NodeSPI peekNode(InvocationContext ctx, Fqn f, boolean forceRefresh, boolean includeDeletedNodes, boolean includeInvalidNodes)
{
return cache.peek(f, includeDeletedNodes, includeInvalidNodes);
-
- // Disabling this for now, until we can prove that it is in fact beneficial.
- // preliminary profiling tests show that it is not.
-
-// NodeSPI n;
-// if (forceRefresh || (n = ctx.getPeekedNode(f)) == null)
-// {
-// n = cache.peek(f, true, true);
-// // put this in the invocation cache
-// ctx.savePeekedNode(n, f);
-// }
-//
-// if (n != null)
-// {
-// if (!includeDeletedNodes && n.isDeleted()) return null;
-// if (!includeInvalidNodes && !n.isValid()) return null;
-// }
-// return n;
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java 2008-04-24 09:41:31 UTC (rev 5654)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java 2008-04-24 10:22:15 UTC (rev 5655)
@@ -5,10 +5,8 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.commands.CacheCommand;
-import org.jboss.cache.commands.functional.MarshallableCommand;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.base.ChainedInterceptor;
-import org.jboss.cache.marshall.MethodCall;
import java.util.ArrayList;
import java.util.Collections;
@@ -234,8 +232,6 @@
public Object invoke(InvocationContext ctx, CacheCommand command)
{
ctx.setExecutingCommand(command);
- // ensure legacy MethodCall is available for interceptor implementations.
- ctx.setMethodCall(createMethodCall((MarshallableCommand) command));
try
{
return command.accept(ctx, firstInChain);
@@ -254,15 +250,6 @@
}
}
- @SuppressWarnings("deprecated")
- private MethodCall createMethodCall(MarshallableCommand command)
- {
- MethodCall call = new MethodCall();
- call.setMethodId(command.getCommandId());
- call.setArgs(command.getParameters());
- return call;
- }
-
/**
* Similar to {@link #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.CacheCommand)}, but
* constructs a invocation context on the fly, using {@link InvocationContextContainer#get()}
Modified: core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-24 09:41:31 UTC (rev 5654)
+++ core/trunk/src/test/java/org/jboss/cache/invocationcontext/TransactionTest.java 2008-04-24 10:22:15 UTC (rev 5655)
@@ -128,7 +128,6 @@
assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
- assertEquals("MethodCall should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
}
private void setUpOnePhaseCache()
16 years, 2 months
JBoss Cache SVN: r5654 - in core/trunk/src: test/java/org/jboss/cache/jmx and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-04-24 05:41:31 -0400 (Thu, 24 Apr 2008)
New Revision: 5654
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java
Log:
JBCACHE-1222 - fixed JMX config
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-04-24 09:20:40 UTC (rev 5653)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-04-24 09:41:31 UTC (rev 5654)
@@ -35,17 +35,19 @@
private ChainedInterceptor createInterceptor(Class<? extends ChainedInterceptor> clazz) throws IllegalAccessException, InstantiationException
{
- ChainedInterceptor i = componentRegistry.getComponent(clazz.getName(), clazz);
- if (i == null)
+ //todo - no reason for the individual interceptors to be registered as components, all manipulation should be done through InterceptorChain
+ ChainedInterceptor chainedInterceptor = componentRegistry.getComponent(clazz.getName(), clazz);
+ if (chainedInterceptor == null)
{
- i = clazz.newInstance();
- componentRegistry.registerComponent(clazz.getName(), i, clazz);
+ chainedInterceptor = clazz.newInstance();
+ componentRegistry.registerComponent(clazz.getName(), chainedInterceptor, clazz);
} else
{
// wipe next/last chaining!!
- i.setNext(null);
+ chainedInterceptor.setNext(null);
}
- return i;
+ chainedInterceptor.setStatisticsEnabled(configuration.getExposeManagementStatistics());
+ return chainedInterceptor;
}
public InterceptorChain buildInterceptorChain() throws IllegalAccessException, InstantiationException, ClassNotFoundException
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java 2008-04-24 09:20:40 UTC (rev 5653)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java 2008-04-24 09:41:31 UTC (rev 5654)
@@ -39,12 +39,11 @@
public void testSetCacheObjectName() throws Exception
{
ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
- String str = on.getCanonicalName();
boolean registered = false;
try
{
CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- wrapper.setCacheObjectName(str);
+ wrapper.setCacheObjectName(on.getCanonicalName());
// Register under the standard name
registerWrapper(wrapper);
@@ -52,12 +51,12 @@
registered = mBeanServer.isRegistered(on);
assertTrue("Registered with configured name", registered);
- assertEquals("Configured name retained", str, wrapper.getCacheObjectName());
+ assertEquals("Configured name retained", on.getCanonicalName(), wrapper.getCacheObjectName());
wrapper.create();
wrapper.start();
- interceptorRegistrationTest(str, true);
+ interceptorRegistrationTest(on.getCanonicalName(), true);
wrapper.stop();
wrapper.destroy();
16 years, 2 months