[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Manik Surtani
manik at jboss.org
Tue May 29 09:50:53 EDT 2007
User: msurtani
Date: 07/05/29 09:50:53
Modified: src/org/jboss/cache/marshall CacheMarshaller200.java
Log:
Added MapCopy to known types
Revision Changes Path
1.15 +50 -30 JBossCache/src/org/jboss/cache/marshall/CacheMarshaller200.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheMarshaller200.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/CacheMarshaller200.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- CacheMarshaller200.java 24 May 2007 18:14:00 -0000 1.14
+++ CacheMarshaller200.java 29 May 2007 13:50:53 -0000 1.15
@@ -14,6 +14,7 @@
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.util.MapCopy;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
@@ -64,6 +65,7 @@
protected static final int MAGICNUMBER_NODEDATA = 18;
protected static final int MAGICNUMBER_GRAVITATERESULT = 19;
protected static final int MAGICNUMBER_SHORT = 20;
+ protected static final int MAGICNUMBER_MAPCOPY = 21;
protected static final int MAGICNUMBER_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
protected static final int MAGICNUMBER_REF = 101;
@@ -326,6 +328,11 @@
out.writeByte(MAGICNUMBER_TREE_MAP);
marshallMap((Map) o, out, refMap);
}
+ else if (o.getClass().equals(MapCopy.class))
+ {
+ out.writeByte(MAGICNUMBER_MAPCOPY);
+ marshallMap((Map) o, out, refMap);
+ }
else if (o.getClass().equals(HashSet.class))
{
out.writeByte(MAGICNUMBER_HASH_SET);
@@ -561,6 +568,8 @@
return unmarshallHashSet(in, refMap);
case MAGICNUMBER_TREE_SET:
return unmarshallTreeSet(in, refMap);
+ case MAGICNUMBER_MAPCOPY:
+ return unmarshallMapCopy(in, refMap);
case MAGICNUMBER_BOOLEAN:
return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
case MAGICNUMBER_INTEGER:
@@ -678,66 +687,77 @@
private List unmarshallArrayList(ObjectInputStream in, Map refMap) throws Exception
{
int listSize = in.readInt();
- List<Object> list = new ArrayList<Object>(listSize);
- for (int i = 0; i < listSize; i++)
- {
- list.add(unmarshallObject(in, refMap));
- }
+ List list = new ArrayList(listSize);
+ populateFromStream(in, refMap, list, listSize);
return list;
}
private List unmarshallLinkedList(ObjectInputStream in, Map refMap) throws Exception
{
- int listSize = in.readInt();
List list = new LinkedList();
- for (int i = 0; i < listSize; i++)
- {
- list.add(unmarshallObject(in, refMap));
- }
+ populateFromStream(in, refMap, list, in.readInt());
return list;
}
private Map unmarshallHashMap(ObjectInputStream in, Map refMap) throws Exception
{
- int listSize = in.readInt();
Map map = new HashMap();
- for (int i = 0; i < listSize; i++)
- {
- map.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
- }
+ populateFromStream(in, refMap, map);
return map;
}
+ private Map unmarshallMapCopy(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
+ {
+ // read in as a HashMap first
+ Map m = unmarshallHashMap(in, refMap);
+ MapCopy mc = new MapCopy(m);
+ return mc;
+ }
+
private Map unmarshallTreeMap(ObjectInputStream in, Map refMap) throws Exception
{
- int listSize = in.readInt();
Map map = new TreeMap();
- for (int i = 0; i < listSize; i++)
- {
- map.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
- }
+ populateFromStream(in, refMap, map);
return map;
}
private Set unmarshallHashSet(ObjectInputStream in, Map refMap) throws Exception
{
- int listSize = in.readInt();
- Set map = new HashSet();
- for (int i = 0; i < listSize; i++)
+ Set set = new HashSet();
+ populateFromStream(in, refMap, set);
+ return set;
+ }
+
+ private Set unmarshallTreeSet(ObjectInputStream in, Map refMap) throws Exception
{
- map.add(unmarshallObject(in, refMap));
+ Set set = new TreeSet();
+ populateFromStream(in, refMap, set);
+ return set;
+ }
+
+ private void populateFromStream(ObjectInputStream in, Map refMap, Map mapToPopulate) throws Exception
+ {
+ int size = in.readInt();
+ for (int i = 0; i < size; i++)
+ {
+ mapToPopulate.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
}
- return map;
}
- private Set unmarshallTreeSet(ObjectInputStream in, Map refMap) throws Exception
+ private void populateFromStream(ObjectInputStream in, Map refMap, Set setToPopulate) throws Exception
+ {
+ int size = in.readInt();
+ for (int i = 0; i < size; i++)
+ {
+ setToPopulate.add(unmarshallObject(in, refMap));
+ }
+ }
+
+ private void populateFromStream(ObjectInputStream in, Map refMap, List listToPopulate, int listSize) throws Exception
{
- int listSize = in.readInt();
- Set map = new TreeSet();
for (int i = 0; i < listSize; i++)
{
- map.add(unmarshallObject(in, refMap));
+ listToPopulate.add(unmarshallObject(in, refMap));
}
- return map;
}
}
More information about the jboss-cvs-commits
mailing list