[jboss-cvs] JBossCache/src/org/jboss/cache/marshall ...

Manik Surtani msurtani at jboss.com
Thu Jan 11 13:31:35 EST 2007


  User: msurtani
  Date: 07/01/11 13:31:35

  Modified:    src/org/jboss/cache/marshall  Tag: Branch_JBossCache_1_4_0
                        TreeCacheMarshaller140.java
  Log:
  Fixed collection marshalling
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +124 -10   JBossCache/src/org/jboss/cache/marshall/Attic/TreeCacheMarshaller140.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheMarshaller140.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/marshall/Attic/TreeCacheMarshaller140.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- TreeCacheMarshaller140.java	11 Nov 2006 17:50:05 -0000	1.1.2.2
  +++ TreeCacheMarshaller140.java	11 Jan 2007 18:31:35 -0000	1.1.2.3
  @@ -24,6 +24,12 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.LinkedList;
  +import java.util.TreeMap;
  +import java.util.HashSet;
  +import java.util.TreeSet;
  +import java.util.Collection;
  +import java.util.Set;
   
   /**
    * An enhanced marshaller for RPC calls between TreeCache instances.
  @@ -40,11 +46,16 @@
       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_LINKED_LIST = 10;
  +    protected static final int MAGICNUMBER_HASH_MAP = 11;
  +    protected static final int MAGICNUMBER_TREE_MAP = 12;
  +    protected static final int MAGICNUMBER_HASH_SET = 13;
  +    protected static final int MAGICNUMBER_TREE_SET = 14;
       protected static final int MAGICNUMBER_NULL = 99;
       protected static final int MAGICNUMBER_SERIALIZABLE = 100;
       protected static final int MAGICNUMBER_REF = 101;
  @@ -242,10 +253,35 @@
               out.writeByte(MAGICNUMBER_IPADDRESS);
               marshallIpAddress((IpAddress) o, out);
           }
  -        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)
           {
  @@ -329,16 +365,28 @@
           ipAddress.writeExternal(out);
       }
   
  -    private void marshallList(List l, ObjectOutputStream out, Map refMap) throws Exception
  +    private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap) throws Exception
       {
  -        out.writeInt(l.size());
  -        Iterator i = l.iterator();
  +        out.writeInt(c.size());
  +        Iterator i = c.iterator();
           while (i.hasNext())
           {
               marshallObject(i.next(), out, refMap);
           }
       }
   
  +   private void marshallMap(Map m, ObjectOutputStream out, Map refMap) throws Exception
  +   {
  +      out.writeInt(m.size());
  +      Iterator i = m.keySet().iterator();
  +      while (i.hasNext())
  +      {
  +         Object key = i.next();
  +         marshallObject(key, out, refMap);
  +         marshallObject(m.get(key), out, refMap);
  +      }
  +   }
  +
       // --------- Unmarshalling methods
   
       private Object unmarshallObject(ObjectInputStream in, ClassLoader loader, Map refMap) throws Exception
  @@ -400,8 +448,18 @@
               case MAGICNUMBER_IPADDRESS:
                   retVal = unmarshallIpAddress(in);
                   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:
  @@ -477,7 +535,7 @@
           return ipAddress;
       }
   
  -    private List unmarshallList(ObjectInputStream in, Map refMap) throws Exception
  +    private List unmarshallArrayList(ObjectInputStream in, Map refMap) throws Exception
       {
           int listSize = in.readInt();
           List list = new ArrayList(listSize);
  @@ -488,6 +546,62 @@
           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));
  +        }
  +        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;
  +    }
  +
  +
       class InactiveRegionException extends CacheException
       {
           public InactiveRegionException()
  
  
  



More information about the jboss-cvs-commits mailing list