Author: manik.surtani(a)jboss.com
Date: 2008-07-30 06:41:08 -0400 (Wed, 30 Jul 2008)
New Revision: 6433
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
Log:
Added marshalling of FastCopyHashMaps
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-30
10:39:40 UTC (rev 6432)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-07-30
10:41:08 UTC (rev 6433)
@@ -15,6 +15,7 @@
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.util.FastCopyHashMap;
import org.jboss.cache.util.ImmutableMapCopy;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
@@ -65,6 +66,7 @@
protected static final int MAGICNUMBER_SHORT = 20;
protected static final int MAGICNUMBER_IMMUTABLE_MAPCOPY = 21;
protected static final int MAGICNUMBER_MARSHALLEDVALUE = 22;
+ protected static final int MAGICNUMBER_FASTCOPY_HASHMAP = 23;
protected static final int MAGICNUMBER_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
protected static final int MAGICNUMBER_REF = 101;
@@ -265,6 +267,7 @@
// --------- Marshalling methods
+ @SuppressWarnings("deprecation")
protected void marshallObject(Object o, ObjectOutputStream out, Map<Object,
Integer> refMap) throws Exception
{
if (o == null)
@@ -341,6 +344,11 @@
out.writeByte(MAGICNUMBER_TREE_MAP);
marshallMap((Map) o, out, refMap);
}
+ else if (o.getClass().equals(FastCopyHashMap.class))
+ {
+ out.writeByte(MAGICNUMBER_FASTCOPY_HASHMAP);
+ marshallMap((Map) o, out, refMap);
+ }
else if (o.getClass().equals(ImmutableMapCopy.class))
{
out.writeByte(MAGICNUMBER_IMMUTABLE_MAPCOPY);
@@ -481,6 +489,7 @@
ipAddress.writeExternal(out);
}
+ @SuppressWarnings("unchecked")
private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap)
throws Exception
{
writeUnsignedInt(out, c.size());
@@ -490,6 +499,7 @@
}
}
+ @SuppressWarnings("unchecked")
private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer>
refMap) throws Exception
{
int mapSize = map.size();
@@ -586,6 +596,8 @@
return unmarshallTreeSet(in, refMap);
case MAGICNUMBER_IMMUTABLE_MAPCOPY:
return unmarshallMapCopy(in, refMap);
+ case MAGICNUMBER_FASTCOPY_HASHMAP:
+ return unmarshallFastCopyHashMap(in, refMap);
case MAGICNUMBER_BOOLEAN:
return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
case MAGICNUMBER_INTEGER:
@@ -623,6 +635,14 @@
throw new Exception("Unknown magic number " + magicNumber);
}
+ private FastCopyHashMap unmarshallFastCopyHashMap(ObjectInputStream in,
UnmarshalledReferences refMap) throws Exception
+ {
+ FastCopyHashMap map = new FastCopyHashMap();
+ populateFromStream(in, refMap, map);
+ return map;
+ }
+
+ @SuppressWarnings("unchecked")
private GravitateResult unmarshallGravitateResult(ObjectInputStream in,
UnmarshalledReferences refMap) throws Exception
{
Boolean found = (Boolean) unmarshallObject(in, refMap);
@@ -723,6 +743,7 @@
return map;
}
+ @SuppressWarnings("unchecked")
private Map unmarshallMapCopy(ObjectInputStream in, UnmarshalledReferences refMap)
throws Exception
{
// read in as a HashMap first
@@ -751,37 +772,33 @@
return set;
}
+ @SuppressWarnings("unchecked")
private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
Map mapToPopulate) throws Exception
{
int size = readUnsignedInt(in);
- for (int i = 0; i < size; i++)
- {
- mapToPopulate.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
- }
+ for (int i = 0; i < size; i++) mapToPopulate.put(unmarshallObject(in, refMap),
unmarshallObject(in, refMap));
}
+ @SuppressWarnings("unchecked")
private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
Set setToPopulate) throws Exception
{
int size = readUnsignedInt(in);
- for (int i = 0; i < size; i++)
- {
- setToPopulate.add(unmarshallObject(in, refMap));
- }
+ for (int i = 0; i < size; i++) setToPopulate.add(unmarshallObject(in, refMap));
}
+ @SuppressWarnings("unchecked")
private void populateFromStream(ObjectInputStream in, UnmarshalledReferences refMap,
List listToPopulate, int listSize) throws Exception
{
- for (int i = 0; i < listSize; i++)
- {
- listToPopulate.add(unmarshallObject(in, refMap));
- }
+ for (int i = 0; i < listSize; i++) listToPopulate.add(unmarshallObject(in,
refMap));
}
+ @SuppressWarnings("deprecation")
protected void marshallDefaultDataVersion(DefaultDataVersion ddv, ObjectOutputStream
out) throws Exception
{
writeUnsignedLong(out, ddv.getRawVersion());
}
+ @SuppressWarnings("deprecation")
protected DefaultDataVersion unmarshallDefaultDataVersion(ObjectInputStream in) throws
Exception
{
return new DefaultDataVersion(readUnsignedLong(in));