JBoss Cache SVN: r6872 - in core/branches/flat/src/main/java/org/jboss/starobrno: interceptors and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 09:26:45 -0400 (Wed, 08 Oct 2008)
New Revision: 6872
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
Log:
Fixed locking interceptor
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java 2008-10-08 13:04:49 UTC (rev 6871)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java 2008-10-08 13:26:45 UTC (rev 6872)
@@ -62,6 +62,11 @@
return null;
}
+ public Map<Object, Object> getMap()
+ {
+ return map;
+ }
+
public int getCommandId()
{
return METHOD_ID;
Added: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/LockingInterceptor.java 2008-10-08 13:26:45 UTC (rev 6872)
@@ -0,0 +1,266 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.interceptors;
+
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.read.GravitateDataCommand;
+import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.tx.CommitCommand;
+import org.jboss.starobrno.commands.tx.PrepareCommand;
+import org.jboss.starobrno.commands.tx.RollbackCommand;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.interceptors.base.PrePostProcessingCommandInterceptor;
+import org.jboss.starobrno.lock.LockManager;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+import org.jboss.starobrno.mvcc.MVCCEntryWrapper;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map.Entry;
+
+/**
+ * Interceptor to implement <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC</a> functionality.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">MVCC designs</a>
+ * @since 3.0
+ */
+public class LockingInterceptor extends PrePostProcessingCommandInterceptor
+{
+ LockManager lockManager;
+ DataContainer dataContainer;
+ MVCCEntryWrapper entryWrapper;
+
+ @Inject
+ public void setDependencies(LockManager lockManager, DataContainer dataContainer, MVCCEntryWrapper entryWrapper)
+ {
+ this.lockManager = lockManager;
+ this.dataContainer = dataContainer;
+ this.entryWrapper = entryWrapper;
+ }
+
+ @Override
+ protected boolean doBeforeCall(InvocationContext ctx, VisitableCommand command)
+ {
+ if (ctx.getOptionOverrides().isSuppressLocking())
+ {
+ if (log.isWarnEnabled()) log.warn("Lock suppression not supported with MVCC!");
+ }
+ return true;
+ }
+
+ @Override
+ public Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ try
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ transactionalCleanup(true, ctx);
+ }
+ }
+
+ @Override
+ public Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ try
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ transactionalCleanup(false, ctx);
+ }
+ }
+
+ @Override
+ public Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ try
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ finally
+ {
+ if (command.isOnePhaseCommit()) transactionalCleanup(true, ctx);
+ }
+ }
+
+ // read commands
+
+ @Override
+ public Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForReading(ctx, command.getKey(), true);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable
+ {
+ if (log.isDebugEnabled()) log.debug("No locking performed for SizeCommands");
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ // write commands
+
+ @Override
+ public Object handleClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
+ {
+ // get a snapshot of all keys in the data container
+ for (Object o : dataContainer.getEntries())
+ {
+ Object key = ((Entry) o).getKey();
+ entryWrapper.wrapEntryForWriting(ctx, key, false, false);
+ }
+
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForWriting(ctx, command.getKey(), false, true);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForWriting(ctx, command.getKey(), true, false);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handlePutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable
+ {
+ for (Object key : command.getMap().keySet())
+ {
+ entryWrapper.wrapEntryForWriting(ctx, key, true, false);
+ }
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForWriting(ctx, command.getKey(), false, true);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForWriting(ctx, command.getKey(), false, true);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
+ public Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ entryWrapper.wrapEntryForReading(ctx, command.getKey(), true);
+ return invokeNextInterceptor(ctx, command);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ protected void doAfterCall(InvocationContext ctx, VisitableCommand command)
+ {
+ // for non-transactional stuff.
+ if (ctx.getTransactionContext() == null)
+ {
+ List<Object> locks;
+ if (!(locks = ctx.getKeysLocked()).isEmpty())
+ {
+ cleanupLocks(locks, ctx, Thread.currentThread(), true);
+ }
+ else
+ {
+ if (trace) log.trace("Nothing to do since there are no modifications in scope.");
+ }
+ }
+ else
+ {
+ if (trace) log.trace("Nothing to do since there is a transaction in scope.");
+ }
+ }
+
+ private void cleanupLocks(List<Object> keysLocked, InvocationContext ctx, Object owner, boolean commit)
+ {
+ // clean up.
+ // unlocking needs to be done in reverse order.
+ ListIterator<Object> it = keysLocked.listIterator(keysLocked.size());
+
+ if (commit)
+ {
+ while (it.hasPrevious())
+ {
+ Object key = it.previous();
+ MVCCEntry entry = ctx.lookupEntry(key);
+ // could be null with read-committed
+ if (entry != null) entry.commitUpdate(ctx, dataContainer);
+ // and then unlock
+ if (trace) log.trace("Releasing lock on [" + key + "] for owner " + owner);
+ lockManager.unlock(key, owner);
+ }
+ }
+ else
+ {
+ while (it.hasPrevious())
+ {
+ Object key = it.previous();
+ MVCCEntry entry = ctx.lookupEntry(key);
+ // could be null with read-committed
+ if (entry != null) entry.rollbackUpdate();
+ // and then unlock
+ if (trace) log.trace("Releasing lock on [" + key + "] for owner " + owner);
+ lockManager.unlock(key, owner);
+ }
+ }
+ ctx.clearKeysLocked();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void transactionalCleanup(boolean commit, InvocationContext ctx)
+ {
+ if (ctx.getTransactionContext() != null)
+ {
+ List<Object> locks = ctx.getTransactionContext().getKeysLocked();
+ if (!locks.isEmpty()) cleanupLocks(locks, ctx, ctx.getGlobalTransaction(), commit);
+ }
+ else
+ {
+ throw new IllegalStateException("Attempting to do a commit or rollback but there is no transactional context in scope. " + ctx);
+ }
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6871 - core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 09:04:49 -0400 (Wed, 08 Oct 2008)
New Revision: 6871
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java
Log:
Fixed stuff
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java 2008-10-08 12:42:02 UTC (rev 6870)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java 2008-10-08 13:04:49 UTC (rev 6871)
@@ -21,30 +21,20 @@
*/
package org.jboss.starobrno.interceptors.base;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jboss.cache.commands.VisitableCommand;
-import org.jboss.cache.commands.legacy.write.CreateNodeCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.InvalidateCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.read.GravitateDataCommand;
+import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.tx.CommitCommand;
+import org.jboss.starobrno.commands.tx.PrepareCommand;
+import org.jboss.starobrno.commands.tx.RollbackCommand;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
+import org.jboss.starobrno.context.InvocationContext;
/**
* This interceptor adds pre and post processing to each <tt>visitXXX()</tt> method.
@@ -64,11 +54,11 @@
public abstract class PrePostProcessingCommandInterceptor extends CommandInterceptor
{
@Override
- public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handlePutDataMapCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handlePutKeyValueCommand(ctx, command) : null;
}
finally
{
@@ -76,55 +66,17 @@
}
}
- protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
- @Override
- public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handlePutKeyValueCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
- @Override
- public final Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handlePutForExternalReadCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
-
protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
- protected Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
-
@Override
- public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleRemoveNodeCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleRemoveCommand(ctx, command) : null;
}
finally
{
@@ -132,17 +84,17 @@
}
}
- protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ protected Object handleRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleCreateNodeCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleReplaceCommand(ctx, command) : null;
}
finally
{
@@ -150,22 +102,17 @@
}
}
- /**
- * @deprecated in 3.0. Will be removed when Optimistic and Pessimistic locking is removed.
- */
- @Deprecated
- protected Object handleCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
+ protected Object handleReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
-
@Override
- public final Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleClearDataCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleClearCommand(ctx, command) : null;
}
finally
{
@@ -173,17 +120,17 @@
}
}
- protected Object handleClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ protected Object handleClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleEvictFqnCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handlePutMapCommand(ctx, command) : null;
}
finally
{
@@ -191,17 +138,17 @@
}
}
- protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ protected Object handlePutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ public Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleInvalidateCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleEvictCommand(ctx, command) : null;
}
finally
{
@@ -209,35 +156,19 @@
}
}
- protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ protected Object handleEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
- @Override
- public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleRemoveKeyCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
+ // read commands
- protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
@Override
- public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ public Object visitSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleGetDataMapCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleSizeCommand(ctx, command) : null;
}
finally
{
@@ -245,17 +176,17 @@
}
}
- protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ protected Object handleSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleExistsNodeCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleGetKeyValueCommand(ctx, command) : null;
}
finally
{
@@ -263,35 +194,17 @@
}
}
- protected Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
- @Override
- public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleGetKeyValueCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ public Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleGetNodeCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleGravitateDataCommand(ctx, command) : null;
}
finally
{
@@ -299,35 +212,19 @@
}
}
- protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ protected Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
- @Override
- public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleGetKeysCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
+ // tx commands
- protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
@Override
- public final Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleGetChildrenNamesCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handlePrepareCommand(ctx, command) : null;
}
finally
{
@@ -335,71 +232,17 @@
}
}
- protected Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
- @Override
- public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleMoveCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
- protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
- @Override
- public final Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleGravitateDataCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
- protected Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
- @Override
- public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handlePrepareCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
@Override
- public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleRollbackCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleRollbackCommand(ctx, command) : null;
}
finally
{
@@ -413,11 +256,11 @@
}
@Override
- public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
{
try
{
- return doBeforeCall(ctx, command) ? handleCommitCommand(ctx, command) : null;
+ return (doBeforeCall(ctx, command)) ? handleCommitCommand(ctx, command) : null;
}
finally
{
@@ -430,24 +273,6 @@
return handleDefault(ctx, command);
}
- @Override
- public final Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- try
- {
- return doBeforeCall(ctx, command) ? handleOptimisticPrepareCommand(ctx, command) : null;
- }
- finally
- {
- doAfterCall(ctx, command);
- }
- }
-
- protected Object handleOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- return handleDefault(ctx, command);
- }
-
/**
* Callback that is invoked after every handleXXX() method defined above.
*
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java 2008-10-08 12:42:02 UTC (rev 6870)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java 2008-10-08 13:04:49 UTC (rev 6871)
@@ -21,29 +21,8 @@
*/
package org.jboss.starobrno.interceptors.base;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jboss.cache.commands.VisitableCommand;
-import org.jboss.cache.commands.read.ExistsCommand;
-import org.jboss.cache.commands.read.GetChildrenNamesCommand;
-import org.jboss.cache.commands.read.GetDataMapCommand;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.read.GetKeysCommand;
-import org.jboss.cache.commands.read.GetNodeCommand;
-import org.jboss.cache.commands.read.GravitateDataCommand;
-import org.jboss.cache.commands.tx.CommitCommand;
-import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
-import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.tx.RollbackCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.InvalidateCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.context.InvocationContext;
/**
* This interceptor will call {@link #skipInterception(org.jboss.cache.InvocationContext ,org.jboss.cache.commands.VisitableCommand)} before invoking each visit method
@@ -61,307 +40,10 @@
*/
public abstract class SkipCheckChainedInterceptor extends CommandInterceptor
{
- @Override
- public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handlePutDataMapCommand(ctx, command);
- }
- protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
+ // TODO!!!
@Override
- public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handlePutKeyValueCommand(ctx, command);
- }
-
- @Override
- public final Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handlePutForExternalReadCommand(ctx, command);
- }
-
- protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- protected Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleRemoveNodeCommand(ctx, command);
- }
-
- protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleRemoveDataCommand(ctx, command);
- }
-
- protected Object handleRemoveDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleEvictFqnCommand(ctx, command);
- }
-
- protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleInvalidateCommand(ctx, command);
- }
-
- protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleRemoveKeyCommand(ctx, command);
- }
-
- protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGetDataMapCommand(ctx, command);
- }
-
- protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleExistsNodeCommand(ctx, command);
- }
-
- protected Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGetKeyValueCommand(ctx, command);
- }
-
- protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGetNodeCommand(ctx, command);
- }
-
- protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGetKeysCommand(ctx, command);
- }
-
- protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGetChildrenNamesCommand(ctx, command);
- }
-
- protected Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleMoveCommand(ctx, command);
- }
-
- protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleGravitateDataCommand(ctx, command);
- }
-
- protected Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handlePrepareCommand(ctx, command);
- }
-
- protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleRollbackCommand(ctx, command);
- }
-
- protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleCommitCommand(ctx, command);
- }
-
- protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
- public final Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- if (skipInterception(ctx, command))
- {
- return invokeNextInterceptor(ctx, command);
- }
- return handleOptimisticPrepareCommand(ctx, command);
- }
-
- protected Object handleOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- return handleAll(ctx, command);
- }
-
- @Override
public final Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
{
if (skipInterception(ctx, command))
16 years, 2 months
JBoss Cache SVN: r6870 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 08:42:02 -0400 (Wed, 08 Oct 2008)
New Revision: 6870
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java
Log:
Fixed stuff
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -41,4 +41,8 @@
boolean exists(Entry<K, V> entry);
int size();
+
+ void clear();
+
+ void removeEntry(K key);
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -65,4 +65,14 @@
{
return data.size();
}
+
+ public void clear()
+ {
+ data.clear();
+ }
+
+ public void removeEntry(K key)
+ {
+ data.remove(key);
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,8 +21,19 @@
*/
package org.jboss.starobrno.commands;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.read.GravitateDataCommand;
+import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.tx.CommitCommand;
+import org.jboss.starobrno.commands.tx.PrepareCommand;
+import org.jboss.starobrno.commands.tx.RollbackCommand;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.commands.write.PutKeyValueCommand;
import java.util.Collection;
@@ -35,12 +46,73 @@
*/
public abstract class AbstractVisitor implements Visitor
{
+ // write commands
+
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
{
return handleDefault(ctx, command);
}
+ public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ // read commands
+
+ public Object visitSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ // tx commands
+
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+
/**
* A default handler for all commands visited. This is called for any visit method called, unless a visit command is
* appropriately overridden.
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -29,7 +29,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
-public interface TransactionBoundaryCommand extends ReplicableCommand
+public interface TransactionBoundaryCommand extends VisitableCommand
{
GlobalTransaction getGlobalTransaction();
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,20 +21,50 @@
*/
package org.jboss.starobrno.commands;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.read.GravitateDataCommand;
+import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.tx.CommitCommand;
+import org.jboss.starobrno.commands.tx.PrepareCommand;
+import org.jboss.starobrno.commands.tx.RollbackCommand;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.commands.write.*;
public interface Visitor
{
+ // write commands
+
Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable;
- Object visitRemoveCommand(InvocationContext ctx, RemoveCommand removeCommand);
+ Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable;
- Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand replaceCommand);
+ Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable;
- Object visitClearCommand(InvocationContext ctx, ClearCommand clearCommand);
+ Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable;
- Object visitPutMapCommand(InvocationContext ctx, PutMapCommand putMapCommand);
+ Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable;
- Object visitEvictCommand(InvocationContext ctx, Visitor visitor);
+ Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable;
+
+ // read commands
+
+ Object visitSizeCommand(InvocationContext ctx, SizeCommand command) throws Throwable;
+
+ Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable;
+
+ Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable;
+
+ // tx commands
+
+ Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable;
+
+ Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable;
+
+ Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable;
+
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -24,7 +24,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.notifications.Notifier;
-import org.jboss.starobrno.commands.DataCommand;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.mvcc.MVCCEntry;
@@ -35,9 +34,8 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
-public class GetKeyValueCommand implements DataCommand
+public class GetKeyValueCommand extends AbstractDataCommand
{
- protected Object key;
public static final int METHOD_ID = 26;
private static final Log log = LogFactory.getLog(GetKeyValueCommand.class);
private static final boolean trace = log.isTraceEnabled();
@@ -49,19 +47,9 @@
this.notifier = notifier;
}
- public Object getKey()
- {
- return key;
- }
-
- public void setKey(Object key)
- {
- this.key = key;
- }
-
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- return null; //TODO: Autogenerated. Implement me properly
+ return visitor.visitGetKeyValueCommand(ctx, this);
}
public Object perform(InvocationContext ctx) throws Throwable
@@ -89,14 +77,4 @@
{
return METHOD_ID;
}
-
- public Object[] getParameters()
- {
- return new Object[]{key};
- }
-
- public void setParameters(int commandId, Object[] parameters)
- {
- this.key = parameters[0];
- }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -26,7 +26,6 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
import org.jboss.starobrno.DataContainer;
-import org.jboss.starobrno.commands.DataCommand;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
import org.jgroups.Address;
@@ -40,7 +39,7 @@
* @author Manik Surtani
* @since 2.2.0
*/
-public class GravitateDataCommand implements DataCommand
+public class GravitateDataCommand extends AbstractDataCommand
{
public static final int METHOD_ID = 35;
@@ -54,7 +53,6 @@
private static final Log log = LogFactory.getLog(GravitateDataCommand.class);
private static final boolean trace = log.isTraceEnabled();
private BuddyFqnTransformer buddyFqnTransformer;
- private Object key;
private DataContainer dataContainer;
public GravitateDataCommand(Object key, boolean searchSubtrees, Address localAddress)
@@ -201,9 +199,7 @@
// }
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- // TODO implement me
- return null;
-// return visitor.visitGravitateDataCommand(ctx, this);
+ return visitor.visitGravitateDataCommand(ctx, this);
}
public int getCommandId()
@@ -216,11 +212,13 @@
return searchSubtrees;
}
+ @Override
public Object[] getParameters()
{
return new Object[]{key, searchSubtrees};
}
+ @Override
public void setParameters(int commandId, Object[] args)
{
key = args[0];
@@ -257,9 +255,4 @@
", searchSubtrees=" + searchSubtrees +
'}';
}
-
- public Object getKey()
- {
- return null; //TODO: Autogenerated. Implement me properly
- }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -43,7 +43,7 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- return null; //TODO: Autogenerated. Implement me properly
+ return visitor.visitSizeCommand(ctx, this);
}
public Object perform(InvocationContext ctx) throws Throwable
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -46,9 +46,7 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- // TODO - implement me
- return null;
-// return visitor.visitCommitCommand(ctx, this);
+ return visitor.visitCommitCommand(ctx, this);
}
public int getCommandId()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -65,9 +65,7 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- // TODO - implement me
- return null;
-// return visitor.visitPrepareCommand(ctx, this);
+ return visitor.visitPrepareCommand(ctx, this);
}
public List<WriteCommand> getModifications()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -46,9 +46,7 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- // TODO - implement me
- return null;
-// return visitor.visitRollbackCommand(ctx, this);
+ return visitor.visitRollbackCommand(ctx, this);
}
public int getCommandId()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -24,15 +24,14 @@
import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
/**
* @author Mircea.Markus(a)jboss.com
*/
public class ClearCommand implements VisitableCommand
{
- public static final Object[] params = new Object[0];
-
+ private static final Object[] params = new Object[0];
public static final int METHOD_ID = 17;
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
@@ -42,7 +41,12 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ for (MVCCEntry e : ctx.getLookedUpEntries().values())
+ {
+ e.setDeleted(true);
+ e.setValid(false);
+ }
+ return null;
}
public Object[] getParameters()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,10 +21,10 @@
*/
package org.jboss.starobrno.commands.write;
+import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
-import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
/**
* @author Mircea.Markus(a)jboss.com
@@ -35,12 +35,22 @@
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
- return visitor.visitEvictCommand(ctx, visitor);
+ return visitor.visitEvictCommand(ctx, this);
}
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ // TODO: notification?!??
+ if (key == null) throw new NullPointerException("Key is null!!");
+
+ MVCCEntry e = ctx.lookupEntry(key);
+ if (e != null && !e.isNullEntry())
+ {
+ e.setDeleted(true);
+ e.setValid(false);
+ }
+
+ return null;
}
public int getCommandId()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,10 +21,10 @@
*/
package org.jboss.starobrno.commands.write;
+import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
-import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
/**
* Implements functionality defined by {@link org.jboss.cache.Cache#put(org.jboss.cache.Fqn, Object, Object)}.
@@ -45,7 +45,8 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ MVCCEntry e = ctx.lookupEntry(key);
+ return e.setValue(value);
}
public int getCommandId()
@@ -55,7 +56,7 @@
public Object[] getParameters()
{
- return new Object[] {key, value};
+ return new Object[]{key, value};
}
public void setParameters(int commandId, Object[] parameters)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -24,9 +24,10 @@
import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
import java.util.Map;
+import java.util.Map.Entry;
/**
* @author Mircea.Markus(a)jboss.com
@@ -35,7 +36,7 @@
{
public static final int METHOD_ID = 2000;
- private Map map;
+ private Map<Object, Object> map;
public PutMapCommand(Map map)
{
@@ -53,7 +54,12 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ for (Entry<Object, Object> e : map.entrySet())
+ {
+ MVCCEntry me = ctx.lookupEntry(e.getKey());
+ if (e != null) e.setValue(e.getValue());
+ }
+ return null;
}
public int getCommandId()
@@ -63,7 +69,7 @@
public Object[] getParameters()
{
- return new Object[] {map};
+ return new Object[]{map};
}
public void setParameters(int commandId, Object[] parameters)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,10 +21,10 @@
*/
package org.jboss.starobrno.commands.write;
+import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
-import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
/**
@@ -41,7 +41,11 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ MVCCEntry e = ctx.lookupEntry(key);
+ if (e == null || e.isNullEntry()) return false;
+ e.setDeleted(true);
+ e.setValid(false);
+ return true;
}
public int getCommandId()
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -21,10 +21,10 @@
*/
package org.jboss.starobrno.commands.write;
+import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
-import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.mvcc.MVCCEntry;
/**
@@ -55,7 +55,14 @@
public Object perform(InvocationContext ctx) throws Throwable
{
- throw new NotImplementedException("Not Implemented");//todo implement
+ MVCCEntry e = ctx.lookupEntry(key);
+ if (e == null || e.isNullEntry()) return false;
+ if (oldValue.equals(e.getValue()))
+ {
+ e.setValue(newValue);
+ return true;
+ }
+ return false;
}
public int getCommandId()
@@ -65,7 +72,7 @@
public Object[] getParameters()
{
- return new Object[] {key, oldValue, newValue};
+ return new Object[]{key, oldValue, newValue};
}
public void setParameters(int commandId, Object[] parameters)
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java 2008-10-08 11:53:03 UTC (rev 6869)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java 2008-10-08 12:42:02 UTC (rev 6870)
@@ -92,4 +92,9 @@
", value=" + value +
'}';
}
+
+ public void setKey(K key)
+ {
+ this.key = key;
+ }
}
16 years, 2 months
JBoss Cache SVN: r6869 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 07:53:03 -0400 (Wed, 08 Oct 2008)
New Revision: 6869
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AnnounceBuddyPoolNameCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AssignToBuddyGroupCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ClusteredGetCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/DataGravitationCleanupCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/RemoveFromBuddyGroupCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ReplicateCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java
Log:
Fixed stuff
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,8 +21,8 @@
*/
package org.jboss.starobrno;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.config.Configuration;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.lifecycle.Lifecycle;
import java.util.Set;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,14 +21,15 @@
*/
package org.jboss.starobrno;
+import org.jboss.starobrno.config.CacheConfig;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.context.InvocationContext;
import org.jboss.util.NotImplementedException;
-import org.jboss.starobrno.config.CacheConfig;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
-import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
/**
* @author Mircea.Markus(a)jboss.com
@@ -36,7 +37,7 @@
public class CacheImpl implements Cache
{
private ConcurrentHashMap data = new ConcurrentHashMap();
- private Map<String, AtomicGroup> atomicGroups = new ConcurrentHashMap<String, AtomicGroup>();
+ private Map<String, AtomicGroup> atomicGroups = new ConcurrentHashMap<String, AtomicGroup>();
private CacheConfig cacheConfig;
@@ -141,4 +142,49 @@
{
return (data != null ? data.hashCode() : 0);
}
+
+ public void evict(Object key)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public Configuration getConfiguration()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public void addCacheListener(Object listener)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void removeCacheListener(Object listener)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public Set getCacheListeners()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public InvocationContext getInvocationContext()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public void setInvocationContext(InvocationContext ctx)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void start()
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void stop()
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,7 +21,7 @@
*/
package org.jboss.starobrno.commands;
-import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.transaction.GlobalTransaction;
/**
* // TODO: MANIK: Document this
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GravitateDataCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,265 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.read;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.commands.DataCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jgroups.Address;
+
+/**
+ * Used with buddy replication's {@link org.jboss.cache.interceptors.DataGravitatorInterceptor}.
+ * <p/>
+ * This is the equivalent of the old MethodCallDefinitions.dataGravitationMethod method call from 2.1.x.
+ * <p/>
+ *
+ * @author Manik Surtani
+ * @since 2.2.0
+ */
+public class GravitateDataCommand implements DataCommand
+{
+ public static final int METHOD_ID = 35;
+
+ /* dependencies */
+ private CacheSPI spi;
+
+ /* parametres */
+ protected boolean searchSubtrees;
+ private Address localAddress;
+
+ private static final Log log = LogFactory.getLog(GravitateDataCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+ private BuddyFqnTransformer buddyFqnTransformer;
+ private Object key;
+ private DataContainer dataContainer;
+
+ public GravitateDataCommand(Object key, boolean searchSubtrees, Address localAddress)
+ {
+ this.key = key;
+ this.searchSubtrees = searchSubtrees;
+ this.localAddress = localAddress;
+ }
+
+ public GravitateDataCommand(Address localAddress)
+ {
+ this.localAddress = localAddress;
+ }
+
+ public void initialize(DataContainer dataContainer, CacheSPI spi, BuddyFqnTransformer transformer)
+ {
+ this.dataContainer = dataContainer;
+ this.spi = spi;
+ buddyFqnTransformer = transformer;
+ }
+
+ /**
+ * Searches for data to gravitate given an Fqn and whether buddy backup subtrees are to be searched as well. Note that
+ * data stored under the Fqn, along with all children, are retrieved.
+ *
+ * @param ctx invocation context
+ * @return a {@link org.jboss.cache.buddyreplication.GravitateResult} containing node data, as well as information on whether this was found in a primary or backup tree.
+ */
+ @SuppressWarnings("unchecked")
+ public Object perform(InvocationContext ctx)
+ {
+ /*
+ // TODO: Test this with MVCC.
+
+ // for now, perform a very simple series of getData calls.
+ if (trace) log.trace("Caller is asking for " + key);
+ try
+ {
+ ctx.setOriginLocal(false);
+ // use a get() call into the cache to make sure cache loading takes place.
+ // no need to cache the original skipDataGravitation setting here - it will always be false of we got here!!
+ //todo 2.2 use dataContainer for peek and load the data in the CLInterceptor rather than using the SPI for than!!!
+ ctx.getOptionOverrides().setSkipDataGravitation(true);
+ Node actualNode = spi.getNode(fqn);
+ ctx.getOptionOverrides().setSkipDataGravitation(false);
+
+ if (trace) log.trace("In local tree, this is " + actualNode);
+
+ Fqn backupNodeFqn = null;
+ if (actualNode == null && searchSubtrees)
+ {
+ log.trace("Looking at backup trees.");
+
+ // need to loop through backupSubtree's children
+ Set allGroupNames = getBackupRoots();
+ if (allGroupNames != null)
+ {
+ for (Object groupName : allGroupNames)
+ {
+ // groupName is the name of a buddy group since all child names in this
+ // collection are direct children of BUDDY_BACKUP_SUBTREE_FQN
+ Fqn backupRoot = Fqn.fromRelativeElements(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, (String) groupName);
+ if (buddyFqnTransformer.isDeadBackupRoot(backupRoot))
+ {
+ Set<Integer> deadChildNames = new TreeSet<Integer>(spi.getChildrenNames(backupRoot));
+ Integer[] elems = deadChildNames.toArray(new Integer[deadChildNames.size()]);
+
+ // these are integers. we need to start with the highest/most recent.
+ for (int i = elems.length - 1; i > -1; i--)
+ {
+ Integer versionOfDefunctData = elems[i];
+ backupNodeFqn = Fqn.fromRelativeFqn(Fqn.fromRelativeElements(backupRoot, versionOfDefunctData), fqn);
+
+ // use a get() call into the cache to make sure cache loading takes place.
+ ctx.getOptionOverrides().setSkipDataGravitation(true);
+ actualNode = spi.peek(backupNodeFqn, false);
+ ctx.getOptionOverrides().setSkipDataGravitation(false);
+
+ // break out of the inner loop searching through the dead node's various backups
+ if (actualNode != null) break;
+ }
+ }
+ else
+ {
+ backupNodeFqn = Fqn.fromRelativeFqn(backupRoot, fqn);
+ // use a get() call into the cache to make sure cache loading takes place.
+ ctx.getOptionOverrides().setSkipDataGravitation(true);
+ actualNode = spi.getNode(backupNodeFqn);
+ ctx.getOptionOverrides().setSkipDataGravitation(false);
+ }
+
+ if (trace)
+ log.trace("Looking for " + backupNodeFqn + ". Search result: " + actualNode);
+
+ // break out of outer loop searching through all available backups.
+ if (actualNode != null) break;
+ }
+ }
+
+ }
+
+ if (actualNode == null)
+ {
+ return GravitateResult.noDataFound();
+ }
+ else
+ {
+ // make sure we LOAD data for this node!!
+ actualNode.getData();
+ }
+
+ if (backupNodeFqn == null && searchSubtrees)
+ {
+ backupNodeFqn = buddyFqnTransformer.getBackupFqn(buddyFqnTransformer.getGroupNameFromAddress(localAddress), fqn);
+ }
+
+ List<NodeData> list = dataContainer.buildNodeData(new LinkedList<NodeData>(), (NodeSPI) actualNode, false);
+
+ return GravitateResult.subtreeResult(list, backupNodeFqn);
+ }
+ catch (RuntimeException re)
+ {
+ if (trace) log.trace("Caught throwable", re);
+ throw re;
+ }
+ finally
+ {
+ ctx.setOriginLocal(true);
+ }
+ */
+
+ throw new UnsupportedOperationException("FIX ME");
+ // TODO: implement BR on flat cache
+ }
+
+ /**
+ * @return a Set of child node names that hang directly off the backup tree root, or null if the backup tree root doesn't exist.
+ */
+// protected Set<Object> getBackupRoots()
+// {
+// InternalNode backupSubtree = dataContainer.peekInternalNode(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false);
+// if (backupSubtree == null) return null;
+// return backupSubtree.getChildrenNames();
+// }
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ // TODO implement me
+ return null;
+// return visitor.visitGravitateDataCommand(ctx, this);
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public boolean isSearchSubtrees()
+ {
+ return searchSubtrees;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{key, searchSubtrees};
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ key = args[0];
+ searchSubtrees = (Boolean) args[1];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ GravitateDataCommand that = (GravitateDataCommand) o;
+
+ if (searchSubtrees != that.searchSubtrees) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (searchSubtrees ? 1 : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "GravitateDataCommand{" +
+ "key=" + key +
+ ", searchSubtrees=" + searchSubtrees +
+ '}';
+ }
+
+ public Object getKey()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AnnounceBuddyPoolNameCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AnnounceBuddyPoolNameCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AnnounceBuddyPoolNameCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jgroups.Address;
+
+/**
+ * Announces a buddy pool name to the cluster. This is not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2.0
+ */
+public class AnnounceBuddyPoolNameCommand implements ReplicableCommand
+{
+ public static final int METHOD_ID = 28;
+ private static final Log log = LogFactory.getLog(AnnounceBuddyPoolNameCommand.class);
+
+ /* dependencies*/
+ private BuddyManager buddyManager;
+
+ /*parameters */
+ private Address address;
+ private String buddyPoolName;
+
+ public AnnounceBuddyPoolNameCommand()
+ {
+ }
+
+ public AnnounceBuddyPoolNameCommand(Address address, String buddyPoolName)
+ {
+ this.address = address;
+ this.buddyPoolName = buddyPoolName;
+ }
+
+ public void initialize(BuddyManager buddyManager)
+ {
+ this.buddyManager = buddyManager;
+ }
+
+ /**
+ * This method calls the relevant handler on the buddy manager to deal with this pool broadcast.
+ *
+ * @param ctx invocation context, ignored.
+ * @return null
+ * @throws Throwable in the event of problems
+ */
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ if (buddyManager != null)
+ buddyManager.handlePoolNameBroadcast(address, buddyPoolName);
+ else if (log.isWarnEnabled())
+ log.warn("Received annouceBuddyPoolName call from [" + address + "] but buddy replication is not enabled on this node!");
+ return null;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public Address getAddress()
+ {
+ return address;
+ }
+
+ public String getBuddyPoolName()
+ {
+ return buddyPoolName;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{address, buddyPoolName};
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ address = (Address) args[0];
+ buddyPoolName = (String) args[1];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AnnounceBuddyPoolNameCommand that = (AnnounceBuddyPoolNameCommand) o;
+
+ if (address != null ? !address.equals(that.address) : that.address != null) return false;
+ if (buddyPoolName != null ? !buddyPoolName.equals(that.buddyPoolName) : that.buddyPoolName != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (address != null ? address.hashCode() : 0);
+ result = 31 * result + (buddyPoolName != null ? buddyPoolName.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AnnounceBuddyPoolNameCommand{" +
+ "buddyManager=" + buddyManager +
+ ", address=" + address +
+ ", buddyPoolName='" + buddyPoolName + '\'' +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AssignToBuddyGroupCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AssignToBuddyGroupCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/AssignToBuddyGroupCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * Assigns a buddy to a group. This is not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2.0
+ */
+public class AssignToBuddyGroupCommand implements ReplicableCommand
+{
+ public static final int METHOD_ID = 29;
+
+ /* dependencies */
+ private BuddyManager buddyManager;
+
+ /* parameters */
+ private BuddyGroup group;
+ private Map<Fqn, byte[]> state;
+
+ public AssignToBuddyGroupCommand(BuddyGroup group, Map<Fqn, byte[]> state)
+ {
+ this.group = group;
+ this.state = state;
+ }
+
+ public AssignToBuddyGroupCommand()
+ {
+ }
+
+ public void initialize(BuddyManager manager)
+ {
+ this.buddyManager = manager;
+ }
+
+ /**
+ * This method calls the relevant handler on the buddy manager to deal with being assigned to a buddy group
+ *
+ * @param ctx invocation context, ignored.
+ * @return null
+ * @throws Throwable in the event of problems
+ */
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ if (buddyManager != null)
+ buddyManager.handleAssignToBuddyGroup(group, state);
+ return null;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public BuddyGroup getGroup()
+ {
+ return group;
+ }
+
+ public Map<Fqn, byte[]> getState()
+ {
+ return state;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{group, state};
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setParameters(int commandId, Object[] args)
+ {
+ group = (BuddyGroup) args[0];
+ state = (Map<Fqn, byte[]>) args[1];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AssignToBuddyGroupCommand that = (AssignToBuddyGroupCommand) o;
+
+ if (group != null ? !group.equals(that.group) : that.group != null) return false;
+ if (state != null ? !state.equals(that.state) : that.state != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (group != null ? group.hashCode() : 0);
+ result = 31 * result + (state != null ? state.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AssignToBuddyGroupCommand{" +
+ "buddyManager=" + buddyManager +
+ ", group=" + group +
+ ", state=" + (state == null ? null : Arrays.asList(state)) +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ClusteredGetCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ClusteredGetCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ClusteredGetCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.commands.DataCommand;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Issues a clustered get call, for use primarily by the {@link org.jboss.cache.loader.ClusteredCacheLoader}. This is
+ * not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2.0
+ */
+public class ClusteredGetCommand implements ReplicableCommand
+{
+ public static final int METHOD_ID = 22;
+
+ private DataCommand dataCommand;
+ private boolean searchBackupSubtrees;
+ private DataContainer dataContainer;
+ private InterceptorChain interceptorChain;
+
+ private static final Log log = LogFactory.getLog(ClusteredGetCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ public ClusteredGetCommand(boolean searchBackupSubtrees, DataCommand dataCommand)
+ {
+ this.searchBackupSubtrees = searchBackupSubtrees;
+ this.dataCommand = dataCommand;
+ }
+
+ public ClusteredGetCommand()
+ {
+ }
+
+ public void initialize(DataContainer dataContainer, InterceptorChain interceptorChain)
+ {
+ this.dataContainer = dataContainer;
+ this.interceptorChain = interceptorChain;
+ }
+
+ /**
+ * Invokes a {@link org.jboss.cache.commands.DataCommand} on a remote cache and returns results.
+ *
+ * @param context invocation context, ignored.
+ * @return a List containing 2 elements: a boolean, (true or false) and a value (Object) which is the result of invoking a remote get specified by {@link #getDataCommand()}. If buddy replication is used one further element is added - an Fqn of the backup subtree in which this node may be found.
+ */
+ public Object perform(InvocationContext context) throws Throwable
+ {
+ if (trace)
+ log.trace("Clustered Get called with params: " + dataCommand + ", " + searchBackupSubtrees);
+
+ Object callResults = null;
+ try
+ {
+ InvocationContext ctx = interceptorChain.getInvocationContext();
+ ctx.setOriginLocal(false);
+ // very hacky to be calling this command directly.
+ callResults = dataCommand.perform(ctx);
+ boolean found = true; // TODO: Revisit this!!
+ if (trace) log.trace("Got result " + callResults + ", found=" + found);
+ if (found && callResults == null) callResults = createEmptyResults();
+ }
+ catch (Exception e)
+ {
+ log.warn("Problems processing clusteredGet call", e);
+ }
+
+ List<Object> results = new ArrayList<Object>(2);
+ if (callResults != null)
+ {
+ results.add(true);
+ results.add(callResults);
+ }
+ else
+ {
+ results.add(false);
+ results.add(null);
+ }
+ return results;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ /**
+ * Creates an empty Collection class based on the return type of the method called.
+ */
+ private Object createEmptyResults()
+ {
+ return null;
+ }
+
+ public Boolean getSearchBackupSubtrees()
+ {
+ return searchBackupSubtrees;
+ }
+
+ public DataCommand getDataCommand()
+ {
+ return dataCommand;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{dataCommand, searchBackupSubtrees}; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ dataCommand = (DataCommand) args[0];
+ searchBackupSubtrees = (Boolean) args[1];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ClusteredGetCommand that = (ClusteredGetCommand) o;
+
+ if (dataCommand != null ? !dataCommand.equals(that.dataCommand) : that.dataCommand != null)
+ return false;
+ return searchBackupSubtrees == that.searchBackupSubtrees;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (dataCommand != null ? dataCommand.hashCode() : 0);
+ result = 31 * result + (searchBackupSubtrees ? 1 : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ClusteredGetCommand{" +
+ "dataCommand=" + dataCommand +
+ ", searchBackupSubtrees=" + searchBackupSubtrees +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/DataGravitationCleanupCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/DataGravitationCleanupCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/DataGravitationCleanupCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+import org.jboss.starobrno.transaction.GlobalTransaction;
+import org.jboss.starobrno.transaction.TransactionTable;
+
+/**
+ * Data gravitation cleanup handler. Primarily used by the {@link org.jboss.cache.interceptors.DataGravitatorInterceptor}.
+ * This is not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class DataGravitationCleanupCommand implements ReplicableCommand
+{
+ public static final int METHOD_ID = 34;
+ private static final Log log = LogFactory.getLog(DataGravitationCleanupCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ /* dependencies */
+ private BuddyManager buddyManager;
+ private TransactionTable transactionTable;
+ private InterceptorChain invoker;
+ private CommandsFactory commandsFactory;
+ private DataContainer dataContainer;
+
+ /* parameters */
+ private GlobalTransaction globalTransaction;
+ private Fqn fqn;
+ private Fqn backup;
+ private BuddyFqnTransformer buddyFqnTransformer;
+
+
+ public DataGravitationCleanupCommand(Fqn primary, Fqn backup)
+ {
+ this.fqn = primary;
+ this.backup = backup;
+ }
+
+ public DataGravitationCleanupCommand()
+ {
+ }
+
+ public void initialize(BuddyManager buddyManager, InterceptorChain invoker, TransactionTable transactionTable,
+ CommandsFactory commandsFactory, DataContainer dataContainer, BuddyFqnTransformer buddyFqnTransformer)
+ {
+ this.buddyManager = buddyManager;
+ this.invoker = invoker;
+ this.transactionTable = transactionTable;
+ this.commandsFactory = commandsFactory;
+ this.dataContainer = dataContainer;
+ this.buddyFqnTransformer = buddyFqnTransformer;
+ }
+
+ /**
+ * Performs a cleanup on nodes that would have been previously gravitated away from the current cache instance.
+ */
+ public Object perform(InvocationContext ctx) throws Throwable
+ {/*
+ if (buddyManager.isDataGravitationRemoveOnFind())
+ {
+ if (trace)
+ log.trace("DataGravitationCleanup: Removing primary (" + fqn + ") and backup (" + backup + ")");
+
+ GlobalTransaction gtx = transactionTable.getCurrentTransaction();
+ if (!executeRemove(gtx, fqn))
+ {
+ // only attempt to clean up the backup if the primary did not exist - a waste of a call otherwise.
+ Object result = executeRemove(gtx, backup);
+ if (wasNodeRemoved(result))
+ {
+ // if this is a DIRECT child of a DEAD buddy backup region, then remove the empty dead region structural node.
+ if (buddyFqnTransformer.isDeadBackupFqn(backup) && buddyFqnTransformer.isDeadBackupRoot(backup.getAncestor(backup.size() - 2)))
+ {
+ Fqn deadBackupRootFqn = backup.getParent();
+ if (!dataContainer.hasChildren(deadBackupRootFqn))
+ {
+ if (trace) log.trace("Removing dead backup region " + deadBackupRootFqn);
+ executeRemove(gtx, deadBackupRootFqn);
+
+ // now check the grand parent and see if we are free of versions
+ deadBackupRootFqn = deadBackupRootFqn.getParent();
+ if (!dataContainer.hasChildren(deadBackupRootFqn))
+ {
+ if (trace) log.trace("Removing dead backup region " + deadBackupRootFqn);
+ executeRemove(gtx, deadBackupRootFqn);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if (trace) log.trace("Managed to remove primary (" + fqn + "). Not bothering with backups.");
+ }
+ }
+ else
+ {
+ if (trace)
+ log.trace("DataGravitationCleanup: Evicting primary (" + fqn + ") and backup (" + backup + ")");
+ evictNode(fqn);
+ evictNode(backup);
+ }
+ return null; */
+ // TODO - needs implementation
+ throw new UnsupportedOperationException("Fix me!");
+ }
+
+ /**
+ * Returns true if such a node was removed.
+ */
+// private boolean executeRemove(GlobalTransaction gtx, Fqn toRemove) throws Throwable
+// {
+// Object result;
+// RemoveNodeCommand removeBackupCommand = commandsFactory.buildRemoveNodeCommand(gtx, toRemove);
+//
+// InvocationContext ctx = invoker.getInvocationContext();
+// ctx.getOptionOverrides().setCacheModeLocal(true);
+// result = invoker.invoke(ctx, removeBackupCommand);
+// return result != null && (Boolean) result;
+// }
+ private boolean wasNodeRemoved(Object result)
+ {
+ return result != null && (Boolean) result;
+ }
+
+// private void evictNode(Fqn fqn) throws Throwable
+// {
+// if (dataContainer.exists(fqn))
+// {
+// List<Fqn> toEvict = dataContainer.getNodesForEviction(fqn, true);
+// for (Fqn aFqn : toEvict)
+// {
+// EvictCommand evictFqnCommand = commandsFactory.buildEvictFqnCommand(aFqn);
+// invoker.invoke(evictFqnCommand);
+// }
+// }
+// else
+// {
+// if (trace) log.trace("Not evicting " + fqn + " as it doesn't exist");
+// }
+// }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public Fqn getBackup()
+ {
+ return backup;
+ }
+
+ public GlobalTransaction getGlobalTransaction()
+ {
+ return globalTransaction;
+ }
+
+ public void setGlobalTransaction(GlobalTransaction gtx)
+ {
+ this.globalTransaction = gtx;
+ }
+
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{fqn, backup}; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ fqn = (Fqn) args[0];
+ backup = (Fqn) args[1];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ DataGravitationCleanupCommand that = (DataGravitationCleanupCommand) o;
+
+ if (backup != null ? !backup.equals(that.backup) : that.backup != null) return false;
+ if (globalTransaction != null ? !globalTransaction.equals(that.globalTransaction) : that.globalTransaction != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (globalTransaction != null ? globalTransaction.hashCode() : 0);
+ result = 31 * result + (backup != null ? backup.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "DataGravitationCleanupCommand{" +
+ "fqn=" + fqn +
+ ", backup=" + backup +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/RemoveFromBuddyGroupCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/RemoveFromBuddyGroupCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/RemoveFromBuddyGroupCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * Removes a buddy from a group. This is not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class RemoveFromBuddyGroupCommand implements ReplicableCommand
+{
+ public static final int METHOD_ID = 30;
+
+ private BuddyManager buddyManager;
+
+ private String groupName;
+
+ public RemoveFromBuddyGroupCommand(String groupName)
+ {
+ this.groupName = groupName;
+ }
+
+ public RemoveFromBuddyGroupCommand()
+ {
+ }
+
+ public void initialize(BuddyManager buddyManager)
+ {
+ this.buddyManager = buddyManager;
+ }
+
+ /**
+ * This method calls the relevant handler on the buddy manager to deal with being removed from a buddy group
+ *
+ * @param ctx invocation context, ignored.
+ * @return null
+ */
+ public Object perform(InvocationContext ctx)
+ {
+ if (buddyManager != null)
+ buddyManager.handleRemoveFromBuddyGroup(groupName);
+ return null;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public String getGroupName()
+ {
+ return groupName;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{groupName};
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ groupName = (String) args[0];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ RemoveFromBuddyGroupCommand that = (RemoveFromBuddyGroupCommand) o;
+
+ if (groupName != null ? !groupName.equals(that.groupName) : that.groupName != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (groupName != null ? groupName.hashCode() : 0);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "RemoveFromBuddyGroupCommand{" +
+ "buddyManager=" + buddyManager +
+ ", groupName='" + groupName + '\'' +
+ '}';
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ReplicateCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ReplicateCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/remote/ReplicateCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,278 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.remote;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Command that implements cluster replication logic. Essentially mimics the replicate() and replicateAll() methods
+ * in 2.1.x, we may need to revisit the usefulness of such a command.
+ * <p/>
+ * This is not a {@link org.jboss.cache.commands.VisitableCommand} and hence
+ * not passed up the {@link org.jboss.cache.interceptors.base.CommandInterceptor} chain.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class ReplicateCommand implements ReplicableCommand
+{
+ public static final int SINGLE_METHOD_ID = 13;
+ public static final int MULTIPLE_METHOD_ID = 14;
+
+ private InterceptorChain invoker;
+
+ private static final Log log = LogFactory.getLog(ReplicateCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ /**
+ * optimisation - rather than constructing a new list each for scenarios where a single modification needs
+ * to be replicated rather use this instance.
+ */
+ private ReplicableCommand singleModification;
+ private List<ReplicableCommand> modifications;
+
+ public ReplicateCommand(List<ReplicableCommand> modifications)
+ {
+ if (modifications != null && modifications.size() == 1)
+ {
+ singleModification = modifications.get(0);
+ }
+ else
+ {
+ this.modifications = modifications;
+ }
+ }
+
+ public ReplicateCommand(ReplicableCommand command)
+ {
+ this.singleModification = command;
+ }
+
+ public ReplicateCommand()
+ {
+ }
+
+ public void initialize(InterceptorChain interceptorChain)
+ {
+ this.invoker = interceptorChain;
+ }
+
+ public void setSingleModification(ReplicableCommand singleModification)
+ {
+ this.singleModification = singleModification;
+ }
+
+ public void setModifications(List<ReplicableCommand> modifications)
+ {
+ if (modifications != null && modifications.size() == 1)
+ singleModification = modifications.get(0);
+ else
+ this.modifications = modifications;
+ }
+
+ /**
+ * Executes commands replicated to the current cache instance by other cache instances.
+ *
+ * @param ctx invocation context, ignored.
+ * @return if this is a single command being processed <b>and</b> it is a {@link org.jboss.cache.commands.read.GravitateDataCommand}, the result of processing this command is returned. Otherwise, null is returned.
+ * @throws Throwable
+ */
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ if (isSingleCommand())
+ {
+ Object retVal = processSingleCommand(singleModification);
+
+ // only send back the result of the execution if it is a data gravitation command.
+ // all other commands don't need to send back return values, there will be an unnecessary overhead of
+ // marshalling results that won't ever be used.
+ if (singleModification instanceof GravitateDataCommand)
+ return retVal;
+ else
+ return null;
+ }
+ for (ReplicableCommand command : modifications) processSingleCommand(command);
+ return null;
+ }
+
+ private Object processSingleCommand(ReplicableCommand cacheCommand)
+ throws Throwable
+ {
+ Object result;
+ try
+ {
+ if (trace) log.trace("Invoking command " + cacheCommand + ", with originLocal flag set to false.");
+
+ if (cacheCommand instanceof VisitableCommand)
+ {
+ Object retVal = invoker.invokeRemote((VisitableCommand) cacheCommand);
+ // we only need to return values for a set of remote calls; not every call.
+ if (returnValueForRemoteCall(cacheCommand))
+ {
+ result = retVal;
+ }
+ else
+ {
+ result = null;
+ }
+ }
+ else
+ {
+ result = cacheCommand.perform(null);
+ }
+ }
+ catch (Throwable ex)
+ {
+ // TODO deal with PFER
+// if (!(cacheCommand instanceof PutForExternalReadCommand))
+// {
+ throw ex;
+// }
+// else
+// {
+// if (trace)
+// log.trace("Caught an exception, but since this is a putForExternalRead() call, suppressing the exception. Exception is:", ex);
+// result = null;
+// }
+ }
+ return result;
+ }
+
+ private boolean returnValueForRemoteCall(ReplicableCommand cacheCommand)
+ {
+ return cacheCommand instanceof GravitateDataCommand || cacheCommand instanceof ClusteredGetCommand;
+ }
+
+ public int getCommandId()
+ {
+ return isSingleCommand() ? SINGLE_METHOD_ID : MULTIPLE_METHOD_ID;
+ }
+
+ public List<ReplicableCommand> getModifications()
+ {
+ return modifications;
+ }
+
+ public ReplicableCommand getSingleModification()
+ {
+ return singleModification;
+ }
+
+ public Object[] getParameters()
+ {
+ if (isSingleCommand())
+ return new Object[]{singleModification};
+ else
+ return new Object[]{modifications};
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setParameters(int commandId, Object[] args)
+ {
+ if (commandId == SINGLE_METHOD_ID)
+ {
+ singleModification = (ReplicableCommand) args[0];
+ }
+ else
+ {
+ modifications = (List<ReplicableCommand>) args[0];
+ }
+ }
+
+ public boolean isSingleCommand()
+ {
+ return singleModification != null;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ReplicateCommand that = (ReplicateCommand) o;
+
+ if (modifications != null ? !modifications.equals(that.modifications) : that.modifications != null) return false;
+ if (singleModification != null ? !singleModification.equals(that.singleModification) : that.singleModification != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (singleModification != null ? singleModification.hashCode() : 0);
+ result = 31 * result + (modifications != null ? modifications.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ReplicateCommand{" +
+ "cmds=" + (isSingleCommand() ? singleModification : modifications) +
+ '}';
+ }
+
+ /**
+ * Creates a copy of this command, amking a deep copy of any collections but everything else copied shallow.
+ *
+ * @return a copy
+ */
+ public ReplicateCommand copy()
+ {
+ ReplicateCommand clone;
+ clone = new ReplicateCommand();
+ clone.invoker = invoker;
+ clone.modifications = modifications == null ? null : new ArrayList<ReplicableCommand>(modifications);
+ clone.singleModification = singleModification;
+ return clone;
+ }
+
+ public boolean containsCommandType(Class<? extends ReplicableCommand> aClass)
+ {
+ if (isSingleCommand())
+ {
+ return getSingleModification().getClass().equals(aClass);
+ }
+ else
+ {
+ for (ReplicableCommand command : getModifications())
+ {
+ if (command.getClass().equals(aClass)) return true;
+ }
+ }
+ return false;
+ }
+}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.commands.tx;
-import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.starobrno.commands.TransactionBoundaryCommand;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.transaction.GlobalTransaction;
/**
* // TODO: MANIK: Document this
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.commands.tx;
-import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.transaction.GlobalTransaction;
/**
* // TODO: MANIK: Document this
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,11 +21,11 @@
*/
package org.jboss.starobrno.commands.tx;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.starobrno.commands.ReplicableCommand;
import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.commands.WriteCommand;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jgroups.Address;
import java.util.ArrayList;
@@ -42,11 +42,11 @@
{
public static final int METHOD_ID = 10;
- protected List<ReplicableCommand> modifications;
+ protected List<WriteCommand> modifications;
protected Address localAddress;
protected boolean onePhaseCommit;
- public PrepareCommand(GlobalTransaction gtx, List<ReplicableCommand> modifications, Address localAddress, boolean onePhaseCommit)
+ public PrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address localAddress, boolean onePhaseCommit)
{
this.gtx = gtx;
this.modifications = modifications;
@@ -70,7 +70,7 @@
// return visitor.visitPrepareCommand(ctx, this);
}
- public List<ReplicableCommand> getModifications()
+ public List<WriteCommand> getModifications()
{
return modifications;
}
@@ -111,7 +111,7 @@
public void setParameters(int commandId, Object[] args)
{
gtx = (GlobalTransaction) args[0];
- modifications = (List<ReplicableCommand>) args[1];
+ modifications = (List<WriteCommand>) args[1];
localAddress = (Address) args[2];
onePhaseCommit = (Boolean) args[3];
}
@@ -147,7 +147,7 @@
PrepareCommand copy = new PrepareCommand();
copy.gtx = gtx;
copy.localAddress = localAddress;
- copy.modifications = modifications == null ? null : new ArrayList<ReplicableCommand>(modifications);
+ copy.modifications = modifications == null ? null : new ArrayList<WriteCommand>(modifications);
copy.onePhaseCommit = onePhaseCommit;
return copy;
}
@@ -165,7 +165,7 @@
public boolean containsModificationType(Class<? extends ReplicableCommand> replicableCommandClass)
{
- for (ReplicableCommand mod : getModifications())
+ for (WriteCommand mod : getModifications())
{
if (mod.getClass().equals(replicableCommandClass))
{
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.commands.tx;
-import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.starobrno.commands.Visitor;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.transaction.GlobalTransaction;
/**
* // TODO: MANIK: Document this
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -23,12 +23,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.util.Immutables;
+import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.starobrno.mvcc.MVCCEntry;
import org.jboss.starobrno.transaction.GlobalTransaction;
-import org.jboss.starobrno.commands.VisitableCommand;
-import org.jboss.cache.config.Option;
-import org.jboss.cache.util.Immutables;
-import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.starobrno.transaction.TransactionTable;
import javax.transaction.Transaction;
import java.util.Collections;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,10 +21,9 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.config.Option;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+import org.jboss.starobrno.commands.WriteCommand;
import javax.transaction.Transaction;
import java.util.List;
@@ -75,14 +74,14 @@
* @param fqn fqn that has been removed.
* @throws NullPointerException if the Fqn is null.
*/
- void addRemovedNode(Fqn fqn);
+ void addRemovedEntry(Object key);
/**
* Gets the list of removed nodes.
*
* @return list of nodes removed in the current transaction scope. Note that this method will return an empty list if nothing has been removed. The list returned is defensively copied.
*/
- List<Fqn> getRemovedNodes();
+ List<Object> getRemovedEntries();
/**
* Sets the local transaction to be associated with this transaction context.
@@ -228,12 +227,12 @@
*
* @param fqn fqn to add. Must not be null.
*/
- void addDummyNodeCreatedByCacheLoader(Fqn fqn);
+ void addDummyEntryCreatedByCacheLoader(Object key);
/**
* @return a list of uninitialized nodes created by the cache loader, or an empty list.
*/
- List<Fqn> getDummyNodesCreatedByCacheLoader();
+ List<Object> getDummyEntriesCreatedByCacheLoader();
/**
* Sets a transaction-scope option override
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -21,11 +21,10 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.WriteCommand;
import org.jboss.cache.config.Option;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
import org.jboss.cache.util.Immutables;
+import org.jboss.starobrno.commands.WriteCommand;
import org.jboss.starobrno.mvcc.MVCCEntry;
import javax.transaction.RollbackException;
@@ -80,12 +79,12 @@
* A list of dummy uninitialised nodes created by the cache loader interceptor to load data for a
* given node in this tx.
*/
- private List<Fqn> dummyNodesCreatedByCacheLoader;
+ private List<Object> dummyNodesCreatedByCacheLoader;
/**
* List<Fqn> of nodes that have been removed by the transaction
*/
- private List<Fqn> removedNodes = null;
+ private List<Object> removedNodes = null;
private final Map<Object, MVCCEntry> lookedUpEntries = new HashMap<Object, MVCCEntry>(8);
@@ -195,17 +194,17 @@
}
- public void addRemovedNode(Fqn fqn)
+ public void addRemovedEntry(Object key)
{
- if (fqn == null) throw new NullPointerException("Fqn is null!");
- if (removedNodes == null) removedNodes = new LinkedList<Fqn>();
- removedNodes.add(fqn);
+ if (key == null) throw new NullPointerException("Key is null!");
+ if (removedNodes == null) removedNodes = new LinkedList<Object>();
+ removedNodes.add(key);
}
- public List<Fqn> getRemovedNodes()
+ public List<Object> getRemovedEntries()
{
if (removedNodes == null) return Collections.emptyList();
- return new ArrayList<Fqn>(removedNodes);
+ return new ArrayList<Object>(removedNodes);
}
public void setTransaction(Transaction tx)
@@ -296,14 +295,14 @@
return sb.toString();
}
- public void addDummyNodeCreatedByCacheLoader(Fqn fqn)
+ public void addDummyEntryCreatedByCacheLoader(Object key)
{
if (dummyNodesCreatedByCacheLoader == null)
- dummyNodesCreatedByCacheLoader = new LinkedList<Fqn>();
- dummyNodesCreatedByCacheLoader.add(fqn);
+ dummyNodesCreatedByCacheLoader = new LinkedList<Object>();
+ dummyNodesCreatedByCacheLoader.add(key);
}
- public List<Fqn> getDummyNodesCreatedByCacheLoader()
+ public List<Object> getDummyEntriesCreatedByCacheLoader()
{
if (dummyNodesCreatedByCacheLoader == null) return Collections.emptyList();
return dummyNodesCreatedByCacheLoader;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -22,7 +22,7 @@
package org.jboss.starobrno.factories.context;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.cache.transaction.TransactionContext;
+import org.jboss.starobrno.context.TransactionContext;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java 2008-10-08 11:51:17 UTC (rev 6868)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -1,283 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.transaction;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.config.Option;
-import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
-
-import javax.transaction.Transaction;
-import java.util.List;
-
-/**
- * Captures information pertaining to a specific JTA transaction.
- * <p/>
- * This was a concrete class called TransactionEntry prior to 3.0.
- * <p/>
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @see org.jboss.cache.InvocationContext
- */
-public interface TransactionContext
-{
- /**
- * Adds a modification to the modification list.
- *
- * @param command modification
- */
- void addModification(WriteCommand command);
-
- /**
- * Returns all modifications. If there are no modifications in this transaction this method will return an empty list.
- *
- * @return list of modifications.
- */
- List<WriteCommand> getModifications();
-
- /**
- * Adds a modification to the local modification list.
- *
- * @param command command to add to list. Should not be null.
- * @throws NullPointerException if the command to be added is null.
- */
- void addLocalModification(WriteCommand command);
-
- /**
- * Returns all modifications that have been invoked with the LOCAL cache mode option. These will also be in the standard modification list.
- *
- * @return list of LOCAL modifications, or an empty list.
- */
- List<WriteCommand> getLocalModifications();
-
- /**
- * Adds the node that has been removed in the scope of the current transaction.
- *
- * @param fqn fqn that has been removed.
- * @throws NullPointerException if the Fqn is null.
- */
- void addRemovedNode(Fqn fqn);
-
- /**
- * Gets the list of removed nodes.
- *
- * @return list of nodes removed in the current transaction scope. Note that this method will return an empty list if nothing has been removed. The list returned is defensively copied.
- */
- List<Fqn> getRemovedNodes();
-
- /**
- * Sets the local transaction to be associated with this transaction context.
- *
- * @param tx JTA transaction to associate with.
- */
- void setTransaction(Transaction tx);
-
- /**
- * Returns a local transaction associated with this context.
- *
- * @return a JTA transaction
- */
- Transaction getTransaction();
-
- /**
- * Adds a lock to the currently maintained collection of locks acquired.
- * <p/>
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addLock(Object)} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- * <p/>
- * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
- * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
- * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
- *
- * @param lock lock to add
- * @see org.jboss.cache.InvocationContext#addLock(Object)
- */
- @SuppressWarnings("unchecked")
- void addLock(Object lock);
-
- /**
- * Removes a lock from the currently maintained collection of locks acquired.
- * <p/>
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#removeLock(Object)} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- * <p/>
- * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
- * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
- * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
- *
- * @param lock lock to remove
- * @see org.jboss.cache.InvocationContext#removeLock(Object)
- */
- @SuppressWarnings("unchecked")
- void removeLock(Object lock);
-
- /**
- * Clears all locks from the currently maintained collection of locks acquired.
- * <p/>
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#clearLocks()} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- * <p/>
- * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
- * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
- * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
- *
- * @see org.jboss.cache.InvocationContext#clearLocks()
- */
- void clearLocks();
-
- /**
- * Adds a List of locks to the currently maintained collection of locks acquired.
- * <p/>
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addAllLocks(java.util.List)} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- * <p/>
- * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
- * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
- * legacy node locking schemes are dropped, this method will be more strongly typed to accept <tt>List<Fqn></tt>.
- *
- * @param newLocks locks to add
- * @see org.jboss.cache.InvocationContext#addAllLocks(java.util.List)
- */
- @SuppressWarnings("unchecked")
- void addAllLocks(List newLocks);
-
- /**
- * Returns an immutable, defensive copy of the List of locks currently maintained for the transaction.
- * <p/>
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#getLocks()} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- * <p/>
- * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
- * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
- * legacy node locking schemes are dropped, this method will be more strongly typed to return <tt>List<Fqn></tt>.
- *
- * @return locks held in current scope.
- * @see org.jboss.cache.InvocationContext#getLocks()
- */
- @SuppressWarnings("unchecked")
- List getLocks();
-
- /**
- * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#hasLock(Object)} ()} instead,
- * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
- *
- * @param lock lock to test
- * @return true if the lock being tested is already held in the current scope, false otherwise.
- */
- boolean hasLock(Object lock);
-
- /**
- * Gets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
- * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
- * a transactional context.
- *
- * @return true if the forceAsyncReplication flag is set to true.
- */
- boolean isForceAsyncReplication();
-
- /**
- * Sets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
- * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
- * a transactional context. Also used by OptimisticReplicationInterceptor when dealing
- * with {@link org.jboss.cache.config.Option#setForceAsynchronous(boolean)} in a
- * non-transactional context (i.e. with an implicit transaction).
- *
- * @param forceAsyncReplication value of forceAsyncReplication
- */
- void setForceAsyncReplication(boolean forceAsyncReplication);
-
- /**
- * Gets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
- * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
- * a transactional context.
- *
- * @return true if the forceAsyncReplication flag is set to true.
- */
- boolean isForceSyncReplication();
-
- /**
- * Sets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
- * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
- * a transactional context.
- *
- * @param forceSyncReplication value of forceSyncReplication
- */
- void setForceSyncReplication(boolean forceSyncReplication);
-
- /**
- * Adds an Fqn to the list of uninitialized nodes created by the cache loader.
- *
- * @param fqn fqn to add. Must not be null.
- */
- void addDummyNodeCreatedByCacheLoader(Fqn fqn);
-
- /**
- * @return a list of uninitialized nodes created by the cache loader, or an empty list.
- */
- List<Fqn> getDummyNodesCreatedByCacheLoader();
-
- /**
- * Sets a transaction-scope option override
- *
- * @param o option to set
- */
- void setOption(Option o);
-
- /**
- * Retrieves a transaction scope option override
- *
- * @return option
- */
- Option getOption();
-
- /**
- * @return the ordered sync handler associated with this transaction
- */
- OrderedSynchronizationHandler getOrderedSynchronizationHandler();
-
- /**
- * Associates an ordered sync handler with this transaction.
- *
- * @param orderedSynchronizationHandler to set
- */
- void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler);
-
- /**
- * @return true if modifications were registered.
- */
- boolean hasModifications();
-
- /**
- * @return true if any modifications have been invoked with cache mode being LOCAL.
- */
- boolean hasLocalModifications();
-
- /**
- * @return true if either there are modifications or local modifications that are not for replicating.
- */
- boolean hasAnyModifications();
-
- /**
- * Cleans up internal state, freeing up references.
- */
- void reset();
-}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java 2008-10-08 11:53:03 UTC (rev 6869)
@@ -0,0 +1,427 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.transaction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.starobrno.context.TransactionContext;
+import org.jboss.starobrno.factories.context.ContextFactory;
+import org.jgroups.Address;
+
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Maintains the mapping between a local {@link Transaction} and a {@link GlobalTransaction}.
+ * Also stores {@link TransactionContext} instances under a given transaction.
+ *
+ * @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 14, 2003
+ * @version $Revision: 6776 $
+ */
+@NonVolatile
+public class TransactionTable
+{
+ private static final Log log = LogFactory.getLog(TransactionTable.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ /**
+ * Mapping between local (javax.transaction.Transaction)
+ * and GlobalTransactions.
+ * New: a local TX can have a number of GTXs
+ */
+ protected final Map<Transaction, GlobalTransaction> tx2gtxMap = new ConcurrentHashMap<Transaction, GlobalTransaction>();
+
+ /**
+ * Mappings between GlobalTransactions and modifications.
+ */
+ protected final Map<GlobalTransaction, TransactionContext> gtx2ContextMap = new ConcurrentHashMap<GlobalTransaction, TransactionContext>();
+
+ protected final Map<GlobalTransaction, Transaction> gtx2TxMap = new ConcurrentHashMap<GlobalTransaction, Transaction>();
+
+ private TransactionManager transactionManager = null;
+
+ private RPCManager rpcManager;
+
+ private ContextFactory contextFactory;
+
+ @Inject
+ public void initialize(TransactionManager transactionManager, RPCManager rpcManager, ContextFactory contextFactory)
+ {
+ this.transactionManager = transactionManager;
+ this.rpcManager = rpcManager;
+ this.contextFactory = contextFactory;
+ }
+
+ /**
+ * Returns the number of local transactions.
+ */
+ public int getNumLocalTransactions()
+ {
+ return tx2gtxMap.size();
+ }
+
+ /**
+ * Returns the number of global transactions.
+ */
+ public int getNumGlobalTransactions()
+ {
+ return gtx2ContextMap.size();
+ }
+
+ /**
+ * Returns the global transaction associated with the local transaction.
+ * Returns null if tx is null or it was not found.
+ */
+ public GlobalTransaction get(Transaction tx)
+ {
+ if (tx == null)
+ return null;
+ return tx2gtxMap.get(tx);
+ }
+
+ /**
+ * Returns the local transaction associated with a GlobalTransaction.
+ *
+ * @param gtx The GlobalTransaction
+ * @return Transaction. The local transaction associated with a given
+ * GlobalTransaction). This will be null if no local transaction is
+ * associated with a given GTX
+ */
+ public Transaction getLocalTransaction(GlobalTransaction gtx)
+ {
+ if (gtx == null) return null;
+ return gtx2TxMap.get(gtx);
+ }
+
+ /**
+ * If assers exists is true and the coresponding local transaction is null an IllegalStateExcetpion is being thrown.
+ */
+ public Transaction getLocalTransaction(GlobalTransaction gtx, boolean assertExists)
+ {
+ Transaction ltx = getLocalTransaction(gtx);
+ if (!assertExists)
+ {
+ return ltx;
+ }
+ if (ltx != null)
+ {
+ if (log.isDebugEnabled()) log.debug("Found local TX=" + ltx + ", global TX=" + gtx);
+ return ltx;
+ }
+ else
+ {
+ throw new IllegalStateException(" found no local TX for global TX " + gtx);
+ }
+ }
+
+ /**
+ * Associates the global transaction with the local transaction.
+ */
+ public void put(Transaction tx, GlobalTransaction gtx)
+ {
+ if (tx == null)
+ {
+ log.error("key (Transaction) is null");
+ return;
+ }
+ tx2gtxMap.put(tx, gtx);
+ gtx2TxMap.put(gtx, tx);
+ }
+
+ /**
+ * Returns the local transaction entry for the global transaction.
+ * Returns null if tx is null or it was not found.
+ */
+ public TransactionContext get(GlobalTransaction gtx)
+ {
+ return gtx != null ? gtx2ContextMap.get(gtx) : null;
+ }
+
+ /**
+ * Associates the global transaction with a transaction context.
+ */
+ public void put(GlobalTransaction tx, TransactionContext transactionContext)
+ {
+ if (tx == null)
+ {
+ log.error("key (GlobalTransaction) is null");
+ return;
+ }
+ gtx2ContextMap.put(tx, transactionContext);
+ }
+
+ /**
+ * Removes a global transation, returns the old transaction entry.
+ */
+ public TransactionContext remove(GlobalTransaction tx)
+ {
+ if (tx == null) return null;
+ gtx2TxMap.remove(tx);
+ return gtx2ContextMap.remove(tx);
+ }
+
+ /**
+ * Removes a local transation, returns the global transaction entry.
+ */
+ public GlobalTransaction remove(Transaction tx)
+ {
+ if (tx == null)
+ return null;
+ return tx2gtxMap.remove(tx);
+ }
+
+ public void remove(GlobalTransaction gtx, Transaction tx)
+ {
+ gtx2TxMap.remove(gtx);
+ gtx2ContextMap.remove(gtx);
+ tx2gtxMap.remove(tx);
+ }
+
+ /**
+ * Returns summary debug information.
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append(tx2gtxMap.size()).append(" mappings, ");
+ sb.append(gtx2ContextMap.size()).append(" transactions");
+ return sb.toString();
+ }
+
+ /**
+ * Returns detailed debug information.
+ */
+ public String toString(boolean printDetails)
+ {
+ if (!printDetails)
+ return toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append("LocalTransactions: ").append(tx2gtxMap.size()).append("\n");
+ sb.append("GlobalTransactions: ").append(gtx2ContextMap.size()).append("\n");
+ sb.append("tx2gtxMap:\n");
+ for (Map.Entry<Transaction, GlobalTransaction> entry : tx2gtxMap.entrySet())
+ {
+ sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
+ }
+ sb.append("gtx2EntryMap:\n");
+ for (Map.Entry<GlobalTransaction, TransactionContext> transactionContextEntry : gtx2ContextMap.entrySet())
+ {
+ sb.append(transactionContextEntry.getKey()).append(": ").append(transactionContextEntry.getValue()).append("\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns the transaction associated with the current thread.
+ * If a local transaction exists, but doesn't yet have a mapping to a
+ * GlobalTransaction, a new GlobalTransaction will be created and mapped to
+ * the local transaction. Note that if a local transaction exists, but is
+ * not ACTIVE or PREPARING, null is returned.
+ *
+ * @return A GlobalTransaction, or null if no (local) transaction was associated with the current thread
+ */
+ public GlobalTransaction getCurrentTransaction()
+ {
+ return getCurrentTransaction(true);
+ }
+
+
+ /**
+ * Returns the transaction associated with the thread; optionally creating
+ * it if is does not exist.
+ */
+ public GlobalTransaction getCurrentTransaction(boolean createIfNotExists)
+ {
+ Transaction tx;
+
+ if ((tx = getLocalTransaction()) == null)
+ {// no transaction is associated with the current thread
+ return null;
+ }
+
+ if (!isValid(tx))
+ {// we got a non-null transaction, but it is not active anymore
+ int status = -1;
+ try
+ {
+ status = tx.getStatus();
+ }
+ catch (SystemException e)
+ {
+ }
+
+ // JBCACHE-982 -- don't complain if COMMITTED
+ if (status != Status.STATUS_COMMITTED)
+ {
+ log.warn("status is " + status + " (not ACTIVE or PREPARING); returning null)");
+ }
+ else
+ {
+ log.trace("status is COMMITTED; returning null");
+ }
+
+ return null;
+ }
+
+ return getCurrentTransaction(tx, createIfNotExists);
+ }
+
+ /**
+ * Returns the transaction associated with the current thread. We get the
+ * initial context and a reference to the TransactionManager to get the
+ * transaction. This method is used by {@link #getCurrentTransaction()}
+ */
+ protected Transaction getLocalTransaction()
+ {
+ if (transactionManager == null)
+ {
+ return null;
+ }
+ try
+ {
+ return transactionManager.getTransaction();
+ }
+ catch (Throwable t)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns true if transaction is ACTIVE, false otherwise
+ */
+ public static boolean isActive(Transaction tx)
+ {
+ if (tx == null) return false;
+ int status;
+ try
+ {
+ status = tx.getStatus();
+ return status == Status.STATUS_ACTIVE;
+ }
+ catch (SystemException e)
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Returns true if transaction is PREPARING, false otherwise
+ */
+ public static boolean isPreparing(Transaction tx)
+ {
+ if (tx == null) return false;
+ int status;
+ try
+ {
+ status = tx.getStatus();
+ return status == Status.STATUS_PREPARING;
+ }
+ catch (SystemException e)
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Return s true of tx's status is ACTIVE or PREPARING
+ *
+ * @param tx
+ * @return true if the tx is active or preparing
+ */
+ public static boolean isValid(Transaction tx)
+ {
+ return isActive(tx) || isPreparing(tx);
+ }
+
+ /**
+ * Tests whether the caller is in a valid transaction. If not, will throw a CacheException.
+ */
+ public static void assertTransactionValid(InvocationContext ctx)
+ {
+ Transaction tx = ctx.getTransaction();
+ if (!isValid(tx)) try
+ {
+ throw new CacheException("Invalid transaction " + tx + ", status = " + (tx == null ? null : tx.getStatus()));
+ }
+ catch (SystemException e)
+ {
+ throw new CacheException("Exception trying to analyse status of transaction " + tx, e);
+ }
+ }
+
+
+ /**
+ * Returns the global transaction for this local transaction.
+ */
+ public GlobalTransaction getCurrentTransaction(Transaction tx)
+ {
+ return getCurrentTransaction(tx, true);
+ }
+
+ /**
+ * Returns the global transaction for this local transaction.
+ *
+ * @param createIfNotExists if true, if a global transaction is not found; one is created
+ */
+ public GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists)
+ {
+ // removed synchronization on txTable because underlying implementation is thread safe
+ // and JTA spec (section 3.4.3 Thread of Control, par 2) says that only one thread may
+ // operate on the transaction at one time so no concern about 2 threads trying to call
+ // this method for the same Transaction instance at the same time
+ //
+ GlobalTransaction gtx = get(tx);
+ if (gtx == null && createIfNotExists)
+ {
+ Address addr = rpcManager.getLocalAddress();
+ gtx = GlobalTransaction.create(addr);
+ put(tx, gtx);
+ TransactionContext transactionContext;
+ try
+ {
+ transactionContext = contextFactory.createTransactionContext(tx);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to create a transaction entry!", e);
+ }
+
+ put(gtx, transactionContext);
+ if (trace)
+ {
+ log.trace("created new GTX: " + gtx + ", local TX=" + tx);
+ }
+ }
+ return gtx;
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6868 - benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 07:51:17 -0400 (Wed, 08 Oct 2008)
New Revision: 6868
Modified:
benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml
Log:
updated
Modified: benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml 2008-10-08 11:30:17 UTC (rev 6867)
+++ benchmarks/benchmark-fwk/trunk/cache-products/jbosscache-3.0.0/conf/mvcc-repl-async.xml 2008-10-08 11:51:17 UTC (rev 6868)
@@ -34,6 +34,6 @@
</jgroupsConfig>
</transport>
<replication>
- <async useReplQueue="true" replQueueInterval="3000" replQueueMaxElements="30000"/>
+ <async useReplQueue="true" replQueueInterval="1000" replQueueMaxElements="500000"/>
</replication>
</jbosscache>
16 years, 2 months
JBoss Cache SVN: r6867 - core/branches/flat/src/main/java/org/jboss/starobrno/commands/read.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 07:30:17 -0400 (Wed, 08 Oct 2008)
New Revision: 6867
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
Log:
_____ ____ ____
\/__/\ \ \ \L\ \\ \ \/\_\
_\ \ \ \ _ <'\ \ \/_/_
/\ \_\ \ \ \L\ \\ \ \L\ \
\ \____/\ \____/ \ \____/
\/___/ \/___/ \/___/
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 11:30:17 UTC (rev 6867)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.read;
+
+import org.jboss.starobrno.commands.DataCommand;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public abstract class AbstractDataCommand implements DataCommand
+{
+ protected Object key;
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbstractDataCommand(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbstractDataCommand()
+ {
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ if (commandId != getCommandId()) throw new IllegalStateException("Invalid method id");
+ key = parameters[0];
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{key};
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6866 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 07:29:20 -0400 (Wed, 08 Oct 2008)
New Revision: 6866
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
Log:
_____ ____ ____
\/__/\ \ \ \L\ \\ \ \/\_\
_\ \ \ \ _ <'\ \ \/_/_
/\ \_\ \ \ \L\ \\ \ \L\ \
\ \____/\ \____/ \ \____/
\/___/ \/___/ \/___/
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 11:15:39 UTC (rev 6865)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -40,6 +40,7 @@
{
// PutKeyValueCommand
InvocationContext ctx = invocationContextContainer.get();
+
return null;
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java 2008-10-08 11:15:39 UTC (rev 6865)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -22,27 +22,19 @@
package org.jboss.starobrno.commands;
import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.*;
-/**
- * This interface is the core of JBoss Cache, where each {@link org.jboss.cache.commands.VisitableCommand} can be visited by a Visitor implementation.
- * Visitors which are accepted by the {@link org.jboss.cache.commands.VisitableCommand} are able to modify the command
- * based on any logic encapsulated by the visitor.
- *
- * @author Mircea.Markus(a)jboss.com
- * @author Manik Surtani
- * @since 2.2.0
- */
public interface Visitor
{
-
- /**
- * Visits a PutKeyValueCommand.
- *
- * @param ctx invocation context
- * @param command command to visit
- * @return response from the visit
- * @throws Throwable in the event of problems.
- */
Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable;
+
+ Object visitRemoveCommand(InvocationContext ctx, RemoveCommand removeCommand);
+
+ Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand replaceCommand);
+
+ Object visitClearCommand(InvocationContext ctx, ClearCommand clearCommand);
+
+ Object visitPutMapCommand(InvocationContext ctx, PutMapCommand putMapCommand);
+
+ Object visitEvictCommand(InvocationContext ctx, Visitor visitor);
}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ClearCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.write;
+
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ClearCommand implements VisitableCommand
+{
+ public static final Object[] params = new Object[0];
+
+ public static final int METHOD_ID = 17;
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitClearCommand(ctx, this);
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ throw new NotImplementedException("Not Implemented");//todo implement
+ }
+
+ public Object[] getParameters()
+ {
+ return params;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ if (commandId != METHOD_ID) throw new IllegalStateException("Invalid method id");
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/EvictCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.write;
+
+import org.jboss.starobrno.commands.read.AbstractDataCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class EvictCommand extends AbstractDataCommand
+{
+ public static final int METHOD_ID = 3000;
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitEvictCommand(ctx, visitor);
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ throw new NotImplementedException("Not Implemented");//todo implement
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-10-08 11:15:39 UTC (rev 6865)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -21,20 +21,11 @@
*/
package org.jboss.starobrno.commands.write;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.NodeNotExistsException;
-import org.jboss.cache.NodeSPI;
-
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.commands.read.AbstractDataCommand;
import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
-import java.util.Collections;
-import java.util.Map;
-
/**
* Implements functionality defined by {@link org.jboss.cache.Cache#put(org.jboss.cache.Fqn, Object, Object)}.
*
@@ -44,99 +35,33 @@
public class PutKeyValueCommand extends AbstractDataCommand
{
public static final int METHOD_ID = 3;
- public static final int VERSIONED_METHOD_ID = 39;
- private static final Log log = LogFactory.getLog(org.jboss.cache.commands.write.PutKeyValueCommand.class);
- private static final boolean trace = log.isTraceEnabled();
-
- /* parametres */
- protected Object key;
protected Object value;
- public PutKeyValueCommand(GlobalTransaction gtx, Object key, Object value)
- {
- this.key = key;
- this.value = value;
- }
-
- public PutKeyValueCommand()
- {
- }
-
- /**
- * Puts the specified key and value into the data map in the node referenced by the specified Fqn.
- *
- * @param ctx invocation context
- * @return the value being overwritten, if any, otherwise a null.
- */
- public Object perform(InvocationContext ctx)
- {
- if (trace) log.trace("Perform(, k='" + key + "', v='" + value + "')");
- return null;
- }
-
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
{
return visitor.visitPutKeyValueCommand(ctx, this);
}
- public Object getKey()
+ public Object perform(InvocationContext ctx) throws Throwable
{
- return key;
+ throw new NotImplementedException("Not Implemented");//todo implement
}
- public Object getValue()
- {
- return value;
- }
-
- public void setKey(Object key)
- {
- this.key = key;
- }
-
- public void setValue(Object value)
- {
- this.value = value;
- }
-
public int getCommandId()
{
return METHOD_ID;
}
- @Override
public Object[] getParameters()
{
- return new Object[]{key, value, false};
+ return new Object[] {key, value};
}
- @Override
- public void setParameters(int commandId, Object[] args)
+ public void setParameters(int commandId, Object[] parameters)
{
- key = args[0];
- value = args[1];
+ if (commandId != METHOD_ID) throw new IllegalStateException("Invalid method id");
+ key = parameters[0];
+ value = parameters[1];
}
-
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- if (!super.equals(o)) return false;
-
- PutKeyValueCommand that = (PutKeyValueCommand) o;
-
- if (key != null ? !key.equals(that.key) : that.key != null) return false;
- if (value != null ? !value.equals(that.value) : that.value != null) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- int result = super.hashCode();
- result = 31 * result + (key != null ? key.hashCode() : 0);
- result = 31 * result + (value != null ? value.hashCode() : 0);
- return result;
- }
}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutMapCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.write;
+
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
+
+import java.util.Map;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class PutMapCommand implements VisitableCommand
+{
+ public static final int METHOD_ID = 2000;
+
+ private Map map;
+
+ public PutMapCommand(Map map)
+ {
+ this.map = map;
+ }
+
+ public PutMapCommand()
+ {
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitPutMapCommand(ctx, this);
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ throw new NotImplementedException("Not Implemented");//todo implement
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[] {map};
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ if (commandId != METHOD_ID) throw new IllegalStateException("Invalid method id");
+ map = (Map) parameters[0];
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.write;
+
+import org.jboss.starobrno.commands.read.AbstractDataCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
+
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class RemoveCommand extends AbstractDataCommand
+{
+ public static final int METHOD_ID = 6;
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitRemoveCommand(ctx, this);
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ throw new NotImplementedException("Not Implemented");//todo implement
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/ReplaceCommand.java 2008-10-08 11:29:20 UTC (rev 6866)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.write;
+
+import org.jboss.starobrno.commands.read.AbstractDataCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.util.NotImplementedException;
+
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ReplaceCommand extends AbstractDataCommand
+{
+ public static final int METHOD_ID = 99;
+
+ protected Object oldValue;
+ protected Object newValue;
+
+ public ReplaceCommand(Object key, Object oldValue, Object newValue)
+ {
+ super(key);
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public ReplaceCommand()
+ {
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitReplaceCommand(ctx, this);
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ throw new NotImplementedException("Not Implemented");//todo implement
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[] {key, oldValue, newValue};
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ if (commandId != METHOD_ID) throw new IllegalArgumentException("Invalid method name");
+ key = parameters[0];
+ oldValue = parameters[1];
+ newValue = parameters[2];
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6865 - core/branches/flat/src/main/java/org/jboss/starobrno/commands/read.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 07:15:39 -0400 (Wed, 08 Oct 2008)
New Revision: 6865
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
Log:
Removed useless abstract class
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 11:14:14 UTC (rev 6864)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 11:15:39 UTC (rev 6865)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.commands.read;
-
-import org.jboss.starobrno.commands.DataCommand;
-
-/**
- * @author Mircea.Markus(a)jboss.com
- */
-public abstract class AbstractDataCommand implements DataCommand
-{
- protected Object key;
-
- public Object getKey()
- {
- return key;
- }
-
- public void setKey(Object key)
- {
- this.key = key;
- }
-
- protected AbstractDataCommand(Object key)
- {
- this.key = key;
- }
-
- protected AbstractDataCommand()
- {
- }
-}
16 years, 2 months
JBoss Cache SVN: r6864 - in core/branches/flat/src/main/java/org/jboss/starobrno: mvcc and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 07:14:14 -0400 (Wed, 08 Oct 2008)
New Revision: 6864
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java
Log:
Updated factory + entry wrapper
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactory.java 2008-10-08 11:14:14 UTC (rev 6864)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+import java.util.Map.Entry;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface EntryFactory
+{
+ Entry createEntry(Object key, Object value, boolean putInContainer);
+
+ MVCCEntry createWrappedEntry(Entry entry);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java 2008-10-08 11:14:14 UTC (rev 6864)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.mvcc.EntryImpl;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+import org.jboss.starobrno.mvcc.NullMarkerEntry;
+import org.jboss.starobrno.mvcc.ReadCommittedEntry;
+import org.jboss.starobrno.mvcc.RepeatableReadEntry;
+
+import java.util.Map.Entry;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class EntryFactoryImpl implements EntryFactory
+{
+ private boolean useRepeatableRead;
+ private static final NullMarkerEntry NULL_MARKER = new NullMarkerEntry();
+ private DataContainer dataContainer;
+ private Configuration configuration;
+
+ @Inject
+ public void injectDependencies(Configuration configuration,
+ DataContainer dataContainer)
+ {
+ this.dataContainer = dataContainer;
+ this.configuration = configuration;
+ }
+
+ @Start
+ public void init()
+ {
+ useRepeatableRead = configuration.getIsolationLevel() == IsolationLevel.REPEATABLE_READ;
+ }
+
+ public Entry createEntry(Object key, Object value, boolean putInContainer)
+ {
+ Entry e = new EntryImpl(key, value);
+ if (putInContainer) dataContainer.putEntry(e);
+ return e;
+ }
+
+ public MVCCEntry createWrappedEntry(Entry entry)
+ {
+ if (entry == null) return useRepeatableRead ? NULL_MARKER : null;
+
+ MVCCEntry mvccEntry = useRepeatableRead ? new RepeatableReadEntry(entry) : new ReadCommittedEntry(entry);
+ return mvccEntry;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java 2008-10-08 11:14:14 UTC (rev 6864)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.mvcc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.lock.TimeoutException;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.EntryFactory;
+import org.jboss.starobrno.lock.LockManager;
+
+import java.util.Map.Entry;
+
+/**
+ * Wraps mvcc entries.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class MVCCEntryWrapper
+{
+ DataContainer container;
+ boolean writeSkewCheck;
+ LockManager lockManager;
+ Configuration configuration;
+ long defaultLockAcquisitionTimeout;
+ EntryFactory entryFactory;
+
+ private static final Log log = LogFactory.getLog(MVCCEntryWrapper.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+
+ @Inject
+ public void injectDependencies(DataContainer dataContainer, LockManager lockManager, Configuration configuration, EntryFactory entryFactory)
+ {
+ this.container = dataContainer;
+ this.configuration = configuration;
+ this.lockManager = lockManager;
+ this.entryFactory = entryFactory;
+ }
+
+ @Start
+ public void start()
+ {
+ defaultLockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
+ writeSkewCheck = configuration.isWriteSkewCheck();
+ }
+
+ public MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException
+ {
+ return wrapEntryForReading(ctx, key, putInContext, false);
+ }
+
+ public MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException
+ {
+ // TODO: Do we need to wrap for reading if we are not in a TX?
+ // TODO: Also, do we need to wrap for reading even IN a TX if we are using read-committed?
+
+ MVCCEntry mvccEntry;
+ if (forceWriteLock)
+ {
+ if (trace) log.trace("Forcing lock on reading key " + key);
+ return wrapEntryForWriting(ctx, key, false, false);
+ }
+ else if ((mvccEntry = ctx.lookupEntry(key)) == null)
+ {
+ if (trace) log.trace("Key " + key + " is not in context, fetching from container.");
+ // simple implementation. Peek the node, wrap it, put wrapped node in the context.
+ Entry entry = container.getEntry(key);
+ mvccEntry = entryFactory.createWrappedEntry(entry);
+ if (mvccEntry != null && putInContext) ctx.putLookedUpEntry(mvccEntry);
+ return mvccEntry;
+ }
+ else
+ {
+ if (trace) log.trace("Key " + key + " is already in context.");
+ return mvccEntry;
+ }
+ }
+
+ public MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent) throws InterruptedException
+ {
+ MVCCEntry mvccEntry = ctx.lookupEntry(key);
+ if (createIfAbsent && mvccEntry != null && mvccEntry.isNullEntry()) mvccEntry = null;
+ if (mvccEntry != null) // exists in context! Just acquire lock if needed, and wrap.
+ {
+ // acquire lock if needed
+ if (acquireLock(ctx, key))
+ {
+ // create a copy of the underlying node
+ mvccEntry.copyForUpdate(container, writeSkewCheck);
+ }
+ if (trace) log.trace("Retrieving wrapped node " + key);
+ if (mvccEntry.isDeleted() && createIfAbsent)
+ {
+ if (trace) log.trace("Node is deleted in current scope. Need to un-delete.");
+ mvccEntry.setDeleted(false);
+ mvccEntry.setValid(true);
+ }
+ }
+ else
+ {
+ // else, fetch from dataContainer.
+ Entry entry = container.getEntry(key);
+ if (entry != null)
+ {
+ // exists in cache! Just acquire lock if needed, and wrap.
+ // do we need a lock?
+ boolean needToCopy = false;
+ if (acquireLock(ctx, key)) needToCopy = true;
+ mvccEntry = entryFactory.createWrappedEntry(entry);
+ ctx.putLookedUpEntry(mvccEntry);
+ if (needToCopy) mvccEntry.copyForUpdate(container, writeSkewCheck);
+ }
+ else if (createIfAbsent) // else, do we need to create one?
+ {
+ // now to lock and create the node. Lock first to prevent concurrent creation!
+ acquireLock(ctx, key);
+ entry = entryFactory.createEntry(key, null, true);
+ mvccEntry = entryFactory.createWrappedEntry(entry);
+ mvccEntry.setCreated(true);
+ ctx.putLookedUpEntry(mvccEntry);
+ mvccEntry.copyForUpdate(container, writeSkewCheck);
+ }
+ }
+
+ // see if we need to force the lock on nonexistent entries.
+ if (mvccEntry == null && forceLockIfAbsent) acquireLock(ctx, key);
+
+ return mvccEntry;
+ }
+
+ /**
+ * Attempts to lock a node if the lock isn't already held in the current scope, and records the lock in the context.
+ *
+ * @param ctx context
+ * @param fqn Fqn to lock
+ * @return true if a lock was needed and acquired, false if it didn't need to acquire the lock (i.e., lock was already held)
+ * @throws InterruptedException if interrupted
+ * @throws org.jboss.cache.lock.TimeoutException
+ * if we are unable to acquire the lock after a specified timeout.
+ */
+ private boolean acquireLock(InvocationContext ctx, Object key) throws InterruptedException, TimeoutException
+ {
+ // don't EVER use lockManager.isLocked() since with lock striping it may be the case that we hold the relevant
+ // lock which may be shared with another Fqn that we have a lock for already.
+ // nothing wrong, just means that we fail to record the lock. And that is a problem.
+ // Better to check our records and lock again if necessary.
+ if (!ctx.hasLockedKey(key))
+ {
+ if (!lockManager.lockAndRecord(key, ctx))
+ {
+ Object owner = lockManager.getOwner(key);
+ throw new TimeoutException("Unable to acquire lock on key [" + key + "] after [" + ctx.getLockAcquisitionTimeout(defaultLockAcquisitionTimeout) + "] milliseconds for requestor [" + lockManager.getLockOwner(ctx) + "]! Lock held by [" + owner + "]");
+ }
+ return true;
+ }
+ return false;
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6863 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 07:13:44 -0400 (Wed, 08 Oct 2008)
New Revision: 6863
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
Log:
New commands + data container
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java 2008-10-08 10:46:56 UTC (rev 6862)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -39,4 +39,6 @@
void putEntry(Entry<K, V> entry);
boolean exists(Entry<K, V> entry);
+
+ int size();
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java 2008-10-08 10:46:56 UTC (rev 6862)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -21,9 +21,10 @@
*/
package org.jboss.starobrno;
-import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
/**
* // TODO: crappy and inefficient - but just a placeholder for now.
@@ -33,17 +34,17 @@
*/
public class UnsortedDataContainer<K, V> implements DataContainer<K, V>
{
- Set<Entry<K, V>> entries = new LinkedHashSet<Entry<K, V>>();
+ private final ConcurrentMap<K, V> data = new ConcurrentHashMap<K, V>();
public Set<Entry<K, V>> getEntries()
{
- return entries;
+ return data.entrySet();
}
public Entry<K, V> getEntry(K k)
{
if (k == null) throw new NullPointerException("I don't like nulls!");
- for (Entry<K, V> e : entries)
+ for (Entry<K, V> e : data.entrySet())
{
if (k.equals(e.getKey())) return e;
}
@@ -52,11 +53,16 @@
public void putEntry(Entry<K, V> kvEntry)
{
- entries.add(kvEntry);
+ data.put(kvEntry.getKey(), kvEntry.getValue());
}
public boolean exists(Entry<K, V> kvEntry)
{
- return getEntry(kvEntry.getKey()) != null;
+ return data.containsKey(kvEntry.getKey());
}
+
+ public int size()
+ {
+ return data.size();
+ }
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/TransactionBoundaryCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands;
+
+import org.jboss.cache.transaction.GlobalTransaction;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface TransactionBoundaryCommand extends ReplicableCommand
+{
+ GlobalTransaction getGlobalTransaction();
+
+ void setGlobalTransaction(GlobalTransaction gtx);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/GetKeyValueCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.read;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.notifications.Notifier;
+import org.jboss.starobrno.commands.DataCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class GetKeyValueCommand implements DataCommand
+{
+ protected Object key;
+ public static final int METHOD_ID = 26;
+ private static final Log log = LogFactory.getLog(GetKeyValueCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+ private Notifier notifier;
+
+ public GetKeyValueCommand(Object key, Notifier notifier)
+ {
+ this.key = key;
+ this.notifier = notifier;
+ }
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ MVCCEntry entry = ctx.lookupEntry(key);
+ if (entry == null || entry.isNullEntry())
+ {
+ if (trace) log.trace("Node not found");
+ return null;
+ }
+ if (entry.isDeleted())
+ {
+ if (trace) log.trace("Entry has been deleted and is of type " + entry.getClass().getSimpleName());
+ return null;
+ }
+ // TODO - notifier stuff
+ // notifier.notifyNodeVisited(fqn, true, ctx);
+ Object result = entry.getValue();
+ if (trace) log.trace("Found value " + result);
+// if (sendNodeEvent) notifier.notifyNodeVisited(fqn, false, ctx);
+ return result;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{key};
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ this.key = parameters[0];
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/SizeCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.read;
+
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class SizeCommand implements VisitableCommand
+{
+ private DataContainer container;
+
+ public SizeCommand(DataContainer container)
+ {
+ this.container = container;
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ return container.size();
+ }
+
+ public int getCommandId()
+ {
+ return 0; // no-op
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[0]; // no-op
+ }
+
+ public void setParameters(int commandId, Object[] parameters)
+ {
+ // no-op
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/AbstractTransactionBoundaryCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.tx;
+
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.TransactionBoundaryCommand;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public abstract class AbstractTransactionBoundaryCommand implements TransactionBoundaryCommand
+{
+ GlobalTransaction gtx;
+
+ public GlobalTransaction getGlobalTransaction()
+ {
+ return gtx;
+ }
+
+ public void setGlobalTransaction(GlobalTransaction gtx)
+ {
+ this.gtx = gtx;
+ }
+
+ /**
+ * This is a no-op.
+ *
+ * @param ctx
+ * @return
+ * @throws Throwable
+ */
+ public Object perform(InvocationContext ctx) throws Throwable
+ {
+ return null;
+ }
+
+ public Object[] getParameters()
+ {
+ return new Object[]{gtx};
+ }
+
+ public void setParameters(int commandId, Object[] args)
+ {
+ gtx = (GlobalTransaction) args[0];
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/CommitCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.tx;
+
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class CommitCommand extends AbstractTransactionBoundaryCommand
+{
+ public static final int METHOD_ID = 11;
+
+ public CommitCommand(GlobalTransaction gtx)
+ {
+ this.gtx = gtx;
+ }
+
+ public CommitCommand()
+ {
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ // TODO - implement me
+ return null;
+// return visitor.visitCommitCommand(ctx, this);
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.tx;
+
+import org.jboss.cache.commands.WriteCommand;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.ReplicableCommand;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jgroups.Address;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class PrepareCommand extends AbstractTransactionBoundaryCommand
+{
+ public static final int METHOD_ID = 10;
+
+ protected List<ReplicableCommand> modifications;
+ protected Address localAddress;
+ protected boolean onePhaseCommit;
+
+ public PrepareCommand(GlobalTransaction gtx, List<ReplicableCommand> modifications, Address localAddress, boolean onePhaseCommit)
+ {
+ this.gtx = gtx;
+ this.modifications = modifications;
+ this.localAddress = localAddress;
+ this.onePhaseCommit = onePhaseCommit;
+ }
+
+ public void removeModifications(Collection<WriteCommand> modificationsToRemove)
+ {
+ if (modifications != null) modifications.removeAll(modificationsToRemove);
+ }
+
+ public PrepareCommand()
+ {
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ // TODO - implement me
+ return null;
+// return visitor.visitPrepareCommand(ctx, this);
+ }
+
+ public List<ReplicableCommand> getModifications()
+ {
+ return modifications;
+ }
+
+ public Address getLocalAddress()
+ {
+ return localAddress;
+ }
+
+ public boolean isOnePhaseCommit()
+ {
+ return onePhaseCommit;
+ }
+
+ public boolean existModifications()
+ {
+ return modifications != null && modifications.size() > 0;
+ }
+
+ public int getModificationsCount()
+ {
+ return modifications != null ? modifications.size() : 0;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ @Override
+ public Object[] getParameters()
+ {
+ return new Object[]{gtx, modifications, localAddress, onePhaseCommit};
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void setParameters(int commandId, Object[] args)
+ {
+ gtx = (GlobalTransaction) args[0];
+ modifications = (List<ReplicableCommand>) args[1];
+ localAddress = (Address) args[2];
+ onePhaseCommit = (Boolean) args[3];
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ PrepareCommand that = (PrepareCommand) o;
+
+ if (onePhaseCommit != that.onePhaseCommit) return false;
+ if (localAddress != null ? !localAddress.equals(that.localAddress) : that.localAddress != null) return false;
+ if (modifications != null ? !modifications.equals(that.modifications) : that.modifications != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (modifications != null ? modifications.hashCode() : 0);
+ result = 31 * result + (localAddress != null ? localAddress.hashCode() : 0);
+ result = 31 * result + (onePhaseCommit ? 1 : 0);
+ return result;
+ }
+
+ public PrepareCommand copy()
+ {
+ PrepareCommand copy = new PrepareCommand();
+ copy.gtx = gtx;
+ copy.localAddress = localAddress;
+ copy.modifications = modifications == null ? null : new ArrayList<ReplicableCommand>(modifications);
+ copy.onePhaseCommit = onePhaseCommit;
+ return copy;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "PrepareCommand{" +
+ "globalTransaction=" + gtx +
+ ", modifications=" + modifications +
+ ", localAddress=" + localAddress +
+ ", onePhaseCommit=" + onePhaseCommit +
+ '}';
+ }
+
+ public boolean containsModificationType(Class<? extends ReplicableCommand> replicableCommandClass)
+ {
+ for (ReplicableCommand mod : getModifications())
+ {
+ if (mod.getClass().equals(replicableCommandClass))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/RollbackCommand.java 2008-10-08 11:13:44 UTC (rev 6863)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.commands.tx;
+
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.Visitor;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class RollbackCommand extends AbstractTransactionBoundaryCommand
+{
+ public static final int METHOD_ID = 12;
+
+ public RollbackCommand(GlobalTransaction globalTransaction)
+ {
+ this.gtx = globalTransaction;
+ }
+
+ public RollbackCommand()
+ {
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ // TODO - implement me
+ return null;
+// return visitor.visitRollbackCommand(ctx, this);
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+}
16 years, 2 months