[jbosscache-commits] JBoss Cache SVN: r6876 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands/tx and 4 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Oct 8 10:58:37 EDT 2008
Author: mircea.markus
Date: 2008-10-08 10:58:36 -0400 (Wed, 08 Oct 2008)
New Revision: 6876
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CallInterceptor.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.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/interceptors/base/CommandInterceptor.java
Log:
dropped WriteCommand
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java 2008-10-08 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -1,48 +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.commands;
-
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.commands.*;
-import org.jboss.cache.commands.DataCommand;
-
-/**
- * A write command that has a reference to a {@link org.jboss.cache.transaction.GlobalTransaction}.
- *
- * @author Mircea.Markus at jboss.com
- * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
- * @since 2.2.0
- */
-public interface WriteCommand extends DataCommand
-{
- /**
- * @return a GlobalTransaction associated with this command.
- */
- GlobalTransaction getGlobalTransaction();
-
- /**
- * Sets a GlobalTransaction on this command.
- *
- * @param gtx global transaction to set
- */
- void setGlobalTransaction(GlobalTransaction gtx);
-}
\ No newline at end of file
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 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/tx/PrepareCommand.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.commands.tx;
+import org.jboss.starobrno.commands.DataCommand;
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;
@@ -42,11 +42,11 @@
{
public static final int METHOD_ID = 10;
- protected List<WriteCommand> modifications;
+ protected List<DataCommand> modifications;
protected Address localAddress;
protected boolean onePhaseCommit;
- public PrepareCommand(GlobalTransaction gtx, List<WriteCommand> modifications, Address localAddress, boolean onePhaseCommit)
+ public PrepareCommand(GlobalTransaction gtx, List<DataCommand> modifications, Address localAddress, boolean onePhaseCommit)
{
this.gtx = gtx;
this.modifications = modifications;
@@ -54,7 +54,7 @@
this.onePhaseCommit = onePhaseCommit;
}
- public void removeModifications(Collection<WriteCommand> modificationsToRemove)
+ public void removeModifications(Collection<DataCommand> modificationsToRemove)
{
if (modifications != null) modifications.removeAll(modificationsToRemove);
}
@@ -68,7 +68,7 @@
return visitor.visitPrepareCommand(ctx, this);
}
- public List<WriteCommand> getModifications()
+ public List<DataCommand> getModifications()
{
return modifications;
}
@@ -109,7 +109,7 @@
public void setParameters(int commandId, Object[] args)
{
gtx = (GlobalTransaction) args[0];
- modifications = (List<WriteCommand>) args[1];
+ modifications = (List<DataCommand>) args[1];
localAddress = (Address) args[2];
onePhaseCommit = (Boolean) args[3];
}
@@ -145,7 +145,7 @@
PrepareCommand copy = new PrepareCommand();
copy.gtx = gtx;
copy.localAddress = localAddress;
- copy.modifications = modifications == null ? null : new ArrayList<WriteCommand>(modifications);
+ copy.modifications = modifications == null ? null : new ArrayList<DataCommand>(modifications);
copy.onePhaseCommit = onePhaseCommit;
return copy;
}
@@ -163,7 +163,7 @@
public boolean containsModificationType(Class<? extends ReplicableCommand> replicableCommandClass)
{
- for (WriteCommand mod : getModifications())
+ for (DataCommand mod : getModifications())
{
if (mod.getClass().equals(replicableCommandClass))
{
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 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/RemoveCommand.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -30,7 +30,7 @@
/**
* @author Mircea.Markus at jboss.com
*/
-public class RemoveCommand extends AbstractDataCommand
+public class RemoveCommand extends AbstractDataCommand
{
public static final int METHOD_ID = 6;
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 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -23,7 +23,7 @@
import org.jboss.cache.config.Option;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
-import org.jboss.starobrno.commands.WriteCommand;
+import org.jboss.starobrno.commands.VisitableCommand;
import javax.transaction.Transaction;
import java.util.List;
@@ -44,14 +44,14 @@
*
* @param command modification
*/
- void addModification(WriteCommand command);
+ void addModification(VisitableCommand 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();
+ List<VisitableCommand> getModifications();
/**
* Adds a modification to the local modification list.
@@ -59,14 +59,14 @@
* @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);
+ void addLocalModification(VisitableCommand 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();
+ List<VisitableCommand> getLocalModifications();
/**
* Adds the node that has been removed in the scope of the current transaction.
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 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -24,20 +24,13 @@
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.commands.VisitableCommand;
import org.jboss.starobrno.mvcc.MVCCEntry;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* A transaction context specially geared to dealing with MVCC.
@@ -60,11 +53,11 @@
/**
* List<ReversibleCommand> of modifications ({@link org.jboss.cache.commands.WriteCommand}). They will be replicated on TX commit
*/
- private List<WriteCommand> modificationList;
+ private List<VisitableCommand> modificationList;
/**
* A list of modifications that have been encountered with a LOCAL mode option. These will be removed from the modification list during replication.
*/
- private List<WriteCommand> localModifications;
+ private List<VisitableCommand> localModifications;
/**
* LinkedHashSet of locks acquired by the transaction. We use a LinkedHashSet because we need efficient Set semantics
@@ -167,27 +160,27 @@
for (MVCCEntry e : entries) lookedUpEntries.put(e.getKey(), e);
}
- public void addModification(WriteCommand command)
+ public void addModification(VisitableCommand command)
{
if (command == null) return;
- if (modificationList == null) modificationList = new LinkedList<WriteCommand>();
+ if (modificationList == null) modificationList = new LinkedList<VisitableCommand>();
modificationList.add(command);
}
- public List<WriteCommand> getModifications()
+ public List<VisitableCommand> getModifications()
{
if (modificationList == null) return Collections.emptyList();
return modificationList;
}
- public void addLocalModification(WriteCommand command)
+ public void addLocalModification(VisitableCommand command)
{
if (command == null) throw new NullPointerException("Command is null!");
- if (localModifications == null) localModifications = new LinkedList<WriteCommand>();
+ if (localModifications == null) localModifications = new LinkedList<VisitableCommand>();
localModifications.add(command);
}
- public List<WriteCommand> getLocalModifications()
+ public List<VisitableCommand> getLocalModifications()
{
if (localModifications == null) return Collections.emptyList();
return localModifications;
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CallInterceptor.java (from rev 6858, core/branches/flat/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CallInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/CallInterceptor.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -0,0 +1,154 @@
+/*
+ * 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.commands.ReplicableCommand;
+import org.jboss.starobrno.commands.VisitableCommand;
+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.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+import org.jboss.starobrno.transaction.GlobalTransaction;
+
+import javax.transaction.Transaction;
+
+/**
+ * Always at the end of the chain, directly in front of the cache. Simply calls into the cache using reflection.
+ * If the call resulted in a modification, add the Modification to the end of the modification list
+ * keyed by the current transaction.
+ * <p/>
+ * Although always added to the end of an optimistically locked chain as well, calls should not make it down to
+ * this interceptor unless it is a call the OptimisticNodeInterceptor knows nothing about.
+ *
+ * @author Bela Ban
+ * @version $Id$
+ */
+public class CallInterceptor extends CommandInterceptor
+{
+ private boolean notOptimisticLocking;
+
+ @Start
+ protected void start()
+ {
+ notOptimisticLocking = false;
+ }
+
+ @Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ if (trace) log.trace("Suppressing invocation of method handlePrepareCommand.");
+ return null;
+ }
+
+ @Override
+ public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ if (trace) log.trace("Suppressing invocation of method handleCommitCommand.");
+ return null;
+ }
+
+ @Override
+ public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ if (trace) log.trace("Suppressing invocation of method handleRollbackCommand.");
+ return null;
+ }
+
+ @Override
+ public Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ if (trace) log.trace("Executing command: " + command + ".");
+ return invokeCommand(ctx, command);
+ }
+
+ private Object invokeCommand(InvocationContext ctx, ReplicableCommand command)
+ throws Throwable
+ {
+ Object retval;
+ try
+ {
+ retval = command.perform(ctx);
+ }
+ catch (Throwable t)
+ {
+ Transaction tx = ctx.getTransaction();
+ if (ctx.isValidTransaction())
+ {
+ tx.setRollbackOnly();
+ }
+ throw t;
+ }
+ return retval;
+ }
+
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ return handleAlterCacheMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable
+ {
+ return handleAlterCacheMethod(ctx, command);
+ }
+
+ @Override
+ public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable
+ {
+ return handleAlterCacheMethod(ctx, command);
+ }
+
+ /**
+ * only add the modification to the modification list if we are using pessimistic locking.
+ * Optimistic locking calls *should* not make it this far down the interceptor chain, but just
+ * in case a method has been invoked that the OptimisticNodeInterceptor knows nothing about, it will
+ * filter down here.
+ */
+ private Object handleAlterCacheMethod(InvocationContext ctx, VisitableCommand command)
+ throws Throwable
+ {
+ Object result = invokeCommand(ctx, command);
+ if (notOptimisticLocking && ctx.isValidTransaction())
+ {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ if (gtx == null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("didn't find GlobalTransaction for " + ctx.getTransaction() + "; won't add modification to transaction list");
+ }
+ }
+ else
+ {
+ ctx.getTransactionContext().addModification(command);
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2008-10-08 14:34:05 UTC (rev 6875)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2008-10-08 14:58:36 UTC (rev 6876)
@@ -26,8 +26,8 @@
import org.jboss.starobrno.commands.AbstractVisitor;
import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.annotations.Inject;
-import org.jboss.starobrno.context.InvocationContext;
/**
* This is the base class for all interceptors to extend, and implements the {@link org.jboss.cache.commands.Visitor} interface
More information about the jbosscache-commits
mailing list