[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Manik Surtani
msurtani at jboss.com
Fri Sep 15 20:23:35 EDT 2006
User: msurtani
Date: 06/09/15 20:23:35
Modified: src/org/jboss/cache/loader AbstractCacheLoader.java
Log:
Updates to the move() API plus more UTs
Revision Changes Path
1.4 +188 -147 JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AbstractCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AbstractCacheLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AbstractCacheLoader.java 13 Sep 2006 15:42:16 -0000 1.3
+++ AbstractCacheLoader.java 16 Sep 2006 00:23:35 -0000 1.4
@@ -6,18 +6,20 @@
*/
package org.jboss.cache.loader;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.marshall.RegionManager;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* A convenience abstract implementation of a {@link org.jboss.cache.CacheLoader}
*
@@ -30,7 +32,7 @@
public void put(Fqn fqn, Map attributes, boolean erase) throws Exception
{
- if(erase)
+ if (erase)
{
removeData(fqn);
}
@@ -39,7 +41,7 @@
public void storeEntireState(ObjectInputStream is) throws Exception
{
- storeState(Fqn.ROOT,is);
+ storeState(Fqn.ROOT, is);
}
public void storeState(Fqn subtree, ObjectInputStream in) throws Exception
@@ -61,9 +63,9 @@
for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
{
- if(nd.isExceptionMarker())
+ if (nd.isExceptionMarker())
{
- throw new CacheException("State provider cacheloader threw exception during loadState",((NodeDataExceptionMarker)nd).getCause());
+ throw new CacheException("State provider cacheloader threw exception during loadState", ((NodeDataExceptionMarker) nd).getCause());
}
if (moveToBuddy)
@@ -93,7 +95,7 @@
public void loadEntireState(ObjectOutputStream os) throws Exception
{
- loadState(Fqn.ROOT,os);
+ loadState(Fqn.ROOT, os);
}
public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
@@ -138,11 +140,13 @@
/**
* Do a preorder traversal: visit the node first, then the node's children
+ *
* @param fqn Start node
* @param out
* @throws Exception
*/
- protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception {
+ protected void loadStateHelper(Fqn fqn, ObjectOutputStream out) throws Exception
+ {
Map attrs;
Set children_names;
String child_name;
@@ -150,21 +154,58 @@
NodeData nd;
// first handle the current node
- attrs=get(fqn);
- if(attrs == null || attrs.size() == 0)
- nd=new NodeData(fqn);
+ attrs = get(fqn);
+ if (attrs == null || attrs.size() == 0)
+ {
+ nd = new NodeData(fqn);
+ }
else
- nd=new NodeData(fqn, attrs);
+ {
+ nd = new NodeData(fqn, attrs);
+ }
out.writeObject(nd);
// then visit the children
- children_names=getChildrenNames(fqn);
- if(children_names == null)
+ children_names = getChildrenNames(fqn);
+ if (children_names == null)
+ {
return;
- for(Iterator it=children_names.iterator(); it.hasNext();) {
- child_name=(String)it.next();
- tmp_fqn=new Fqn(fqn, child_name);
+ }
+ for (Iterator it = children_names.iterator(); it.hasNext();)
+ {
+ child_name = (String) it.next();
+ tmp_fqn = new Fqn(fqn, child_name);
loadStateHelper(tmp_fqn, out);
}
}
+
+ public void put(List<Modification> modifications) throws Exception
+ {
+ for (Modification m : modifications)
+ {
+ switch (m.getType())
+ {
+ case Modification.PUT_DATA:
+ put(m.getFqn(), m.getData());
+ break;
+ case Modification.PUT_DATA_ERASE:
+ removeData(m.getFqn());
+ put(m.getFqn(), m.getData());
+ break;
+ case Modification.PUT_KEY_VALUE:
+ put(m.getFqn(), m.getKey(), m.getValue());
+ break;
+ case Modification.REMOVE_DATA:
+ removeData(m.getFqn());
+ break;
+ case Modification.REMOVE_KEY_VALUE:
+ remove(m.getFqn(), m.getKey());
+ break;
+ case Modification.REMOVE_NODE:
+ remove(m.getFqn());
+ break;
+ }
+ }
+ }
+
}
More information about the jboss-cvs-commits
mailing list