[infinispan-commits] Infinispan SVN: r276 - in trunk: core/src/main/java/org/infinispan/atomic and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed May 13 04:52:37 EDT 2009
Author: mircea.markus
Date: 2009-05-13 04:52:37 -0400 (Wed, 13 May 2009)
New Revision: 276
Added:
trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapDelta.java
trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java
trunk/core/src/main/java/org/infinispan/atomic/ClearOperation.java
trunk/core/src/main/java/org/infinispan/atomic/PutOperation.java
trunk/core/src/main/java/org/infinispan/atomic/RemoveOperation.java
Removed:
trunk/core/src/main/java/org/infinispan/atomic/atomichashmap/
trunk/core/src/main/java/org/infinispan/atomic/operations/
Modified:
trunk/core/src/main/java/org/infinispan/CacheDelegate.java
trunk/core/src/main/java/org/infinispan/atomic/AtomicMap.java
trunk/core/src/main/java/org/infinispan/atomic/NullDelta.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/ExternalizerClassFactory.java
trunk/core/src/main/java/org/infinispan/marshall/jboss/MagicNumberClassTable.java
trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTest.java
trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java
Log:
reduced Operation's visibility
Modified: trunk/core/src/main/java/org/infinispan/CacheDelegate.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/CacheDelegate.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/main/java/org/infinispan/CacheDelegate.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -23,7 +23,7 @@
import org.infinispan.atomic.AtomicMap;
import org.infinispan.atomic.AtomicMapCache;
-import org.infinispan.atomic.atomichashmap.AtomicHashMap;
+import org.infinispan.atomic.AtomicHashMap;
import org.infinispan.batch.BatchContainer;
import org.infinispan.commands.CommandsFactory;
import org.infinispan.commands.LockControlCommand;
Copied: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/atomichashmap/AtomicHashMap.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -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.infinispan.atomic;
+
+import net.jcip.annotations.NotThreadSafe;
+import org.infinispan.Cache;
+import org.infinispan.batch.BatchContainer;
+import org.infinispan.context.InvocationContextContainer;
+import org.infinispan.util.FastCopyHashMap;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Note that for replication to work properly, this class <b><i>requires</i></b> that all writes take place within the
+ * scope of an ongoing transaction or batch.
+ * <p/>
+ *
+ * @author (various)
+ * @param <K>
+ * @param <V>
+ * @since 4.0
+ */
+ at NotThreadSafe
+public class AtomicHashMap<K, V> implements AtomicMap<K, V>, DeltaAware, Cloneable {
+ FastCopyHashMap<K, V> delegate;
+ private AtomicHashMapDelta delta = null;
+ private volatile AtomicHashMapProxy proxy;
+
+ /**
+ * Construction only allowed through this factory method. This factory is intended for use internally by the
+ * CacheDelegate. User code should use {@link org.infinispan.atomic.AtomicMapCache#getAtomicMap(Object)}.
+ */
+ public static AtomicHashMap newInstance(Cache cache, Object cacheKey) {
+ AtomicHashMap value = new AtomicHashMap();
+ Object oldValue = cache.putIfAbsent(cacheKey, value);
+ if (oldValue != null) value = (AtomicHashMap) oldValue;
+ return value;
+ }
+
+ public AtomicHashMap() {
+ delegate = new FastCopyHashMap<K, V>();
+ }
+
+ public void commit() {
+ if (delta != null) delta = null;
+ }
+
+ public int size() {
+ return delegate.size();
+ }
+
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ public boolean containsKey(Object key) {
+ return delegate.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return delegate.containsValue(value);
+ }
+
+ public V get(Object key) {
+ return delegate.get(key);
+ }
+
+ public Set<K> keySet() {
+ return delegate.keySet();
+ }
+
+ public Collection<V> values() {
+ return delegate.values();
+ }
+
+ public Set<Entry<K, V>> entrySet() {
+ return delegate.entrySet();
+ }
+
+ public V put(K key, V value) {
+ V oldValue = delegate.put(key, value);
+ PutOperation<K, V> op = new PutOperation<K, V>(key, oldValue, value);
+ getDelta().addOperation(op);
+ return oldValue;
+ }
+
+ public V remove(Object key) {
+ V oldValue = delegate.remove(key);
+ RemoveOperation<K, V> op = new RemoveOperation<K, V>((K)key, oldValue);
+ getDelta().addOperation(op);
+ return oldValue;
+ }
+
+ public void putAll(Map<? extends K, ? extends V> t) {
+ // this is crappy - need to do this more efficiently!
+ for (Entry<? extends K, ? extends V> e : t.entrySet()) put(e.getKey(), e.getValue());
+ }
+
+ public void clear() {
+ FastCopyHashMap<K, V> originalEntries = (FastCopyHashMap<K, V>) delegate.clone();
+ ClearOperation<K, V> op = new ClearOperation<K, V>(originalEntries);
+ if (delta!= null ) delta.addOperation(op);
+ delegate.clear();
+ }
+
+ public AtomicMap getProxy(Cache cache, Object mapKey,
+ BatchContainer batchContainer, InvocationContextContainer icc) {
+ // construct the proxy lazily
+ if (proxy == null) // DCL is OK here since proxy is volatile (and we live in a post-JDK 5 world)
+ {
+ synchronized (this) {
+ if (proxy == null)
+ proxy = new AtomicHashMapProxy(cache, mapKey, batchContainer, icc);
+ }
+ }
+ return proxy;
+ }
+
+ public Delta delta() {
+ Delta toReturn = delta == null ? NullDelta.INSTANCE : delta;
+ delta = null; // reset
+ return toReturn;
+ }
+
+ public AtomicHashMap copyForWrite() {
+ try {
+ AtomicHashMap clone = (AtomicHashMap) super.clone();
+ clone.delegate = (FastCopyHashMap) delegate.clone();
+ clone.proxy = proxy;
+ return clone;
+ }
+ catch (CloneNotSupportedException e) {
+ // should never happen!!
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "AtomicHashMap{" +
+ "delegate=" + delegate +
+ '}';
+ }
+
+ /**
+ * Initializes the delta instance to start recording changes.
+ */
+ public void initForWriting() {
+ delta = new AtomicHashMapDelta();
+ }
+
+ private AtomicHashMapDelta getDelta() {
+ if (delta == null) delta = new AtomicHashMapDelta();
+ return delta;
+ }
+}
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapDelta.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/atomichashmap/AtomicHashMapDelta.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapDelta.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapDelta.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -0,0 +1,88 @@
+/*
+ * 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.infinispan.atomic;
+
+import org.infinispan.atomic.Delta;
+import org.infinispan.atomic.DeltaAware;
+import org.infinispan.atomic.Operation;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Changes that have occured on an AtomicHashMap
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ * @since 4.0
+ */
+public class AtomicHashMapDelta implements Delta {
+ private static final Log log = LogFactory.getLog(AtomicHashMapDelta.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ private List<Operation> changelog;
+
+ public DeltaAware merge(DeltaAware d) {
+ AtomicHashMap other;
+ if (d != null && (d instanceof AtomicHashMap))
+ other = (AtomicHashMap) d;
+ else
+ other = new AtomicHashMap();
+
+ for (Operation o : changelog) o.replay(other.delegate);
+ other.commit();
+ return other;
+ }
+
+ public void addOperation(Operation o) {
+ if (changelog == null) {
+ // lazy init
+ changelog = new LinkedList<Operation>();
+ }
+ changelog.add(o);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ if (trace) log.trace("Serializing changelog " + changelog);
+ out.writeObject(changelog);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ changelog = (List<Operation>) in.readObject();
+ if (trace) log.trace("Deserialized changelog " + changelog);
+ }
+
+ @Override
+ public String toString() {
+ return "AtomicHashMapDelta{" +
+ "changelog=" + changelog +
+ '}';
+ }
+
+ public int getChangeLogSize() {
+ return changelog == null ? 0 : changelog.size();
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapDelta.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/atomichashmap/AtomicHashMapProxy.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -0,0 +1,176 @@
+/*
+ * 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.infinispan.atomic;
+
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicMap;
+import org.infinispan.batch.AutoBatchSupport;
+import org.infinispan.batch.BatchContainer;
+import org.infinispan.context.Flag;
+import org.infinispan.context.InvocationContext;
+import org.infinispan.context.InvocationContextContainer;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A layer of indirection around an {@link AtomicHashMap} to provide reader consistency
+ *
+ * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
+ * @since 4.0
+ */
+public class AtomicHashMapProxy<K, V> extends AutoBatchSupport implements AtomicMap<K, V> {
+ private static final Log log = LogFactory.getLog(AtomicHashMapProxy.class);
+ private static final boolean trace = log.isTraceEnabled();
+ Object deltaMapKey;
+ Cache cache;
+ InvocationContextContainer icc;
+
+ public AtomicHashMapProxy(Cache cache, Object deltaMapKey, BatchContainer batchContainer, InvocationContextContainer icc) {
+ this.cache = cache;
+ this.deltaMapKey = deltaMapKey;
+ this.batchContainer = batchContainer;
+ this.icc = icc;
+ }
+
+ // internal helper, reduces lots of casts.
+ private AtomicHashMap<K, V> getDeltaMapForRead() {
+ return (AtomicHashMap<K, V>) cache.get(deltaMapKey);
+ }
+
+ private AtomicHashMap<K, V> getDeltaMapForWrite(InvocationContext ctx) {
+ if (ctx.hasLockedKey(deltaMapKey)) {
+ return (AtomicHashMap<K, V>) cache.get(deltaMapKey);
+ } else {
+ // acquire WL
+ boolean suppressLocks = ctx.hasFlag(Flag.SKIP_LOCKING);
+ if (!suppressLocks) ctx.setFlags(Flag.FORCE_WRITE_LOCK);
+
+ if (trace) {
+ if (suppressLocks)
+ log.trace("Skip locking flag used. Skipping locking.");
+ else
+ log.trace("Forcing write lock even for reads");
+ }
+
+ AtomicHashMap map = getDeltaMapForRead();
+ // copy for write
+ AtomicHashMap copy = map == null ? new AtomicHashMap() : map.copyForWrite();
+ copy.initForWriting();
+ // reinstate the flag
+ if (suppressLocks) ctx.setFlags(Flag.SKIP_LOCKING);
+ cache.put(deltaMapKey, copy);
+ return copy;
+ }
+ }
+
+ // readers
+
+ public Set<K> keySet() {
+ return getDeltaMapForRead().keySet();
+ }
+
+ public Collection<V> values() {
+ return getDeltaMapForRead().values();
+ }
+
+ public Set<Entry<K, V>> entrySet() {
+ return getDeltaMapForRead().entrySet();
+ }
+
+ public int size() {
+ return getDeltaMapForRead().size();
+ }
+
+ public boolean isEmpty() {
+ return getDeltaMapForRead().isEmpty();
+ }
+
+ public boolean containsKey(Object key) {
+ return getDeltaMapForRead().containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return getDeltaMapForRead().containsValue(value);
+ }
+
+ public V get(Object key) {
+ return getDeltaMapForRead().get(key);
+ }
+
+ // writers
+
+ public V put(K key, V value) {
+ try {
+ startAtomic();
+ InvocationContext ctx = icc.getLocalInvocationContext();
+ AtomicHashMap<K, V> deltaMapForWrite = getDeltaMapForWrite(ctx);
+ return deltaMapForWrite.put(key, value);
+ }
+ finally {
+ endAtomic();
+ }
+ }
+
+ public V remove(Object key) {
+ try {
+ startAtomic();
+ InvocationContext ic = icc.getLocalInvocationContext();
+ return getDeltaMapForWrite(ic).remove(key);
+ }
+ finally {
+ endAtomic();
+ }
+ }
+
+ public void putAll(Map<? extends K, ? extends V> m) {
+ try {
+ startAtomic();
+ InvocationContext ic = icc.getLocalInvocationContext();
+ getDeltaMapForWrite(ic).putAll(m);
+ }
+ finally {
+ endAtomic();
+ }
+ }
+
+ public void clear() {
+ try {
+ startAtomic();
+ InvocationContext ic = icc.getLocalInvocationContext();
+ getDeltaMapForWrite(ic).clear();
+ }
+ finally {
+ endAtomic();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "AtomicHashMapProxy{" +
+ "deltaMapKey=" + deltaMapKey +
+ '}';
+ }
+}
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/java/org/infinispan/atomic/AtomicMap.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicMap.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicMap.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -34,7 +34,7 @@
*
* @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
* @see DeltaAware
- * @see org.infinispan.atomic.atomichashmap.AtomicHashMap
+ * @see AtomicHashMap
* @since 4.0
*/
public interface AtomicMap<K, V> extends Map<K, V> {
Copied: trunk/core/src/main/java/org/infinispan/atomic/ClearOperation.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/operations/ClearOperation.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/ClearOperation.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/ClearOperation.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -0,0 +1,46 @@
+/*
+ * 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.infinispan.atomic;
+
+import org.infinispan.util.FastCopyHashMap;
+
+import java.util.Map;
+
+
+public class ClearOperation<K, V> extends Operation<K, V> {
+ FastCopyHashMap<K, V> originalEntries;
+
+ public ClearOperation() {
+ }
+
+ ClearOperation(FastCopyHashMap<K, V> originalEntries) {
+ this.originalEntries = originalEntries;
+ }
+
+ public void rollback(Map<K, V> delegate) {
+ if (!originalEntries.isEmpty()) delegate.putAll(originalEntries);
+ }
+
+ public void replay(Map<K, V> delegate) {
+ delegate.clear();
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/ClearOperation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/java/org/infinispan/atomic/NullDelta.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/NullDelta.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/main/java/org/infinispan/atomic/NullDelta.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -21,7 +21,7 @@
*/
package org.infinispan.atomic;
-import org.infinispan.atomic.atomichashmap.AtomicHashMap;
+import org.infinispan.atomic.AtomicHashMap;
import java.io.IOException;
import java.io.ObjectInput;
Copied: trunk/core/src/main/java/org/infinispan/atomic/PutOperation.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/operations/PutOperation.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/PutOperation.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/PutOperation.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -0,0 +1,67 @@
+/*
+ * 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.infinispan.atomic;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+
+public class PutOperation<K, V> extends Operation<K, V> {
+ private K key;
+ private V oldValue;
+ private V newValue;
+
+ public PutOperation() {
+ }
+
+ PutOperation(K key, V oldValue, V newValue) {
+ this.key = key;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public void rollback(Map<K, V> delegate) {
+ if (oldValue == null)
+ delegate.remove(key);
+ else
+ delegate.put(key, oldValue);
+ }
+
+ public void replay(Map<K, V> delegate) {
+ delegate.put(key, newValue);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ // don't bother writing out the old value since it will never be rolled back
+ out.writeObject(key);
+ out.writeObject(newValue);
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ key = (K) in.readObject();
+ newValue = (V) in.readObject();
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/PutOperation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: trunk/core/src/main/java/org/infinispan/atomic/RemoveOperation.java (from rev 275, trunk/core/src/main/java/org/infinispan/atomic/operations/RemoveOperation.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/RemoveOperation.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/RemoveOperation.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -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.infinispan.atomic;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+
+
+public class RemoveOperation<K, V> extends Operation<K, V> {
+ private K key;
+ private V oldValue;
+
+ public RemoveOperation() {
+ }
+
+ RemoveOperation(K key, V oldValue) {
+ this.key = key;
+ this.oldValue = oldValue;
+ }
+
+ public void rollback(Map<K, V> delegate) {
+ if (oldValue != null) delegate.put(key, oldValue);
+ }
+
+ public void replay(Map<K, V> delegate) {
+ delegate.remove(key);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(key);
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ key = (K) in.readObject();
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/main/java/org/infinispan/atomic/RemoveOperation.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/ExternalizerClassFactory.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/ExternalizerClassFactory.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/ExternalizerClassFactory.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -23,7 +23,7 @@
import net.jcip.annotations.Immutable;
import org.infinispan.CacheException;
-import org.infinispan.atomic.atomichashmap.AtomicHashMap;
+import org.infinispan.atomic.AtomicHashMap;
import org.infinispan.commands.control.StateTransferControlCommand;
import org.infinispan.commands.read.GetKeyValueCommand;
import org.infinispan.commands.remote.ClusteredGetCommand;
Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/MagicNumberClassTable.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/MagicNumberClassTable.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/MagicNumberClassTable.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -23,7 +23,7 @@
import net.jcip.annotations.Immutable;
import org.infinispan.CacheException;
-import org.infinispan.atomic.atomichashmap.AtomicHashMap;
+import org.infinispan.atomic.AtomicHashMap;
import org.infinispan.commands.control.StateTransferControlCommand;
import org.infinispan.commands.read.GetKeyValueCommand;
import org.infinispan.commands.remote.ClusteredGetCommand;
Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTest.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTest.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -25,8 +25,8 @@
import org.easymock.EasyMock;
import org.testng.annotations.Test;
-import org.infinispan.atomic.atomichashmap.AtomicHashMap;
-import org.infinispan.atomic.atomichashmap.AtomicHashMapDelta;
+import org.infinispan.atomic.AtomicHashMap;
+import org.infinispan.atomic.AtomicHashMapDelta;
import java.io.IOException;
import java.io.ObjectOutput;
Modified: trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java
===================================================================
--- trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java 2009-05-13 08:12:39 UTC (rev 275)
+++ trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java 2009-05-13 08:52:37 UTC (rev 276)
@@ -23,7 +23,7 @@
import org.infinispan.Cache;
import org.infinispan.atomic.AtomicMap;
-import org.infinispan.atomic.atomichashmap.AtomicHashMapProxy;
+import org.infinispan.atomic.AtomicHashMapProxy;
import org.infinispan.batch.BatchContainer;
import org.infinispan.context.Flag;
import org.infinispan.context.InvocationContextContainer;
More information about the infinispan-commits
mailing list