[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...
Manik Surtani
msurtani at jboss.com
Fri Dec 29 10:18:20 EST 2006
User: msurtani
Date: 06/12/29 10:18:20
Modified: src/org/jboss/cache/marshall TreeCacheMarshaller200.java
Log:
Enhanced marshalling for default data versions
Revision Changes Path
1.11 +39 -31 JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller200.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/TreeCacheMarshaller200.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- TreeCacheMarshaller200.java 16 Nov 2006 17:11:46 -0000 1.10
+++ TreeCacheMarshaller200.java 29 Dec 2006 15:18:20 -0000 1.11
@@ -12,6 +12,7 @@
import org.jboss.cache.GlobalTransaction;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.rpc.RpcTreeCache;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
@@ -23,7 +24,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,6 +49,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_NULL = 99;
protected static final int MAGICNUMBER_SERIALIZABLE = 100;
protected static final int MAGICNUMBER_REF = 101;
@@ -69,7 +70,7 @@
public void objectToStream(Object o, ObjectOutputStream out) throws Exception
{
if (log.isTraceEnabled()) log.trace("Marshalling object " + o);
- Map refMap = new HashMap();
+ Map<Object, Integer> refMap = new HashMap<Object, Integer>();
if (useRegionBasedMarshalling)
{
@@ -85,7 +86,7 @@
public Object objectFromStream(ObjectInputStream in) throws Exception
{
Object retValue;
- Map refMap = new HashMap();
+ Map<Integer, Object> refMap = new HashMap<Integer, Object>();
if (useRegionBasedMarshalling)
{
@@ -160,7 +161,7 @@
// --------- Marshalling methods
- private void marshallObject(Object o, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
if (o == null)
{
@@ -205,6 +206,11 @@
out.writeByte(TreeCacheMarshaller200.MAGICNUMBER_IPADDRESS);
marshallIpAddress((IpAddress) o, out);
}
+ else if (o instanceof DefaultDataVersion)
+ {
+ out.writeByte(TreeCacheMarshaller200.MAGICNUMBER_DEFAULT_DATA_VERSION);
+ out.writeLong(((DefaultDataVersion) o).getRawVersion());
+ }
else if (o instanceof List)
{
out.writeByte(TreeCacheMarshaller200.MAGICNUMBER_LIST);
@@ -254,10 +260,10 @@
}
}
- private int createReference(Object o, Map refMap)
+ private int createReference(Object o, Map<Object, Integer> refMap)
{
int reference = refMap.size();
- refMap.put(o, Integer.valueOf(reference));
+ refMap.put(o, reference);
return reference;
}
@@ -267,7 +273,7 @@
out.writeObject(s);
}
- private void marshallMethodCall(MethodCall methodCall, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallMethodCall(MethodCall methodCall, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
out.writeShort(methodCall.getMethodId());
Object[] args = methodCall.getArgs();
@@ -280,14 +286,14 @@
}
}
- private void marshallGlobalTransaction(GlobalTransaction globalTransaction, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallGlobalTransaction(GlobalTransaction globalTransaction, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
out.writeLong(globalTransaction.getId());
marshallObject(globalTransaction.getAddress(), out, refMap);
}
- private void marshallFqn(Fqn fqn, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallFqn(Fqn fqn, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
boolean isRoot = fqn.isRoot();
out.writeBoolean(isRoot);
@@ -306,17 +312,16 @@
ipAddress.writeExternal(out);
}
- private void marshallList(List l, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallList(List l, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
out.writeInt(l.size());
- Iterator i = l.iterator();
- while (i.hasNext())
+ for (Object o : l)
{
- marshallObject(i.next(), out, refMap);
+ marshallObject(o, out, refMap);
}
}
- private void marshallMap(Map map, ObjectOutputStream out, Map refMap) throws Exception
+ private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
{
int mapSize = map.size();
out.writeInt(mapSize);
@@ -331,7 +336,7 @@
// --------- Unmarshalling methods
- private Object unmarshallObject(ObjectInputStream in, ClassLoader loader, Map refMap) throws Exception
+ private Object unmarshallObject(ObjectInputStream in, ClassLoader loader, Map<Integer, Object> refMap) throws Exception
{
if (loader == null)
{
@@ -353,7 +358,7 @@
}
}
- private Object unmarshallObject(ObjectInputStream in, Map refMap) throws Exception
+ private Object unmarshallObject(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
byte magicNumber = in.readByte();
Integer reference;
@@ -363,14 +368,14 @@
case TreeCacheMarshaller200.MAGICNUMBER_NULL:
return null;
case TreeCacheMarshaller200.MAGICNUMBER_REF:
- reference = Integer.valueOf(in.readShort());
+ reference = (int) in.readShort();
if (!refMap.containsKey(reference))
{
throw new IOException("Unable to locate object reference " + reference + " in byte stream!");
}
return refMap.get(reference);
case TreeCacheMarshaller200.MAGICNUMBER_SERIALIZABLE:
- reference = Integer.valueOf(in.readShort());
+ reference = (int) in.readShort();
retVal = in.readObject();
refMap.put(reference, retVal);
return retVal;
@@ -378,29 +383,32 @@
retVal = unmarshallMethodCall(in, refMap);
return retVal;
case TreeCacheMarshaller200.MAGICNUMBER_FQN:
- reference = Integer.valueOf(in.readShort());
+ reference = (int) in.readShort();
retVal = unmarshallFqn(in, refMap);
refMap.put(reference, retVal);
return retVal;
case TreeCacheMarshaller200.MAGICNUMBER_GTX:
- reference = Integer.valueOf(in.readShort());
+ reference = (int) in.readShort();
retVal = unmarshallGlobalTransaction(in, refMap);
refMap.put(reference, retVal);
return retVal;
case TreeCacheMarshaller200.MAGICNUMBER_IPADDRESS:
retVal = unmarshallIpAddress(in);
return retVal;
+ case TreeCacheMarshaller200.MAGICNUMBER_DEFAULT_DATA_VERSION:
+ retVal = new DefaultDataVersion(in.readLong());
+ return retVal;
case TreeCacheMarshaller200.MAGICNUMBER_LIST:
return unmarshallList(in, refMap);
case TreeCacheMarshaller200.MAGICNUMBER_BOOLEAN:
return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
case TreeCacheMarshaller200.MAGICNUMBER_INTEGER:
- return Integer.valueOf(in.readInt());
+ return in.readInt();
case TreeCacheMarshaller200.MAGICNUMBER_LONG:
- retVal = Long.valueOf(in.readLong());
+ retVal = in.readLong();
return retVal;
case TreeCacheMarshaller200.MAGICNUMBER_STRING:
- reference = Integer.valueOf(in.readShort());
+ reference = (int) in.readShort();
retVal = unmarshallString(in);
refMap.put(reference, retVal);
return retVal;
@@ -421,7 +429,7 @@
return (String) in.readObject();
}
- private MethodCall unmarshallMethodCall(ObjectInputStream in, Map refMap) throws Exception
+ private MethodCall unmarshallMethodCall(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
short methodId = in.readShort();
byte numArgs = in.readByte();
@@ -439,7 +447,7 @@
return MethodCallFactory.create(MethodDeclarations.lookupMethod(methodId), args);
}
- private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, Map refMap) throws Exception
+ private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
GlobalTransaction gtx = new GlobalTransaction();
long id = in.readLong();
@@ -449,7 +457,7 @@
return gtx;
}
- private Fqn unmarshallFqn(ObjectInputStream in, Map refMap) throws Exception
+ private Fqn unmarshallFqn(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
boolean isRoot = in.readBoolean();
@@ -457,7 +465,7 @@
if (!isRoot)
{
int numElements = in.readShort();
- List elements = new ArrayList(numElements);
+ List<Object> elements = new ArrayList<Object>(numElements);
for (int i = 0; i < numElements; i++)
{
elements.add(unmarshallObject(in, refMap));
@@ -478,10 +486,10 @@
return ipAddress;
}
- private List unmarshallList(ObjectInputStream in, Map refMap) throws Exception
+ private List unmarshallList(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
int listSize = in.readInt();
- List list = new ArrayList(listSize);
+ List<Object> list = new ArrayList<Object>(listSize);
for (int i = 0; i < listSize; i++)
{
list.add(unmarshallObject(in, refMap));
@@ -489,11 +497,11 @@
return list;
}
- private Map unmarshallMap(ObjectInputStream in, Map refMap) throws Exception
+ private Map unmarshallMap(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
{
int mapSize = in.readInt();
if (mapSize == 0) return Collections.emptyMap();
- Map map = new HashMap(mapSize);
+ Map<Object, Object> map = new HashMap<Object, Object>(mapSize);
for (int i = 0; i < mapSize; i++)
{
map.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
More information about the jboss-cvs-commits
mailing list