[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Wed Jan 3 12:50:31 EST 2007
User: msurtani
Date: 07/01/03 12:50:31
Modified: src/org/jboss/cache AbstractCacheListener.java
ConsoleListener.java TreeCacheView.java
CacheImpl.java TreeCacheView2.java
CacheListener.java
Log:
added more rich nodeModified callback
Revision Changes Path
1.4 +1 -1 JBossCache/src/org/jboss/cache/AbstractCacheListener.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractCacheListener.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/AbstractCacheListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AbstractCacheListener.java 2 Jan 2007 17:15:29 -0000 1.3
+++ AbstractCacheListener.java 3 Jan 2007 17:50:31 -0000 1.4
@@ -23,7 +23,7 @@
{
}
- public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
{
}
1.13 +1 -1 JBossCache/src/org/jboss/cache/ConsoleListener.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConsoleListener.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/ConsoleListener.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- ConsoleListener.java 2 Jan 2007 17:15:29 -0000 1.12
+++ ConsoleListener.java 3 Jan 2007 17:50:31 -0000 1.13
@@ -126,7 +126,7 @@
if (pre) printNode(fqn, "loaded");
}
- public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
{
if (pre)
printEvent("DataNode about to be modified: " + fqn);
1.21 +2 -2 JBossCache/src/org/jboss/cache/TreeCacheView.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheView.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- TreeCacheView.java 2 Jan 2007 17:15:29 -0000 1.20
+++ TreeCacheView.java 3 Jan 2007 17:50:31 -0000 1.21
@@ -53,7 +53,7 @@
* The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
* data needs to be displayed, the underlying cache will be accessed directly.
*
- * @version $Revision: 1.20 $
+ * @version $Revision: 1.21 $
* @author<a href="mailto:bela at jboss.org">Bela Ban</a> March 27 2003
*/
public class TreeCacheView implements TreeCacheViewMBean
@@ -595,7 +595,7 @@
nodeRemoved(fqn, pre, isLocal, null);
}
- public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
{
// Map data;
//data=getData(fqn);
1.14 +16 -10 JBossCache/src/org/jboss/cache/CacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- CacheImpl.java 3 Jan 2007 15:33:09 -0000 1.13
+++ CacheImpl.java 3 Jan 2007 17:50:31 -0000 1.14
@@ -78,6 +78,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -98,7 +99,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: CacheImpl.java,v 1.13 2007/01/03 15:33:09 msurtani Exp $
+ * @version $Id: CacheImpl.java,v 1.14 2007/01/03 17:50:31 msurtani Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
@@ -2203,7 +2204,7 @@
Node n = findNodeCheck(tx, fqn);
Map rawData = n.getNodeSPI().getRawData();
- notifier.notifyNodeModified(fqn, true, rawData, true);
+ notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_MAP, rawData, true);
getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
@@ -2221,7 +2222,7 @@
if (erase_contents) n.clearData();
n.put(data);
- notifier.notifyNodeModified(fqn, false, rawData, true);
+ notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_MAP, rawData, true);
}
@@ -2258,7 +2259,7 @@
Node n = findNodeCheck(tx, fqn);
Map rawData = n.getNodeSPI().getRawData();
- notifier.notifyNodeModified(fqn, true, rawData, true);
+ notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_DATA, rawData, true);
getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
Object old_value = n.put(key, value);
@@ -2280,7 +2281,9 @@
tx_table.addUndoOperation(tx, undo_op);
}
- notifier.notifyNodeModified(fqn, false, rawData, true);
+ Map newData = new HashMap();
+ newData.put(key, value);
+ notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_DATA, newData, true);
return old_value;
}
@@ -2491,7 +2494,7 @@
return null;
}
- notifier.notifyNodeModified(fqn, true, n.getNodeSPI().getRawData(), true);
+ notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.REMOVE_DATA, n.getNodeSPI().getRawData(), true);
getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
old_value = n.remove(key);
@@ -2505,7 +2508,9 @@
tx_table.addUndoOperation(tx, undo_op);
}
- notifier.notifyNodeModified(fqn, false, n.getNodeSPI().getRawData(), true);
+ Map removedData = new HashMap();
+ removedData.put(key, old_value);
+ notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.REMOVE_DATA, removedData, true);
return old_value;
}
@@ -2569,11 +2574,12 @@
return;
}
+ Map data = n.getData();
+
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
if (tx != null && create_undo_ops && !eviction)
{
- Map data = n.getData();
if (!data.isEmpty())
{
undo_op = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal,
@@ -2587,7 +2593,7 @@
}
else
{
- notifier.notifyNodeModified(fqn, true, n.getNodeSPI().getRawData(), true);
+ notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.REMOVE_DATA, data, true);
}
Map raw = n.getNodeSPI().getRawData();
@@ -2609,7 +2615,7 @@
}
else
{
- notifier.notifyNodeModified(fqn, false, n.getData(), true);
+ notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.REMOVE_DATA, data, true);
}
}
1.20 +2 -2 JBossCache/src/org/jboss/cache/TreeCacheView2.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheView2.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView2.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- TreeCacheView2.java 2 Jan 2007 17:15:29 -0000 1.19
+++ TreeCacheView2.java 3 Jan 2007 17:50:31 -0000 1.20
@@ -53,7 +53,7 @@
* The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
* data needs to be displayed, the underlying cache will be accessed directly.
*
- * @version $Revision: 1.19 $
+ * @version $Revision: 1.20 $
*/
public class TreeCacheView2
{
@@ -473,7 +473,7 @@
}
- public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
+ public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
{
// data=getData(fqn.toString());
// System.out.println("Data modified: fqn: " +fqn + " data: " +data);
1.6 +29 -11 JBossCache/src/org/jboss/cache/CacheListener.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheListener.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheListener.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CacheListener.java 2 Jan 2007 17:15:29 -0000 1.5
+++ CacheListener.java 3 Jan 2007 17:50:31 -0000 1.6
@@ -20,6 +20,11 @@
*/
public interface CacheListener
{
+ public enum ModificationType
+ {
+ PUT_DATA, REMOVE_DATA, PUT_MAP
+ }
+
/**
* Called before and after a {@link Node} is created.
*
@@ -30,19 +35,32 @@
void nodeCreated(Fqn fqn, boolean pre, boolean isLocal);
/**
- * Called before and after a {@link Node} is modified. Data passed in is
- * always an unmodifiable {@link Map} of the data in the {@link Node}.
+ * Called before and after a {@link Node} is modified. Data passed in the <code>data</code> parameter can be used to
+ * determine what was modified.
* <p/>
- * When called with pre=true, this is the initial state of the {@link Node} before
- * modification. When called with pre=false, this is the new state of the
- * {@link Node}.
- *
- * @param fqn The affected Fqn
- * @param pre whether this notification event is before (pre=true) or after (pre=true) changes have been made to the cache.
- * @param isLocal whether the event originated from a remote cache (isLocal=false) or locally.
- * @param data an unmodifiable {@link Map} of data. May be empty, will never be null.
+ * When called with <code>pre == true</code>, <code>data</code> is the initial state of the {@link Node} before
+ * modification.
+ * <p/>
+ * When called with <code>pre == false</code>, the contents of <code>data</code>
+ * depend on the value of <code>modType</code>:
+ * <ul>
+ * <li><b>{@link org.jboss.cache.CacheListener.ModificationType#PUT_DATA}</b>: Map contains the single key/value pair that was added or modified.</li>
+ * <li><b>{@link org.jboss.cache.CacheListener.ModificationType#REMOVE_DATA}</b>: Map contains the key/value pairs that were removed.</li>
+ * <li><b>{@link ModificationType#PUT_MAP}</b>: Map contains the new state of the {@link Node} following modification. This map includes modified key/value
+ * pairs as well as any that were not affected.</li>
+ * </ul>
+ * <p/>
+ * Implementations interested in seeing the difference in the node data in the {@link ModificationType#PUT_MAP} case can cache the <code>data</code> map passed when
+ * <code>pre == true</code>, and then when the <code>pre == false</code> callback is received, pass the cached map and the new <code>data</code> to
+ * {@link org.jboss.cache.util.Util#diffNodeData(java.util.Map,java.util.Map)}
+ *
+ * @param fqn Fqn of the node being modified
+ * @param pre <code>true</code> if the modification is about to be applied, <code>false</code> if it has already been applied
+ * @param isLocal <code>true</code> if the modification originated locally, <code>false</code> if it was replicated from another cache instance in the cluster.
+ * @param modType PUT_KEY_VALUE, REMOVE_KEY_VALUE or PUT_MAP
+ * @param data Unmodifiable {@link java.util.Map}; will not be <code>null</code>. See description above.
*/
- void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map<Object, Object> data);
+ void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map<Object, Object> data);
/**
* Called before and after a {@link Node} is removed. Data passed in is
More information about the jboss-cvs-commits
mailing list