[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Galder Zamarreno
galder.zamarreno at jboss.com
Fri Jan 12 10:53:56 EST 2007
User: gzamarreno
Date: 07/01/12 10:53:56
Modified: src/org/jboss/cache/marshall CacheMarshaller200.java
Log:
[JBCACHE-936] Fix ported from 1.4.x branch to head
Revision Changes Path
1.3 +104 -26 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- CacheMarshaller200.java 4 Jan 2007 05:35:37 -0000 1.2
+++ CacheMarshaller200.java 12 Jan 2007 15:53:56 -0000 1.3
@@ -27,6 +27,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.LinkedList;
+import java.util.TreeMap;
+import java.util.HashSet;
+import java.util.TreeSet;
+import java.util.Collection;
/**
* An enhanced marshaller for RPC calls between CacheImpl instances.
@@ -43,13 +48,17 @@
protected static final int MAGICNUMBER_FQN = 2;
protected static final int MAGICNUMBER_GTX = 3;
protected static final int MAGICNUMBER_IPADDRESS = 4;
- protected static final int MAGICNUMBER_LIST = 5;
+ protected static final int MAGICNUMBER_ARRAY_LIST = 5;
protected static final int MAGICNUMBER_INTEGER = 6;
protected static final int MAGICNUMBER_LONG = 7;
protected static final int MAGICNUMBER_BOOLEAN = 8;
protected static final int MAGICNUMBER_STRING = 9;
- protected static final int MAGICNUMBER_MAP = 10;
- protected static final int MAGICNUMBER_DEFAULT_DATA_VERSION = 11;
+ protected static final int MAGICNUMBER_DEFAULT_DATA_VERSION = 10;
+ protected static final int MAGICNUMBER_LINKED_LIST = 11;
+ protected static final int MAGICNUMBER_HASH_MAP = 12;
+ protected static final int MAGICNUMBER_TREE_MAP = 13;
+ protected static final int MAGICNUMBER_HASH_SET = 14;
+ protected static final int MAGICNUMBER_TREE_SET = 15;
protected static final int MAGICNUMBER_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
protected static final int MAGICNUMBER_REF = 101;
@@ -211,10 +220,35 @@
out.writeByte(MAGICNUMBER_DEFAULT_DATA_VERSION);
out.writeLong(((DefaultDataVersion) o).getRawVersion());
}
- else if (o instanceof List)
+ else if (o.getClass().equals(ArrayList.class))
{
- out.writeByte(MAGICNUMBER_LIST);
- marshallList((List) o, out, refMap);
+ out.writeByte(MAGICNUMBER_ARRAY_LIST);
+ marshallCollection((Collection) o, out, refMap);
+ }
+ else if (o.getClass().equals(LinkedList.class))
+ {
+ out.writeByte(MAGICNUMBER_LINKED_LIST);
+ marshallCollection((Collection) o, out, refMap);
+ }
+ else if (o.getClass().equals(HashMap.class))
+ {
+ out.writeByte(MAGICNUMBER_HASH_MAP);
+ marshallMap((Map) o, out, refMap);
+ }
+ else if (o.getClass().equals(TreeMap.class))
+ {
+ out.writeByte(MAGICNUMBER_TREE_MAP);
+ marshallMap((Map) o, out, refMap);
+ }
+ else if (o.getClass().equals(HashSet.class))
+ {
+ out.writeByte(MAGICNUMBER_HASH_SET);
+ marshallCollection((Collection) o, out, refMap);
+ }
+ else if (o.getClass().equals(TreeSet.class))
+ {
+ out.writeByte(MAGICNUMBER_TREE_SET);
+ marshallCollection((Collection) o, out, refMap);
}
else if (o instanceof Boolean)
{
@@ -238,11 +272,6 @@
out.writeShort(refId);
marshallString((String) o, out);
}
- else if (o instanceof Map)
- {
- out.writeByte(MAGICNUMBER_MAP);
- marshallMap((Map) o, out, refMap);
- }
else if (o instanceof Serializable)
{
int refId = createReference(o, refMap);
@@ -312,10 +341,10 @@
ipAddress.writeExternal(out);
}
- private void marshallList(List l, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
+ private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap) throws Exception
{
- out.writeInt(l.size());
- for (Object o : l)
+ out.writeInt(c.size());
+ for (Object o : c)
{
marshallObject(o, out, refMap);
}
@@ -398,8 +427,18 @@
case MAGICNUMBER_DEFAULT_DATA_VERSION:
retVal = new DefaultDataVersion(in.readLong());
return retVal;
- case MAGICNUMBER_LIST:
- return unmarshallList(in, refMap);
+ case MAGICNUMBER_ARRAY_LIST:
+ return unmarshallArrayList(in, refMap);
+ case MAGICNUMBER_LINKED_LIST:
+ return unmarshallLinkedList(in, refMap);
+ case MAGICNUMBER_HASH_MAP:
+ return unmarshallHashMap(in, refMap);
+ case MAGICNUMBER_TREE_MAP:
+ return unmarshallTreeMap(in, refMap);
+ case MAGICNUMBER_HASH_SET:
+ return unmarshallHashSet(in, refMap);
+ case MAGICNUMBER_TREE_SET:
+ return unmarshallTreeSet(in, refMap);
case MAGICNUMBER_BOOLEAN:
return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
case MAGICNUMBER_INTEGER:
@@ -412,8 +451,6 @@
retVal = unmarshallString(in);
refMap.put(reference, retVal);
return retVal;
- case MAGICNUMBER_MAP:
- return unmarshallMap(in, refMap);
default:
if (log.isErrorEnabled())
{
@@ -486,7 +523,7 @@
return ipAddress;
}
- private List unmarshallList(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
+ private List unmarshallArrayList(ObjectInputStream in, Map refMap) throws Exception
{
int listSize = in.readInt();
List<Object> list = new ArrayList<Object>(listSize);
@@ -497,17 +534,58 @@
return list;
}
- private Map unmarshallMap(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
+ private List unmarshallLinkedList(ObjectInputStream in, Map refMap) throws Exception
+ {
+ int listSize = in.readInt();
+ List list = new LinkedList();
+ for (int i = 0; i < listSize; i++)
{
- int mapSize = in.readInt();
- if (mapSize == 0) return Collections.emptyMap();
- Map<Object, Object> map = new HashMap<Object, Object>(mapSize);
- for (int i = 0; i < mapSize; i++)
+ list.add(unmarshallObject(in, refMap));
+ }
+ 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));
+ }
+ return map;
+ }
+
+ 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));
}
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++)
+ {
+ map.add(unmarshallObject(in, refMap));
+ }
+ return map;
+ }
+ private Set unmarshallTreeSet(ObjectInputStream in, Map refMap) throws Exception
+ {
+ int listSize = in.readInt();
+ Set map = new TreeSet();
+ for (int i = 0; i < listSize; i++)
+ {
+ map.add(unmarshallObject(in, refMap));
+ }
+ return map;
+ }
}
More information about the jboss-cvs-commits
mailing list