Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 763   Methods: 36
NCLOC: 664   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheMarshaller200.java 86% 90.9% 94.4% 89.9%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.marshall;
 8   
 9    import org.apache.commons.logging.Log;
 10    import org.apache.commons.logging.LogFactory;
 11    import org.jboss.cache.Fqn;
 12    import org.jboss.cache.Region;
 13    import org.jboss.cache.RegionManager;
 14    import org.jboss.cache.buddyreplication.GravitateResult;
 15    import org.jboss.cache.optimistic.DefaultDataVersion;
 16    import org.jboss.cache.transaction.GlobalTransaction;
 17    import org.jboss.cache.util.MapCopy;
 18    import org.jgroups.Address;
 19    import org.jgroups.stack.IpAddress;
 20   
 21    import java.io.Externalizable;
 22    import java.io.IOException;
 23    import java.io.ObjectInputStream;
 24    import java.io.ObjectOutputStream;
 25    import java.io.Serializable;
 26    import java.util.ArrayList;
 27    import java.util.Collection;
 28    import java.util.HashMap;
 29    import java.util.HashSet;
 30    import java.util.LinkedList;
 31    import java.util.List;
 32    import java.util.Map;
 33    import java.util.Set;
 34    import java.util.TreeMap;
 35    import java.util.TreeSet;
 36   
 37    /**
 38    * An enhanced marshaller for RPC calls between CacheImpl instances.
 39    *
 40    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 41    */
 42    public class CacheMarshaller200 extends AbstractMarshaller
 43    {
 44    // logger
 45    private Log log = LogFactory.getLog(CacheMarshaller200.class);
 46   
 47    // magic numbers
 48    protected static final int MAGICNUMBER_METHODCALL = 1;
 49    protected static final int MAGICNUMBER_FQN = 2;
 50    protected static final int MAGICNUMBER_GTX = 3;
 51    protected static final int MAGICNUMBER_IPADDRESS = 4;
 52    protected static final int MAGICNUMBER_ARRAY_LIST = 5;
 53    protected static final int MAGICNUMBER_INTEGER = 6;
 54    protected static final int MAGICNUMBER_LONG = 7;
 55    protected static final int MAGICNUMBER_BOOLEAN = 8;
 56    protected static final int MAGICNUMBER_STRING = 9;
 57    protected static final int MAGICNUMBER_DEFAULT_DATA_VERSION = 10;
 58    protected static final int MAGICNUMBER_LINKED_LIST = 11;
 59    protected static final int MAGICNUMBER_HASH_MAP = 12;
 60    protected static final int MAGICNUMBER_TREE_MAP = 13;
 61    protected static final int MAGICNUMBER_HASH_SET = 14;
 62    protected static final int MAGICNUMBER_TREE_SET = 15;
 63    protected static final int MAGICNUMBER_NODEDATA_MARKER = 16;
 64    protected static final int MAGICNUMBER_NODEDATA_EXCEPTION_MARKER = 17;
 65    protected static final int MAGICNUMBER_NODEDATA = 18;
 66    protected static final int MAGICNUMBER_GRAVITATERESULT = 19;
 67    protected static final int MAGICNUMBER_SHORT = 20;
 68    protected static final int MAGICNUMBER_MAPCOPY = 21;
 69    protected static final int MAGICNUMBER_NULL = 99;
 70    protected static final int MAGICNUMBER_SERIALIZABLE = 100;
 71    protected static final int MAGICNUMBER_REF = 101;
 72   
 73    protected static final InactiveRegionException IRE = new InactiveRegionException("Cannot unmarshall to an inactive region");
 74   
 75    // this is pretty nasty, and may need more thought.
 76    protected final ThreadLocal<Fqn> regionForCall = new ThreadLocal<Fqn>();
 77   
 78  1504 public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
 79    {
 80  1504 init(manager, defaultInactive, useRegionBasedMarshalling);
 81  1504 if (useRegionBasedMarshalling)
 82    {
 83  145 log.debug("Using region based marshalling logic : marshalling Fqn as a String first for every call.");
 84    }
 85    }
 86   
 87    /**
 88    * Tests if the type of object being marshalled is a method call or a return value
 89    *
 90    * @param o object to marshall
 91    * @return true if the object is a return value to a method call; false otherwise
 92    */
 93  281849 protected boolean isReturnValue(Object o)
 94    {
 95  281849 return !(o instanceof MethodCall);
 96    }
 97   
 98    // -------- AbstractMarshaller interface
 99   
 100  363357 public void objectToObjectStream(Object o, ObjectOutputStream out) throws Exception
 101    {
 102  363357 if (useRegionBasedMarshalling)
 103    {
 104  161512 Fqn region;
 105  161512 if (o == null)
 106    {
 107    // if the return value we're trying to marshall is null we're easy ...
 108  20181 region = null;
 109    }
 110  141331 else if (isReturnValue(o))
 111    {
 112    // we are marshalling a return value from a method call.
 113    // let's see if an incoming unmarshalling call for this exists, in the same thread stack and had registered
 114    // a Fqn region.
 115  61078 region = regionForCall.get();
 116   
 117    // otherwise, we need to marshall the retval.
 118    }
 119    else
 120    {
 121    // this is an outgoing method call.
 122    // we first marshall the Fqn as a String
 123  80253 MethodCall call = (MethodCall) o;
 124  80253 region = extractFqnRegion(call);
 125    }
 126  0 if (log.isTraceEnabled()) log.trace("Region based call. Using region " + region);
 127  161512 objectToObjectStream(o, out, region);
 128    }
 129    else
 130    {
 131    // not region based!
 132  0 if (log.isTraceEnabled()) log.trace("Marshalling object " + o);
 133  201845 Map<Object, Integer> refMap = new HashMap<Object, Integer>();
 134  201845 marshallObject(o, out, refMap);
 135    }
 136    }
 137   
 138  367203 public Object objectFromObjectStream(ObjectInputStream in) throws Exception
 139    {
 140  367203 if (useRegionBasedMarshalling)
 141    {
 142  161565 return objectFromObjectStreamRegionBased(in);
 143    }
 144    else
 145    {
 146  205638 Map<Integer, Object> refMap = new HashMap<Integer, Object>();
 147  205638 Object retValue = unmarshallObject(in, refMap);
 148  0 if (log.isTraceEnabled()) log.trace("Unmarshalled object " + retValue);
 149  205638 return retValue;
 150    }
 151    }
 152   
 153  162355 public void objectToObjectStream(Object o, ObjectOutputStream out, Fqn region) throws Exception
 154    {
 155  0 if (log.isTraceEnabled()) log.trace("Marshalling object " + o);
 156  162355 Map<Object, Integer> refMap = new HashMap<Object, Integer>();
 157  162355 if (useRegionBasedMarshalling) // got to check again in case this meth is called directly
 158    {
 159  161686 log.trace("Writing region " + region + " to stream");
 160  161686 marshallObject(region, out, refMap);
 161    }
 162  162355 marshallObject(o, out, refMap);
 163    }
 164   
 165  161565 protected Object objectFromObjectStreamRegionBased(ObjectInputStream in) throws Exception
 166    {
 167  161565 Map<Integer, Object> refMap = new HashMap<Integer, Object>();
 168  161565 Object o = unmarshallObject(in, refMap);
 169  161565 Fqn regionFqn = null;
 170  161565 if (o == null)
 171    {
 172    // a null region. Could happen. Use std marshalling.
 173  20953 log.trace("Unmarshalled region as null. Not using a context class loader to unmarshall.");
 174    }
 175    else
 176    {
 177  140612 regionFqn = (Fqn) o;
 178    }
 179   
 180  0 if (log.isTraceEnabled()) log.trace("Unmarshalled regionFqn " + regionFqn + " from stream");
 181   
 182  161565 Region region = null;
 183  161565 Object retValue;
 184   
 185  161565 if (regionFqn != null)
 186    {
 187  140612 region = findRegion(regionFqn);
 188    }
 189  161508 if (region == null)
 190    {
 191  20990 retValue = unmarshallObject(in, refMap);
 192    }
 193    else
 194    {
 195  140518 retValue = unmarshallObject(in, region.getClassLoader(), refMap);
 196   
 197    // only set this if this is an incoming method call and not a return value.
 198  80219 if (!isReturnValue(retValue)) regionForCall.set(regionFqn);
 199    }
 200  0 if (log.isTraceEnabled()) log.trace("Unmarshalled object " + retValue);
 201  161508 return retValue;
 202    }
 203   
 204  140612 private Region findRegion(Fqn fqn) throws InactiveRegionException
 205    {
 206  140612 Region region = getRegion(fqn);
 207   
 208  140612 if (region != null)
 209    {
 210  140522 if (!region.isActive())
 211    {
 212  4 if (log.isDebugEnabled())
 213    {
 214  0 throw new InactiveRegionException("Cannot unmarshall message for region " + fqn + ". This region is inactive.");
 215    }
 216    else
 217    {
 218  4 throw IRE;
 219    }
 220    }
 221    }
 222  90 else if (defaultInactive)
 223    {
 224  53 if (log.isDebugEnabled())
 225    {
 226    // No region but default inactive means region is inactive
 227  0 throw new InactiveRegionException("Cannot unmarshall message for region " + fqn + ". By default region " + fqn
 228    + " is inactive.");
 229    }
 230    else
 231    {
 232  53 throw IRE;
 233    }
 234    }
 235   
 236  140555 return region;
 237    }
 238   
 239  80253 private Fqn extractFqnRegion(MethodCall call) throws Exception
 240    {
 241  80253 Fqn fqn;
 242  80252 if (call.getMethod().equals(MethodDeclarations.replicateMethod))
 243    {
 244  20225 fqn = extractFqnFromMethodCall(call);
 245    }
 246  60028 else if (call.getMethod().equals(MethodDeclarations.replicateAllMethod))
 247    {
 248  1 fqn = extractFqnFromListOfMethodCall(call);
 249    }
 250    else
 251    {
 252  60027 fqn = extractFqn(call);
 253    }
 254   
 255  80253 Region r = getRegion(fqn);
 256  80253 return r == null ? null : r.getFqn();
 257    }
 258   
 259    // --------- Marshalling methods
 260   
 261  2939463 private void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 262    {
 263  2939450 if (o == null)
 264    {
 265  106290 out.writeByte(MAGICNUMBER_NULL);
 266    }
 267  2833163 else if (refMap.containsKey(o))// see if this object has been marshalled before.
 268    {
 269  144868 out.writeByte(MAGICNUMBER_REF);
 270  144868 out.writeShort(refMap.get(o));
 271    }
 272  2688305 else if (o instanceof MethodCall)
 273    {
 274    // first see if this is a 'known' method call.
 275  331206 MethodCall call = (MethodCall) o;
 276   
 277  331206 if (call.getMethodId() > -1)
 278    {
 279  331206 out.writeByte(MAGICNUMBER_METHODCALL);
 280  331206 marshallMethodCall(call, out, refMap);
 281    }
 282    else
 283    {
 284  0 throw new IllegalArgumentException("MethodCall does not have a valid method id. Was this method call created with MethodCallFactory?");
 285    }
 286    }
 287  2357079 else if (o instanceof Fqn)
 288    {
 289  304111 int refId = createReference(o, refMap);
 290  304109 out.writeByte(MAGICNUMBER_FQN);
 291  304111 out.writeShort(refId);
 292  304111 marshallFqn((Fqn) o, out, refMap);
 293    }
 294  2052988 else if (o instanceof GlobalTransaction)
 295    {
 296  1444 int refId = createReference(o, refMap);
 297  1444 out.writeByte(MAGICNUMBER_GTX);
 298  1444 out.writeShort(refId);
 299  1444 marshallGlobalTransaction((GlobalTransaction) o, out, refMap);
 300    }
 301  2051544 else if (o instanceof IpAddress)
 302    {
 303  2457 out.writeByte(MAGICNUMBER_IPADDRESS);
 304  2457 marshallIpAddress((IpAddress) o, out);
 305    }
 306  2049082 else if (o instanceof DefaultDataVersion)
 307    {
 308  173 out.writeByte(MAGICNUMBER_DEFAULT_DATA_VERSION);
 309  173 out.writeLong(((DefaultDataVersion) o).getRawVersion());
 310    }
 311  2048914 else if (o.getClass().equals(ArrayList.class))
 312    {
 313  120239 out.writeByte(MAGICNUMBER_ARRAY_LIST);
 314  120239 marshallCollection((Collection) o, out, refMap);
 315    }
 316  1928675 else if (o.getClass().equals(LinkedList.class))
 317    {
 318  1431 out.writeByte(MAGICNUMBER_LINKED_LIST);
 319  1431 marshallCollection((Collection) o, out, refMap);
 320    }
 321  1927244 else if (o.getClass().equals(HashMap.class))
 322    {
 323  33302 out.writeByte(MAGICNUMBER_HASH_MAP);
 324  33302 marshallMap((Map) o, out, refMap);
 325    }
 326  1893942 else if (o.getClass().equals(TreeMap.class))
 327    {
 328  0 out.writeByte(MAGICNUMBER_TREE_MAP);
 329  0 marshallMap((Map) o, out, refMap);
 330    }
 331  1893942 else if (o.getClass().equals(MapCopy.class))
 332    {
 333  40142 out.writeByte(MAGICNUMBER_MAPCOPY);
 334  40142 marshallMap((Map) o, out, refMap);
 335    }
 336  1853792 else if (o.getClass().equals(HashSet.class))
 337    {
 338  40008 out.writeByte(MAGICNUMBER_HASH_SET);
 339  40008 marshallCollection((Collection) o, out, refMap);
 340    }
 341  1813792 else if (o.getClass().equals(TreeSet.class))
 342    {
 343  0 out.writeByte(MAGICNUMBER_TREE_SET);
 344  0 marshallCollection((Collection) o, out, refMap);
 345    }
 346  1813792 else if (o instanceof Boolean)
 347    {
 348  287550 out.writeByte(MAGICNUMBER_BOOLEAN);
 349  287550 out.writeBoolean(((Boolean) o).booleanValue());
 350    }
 351  1526242 else if (o instanceof Integer)
 352    {
 353  51155 out.writeByte(MAGICNUMBER_INTEGER);
 354  51155 out.writeInt(((Integer) o).intValue());
 355    }
 356  1475087 else if (o instanceof Long)
 357    {
 358  55 out.writeByte(MAGICNUMBER_LONG);
 359  55 out.writeLong(((Long) o).longValue());
 360    }
 361  1475032 else if (o instanceof Short)
 362    {
 363  722 out.writeByte(MAGICNUMBER_SHORT);
 364  722 out.writeShort(((Short) o).shortValue());
 365    }
 366  1474310 else if (o instanceof String)
 367    {
 368  1418470 int refId = createReference(o, refMap);
 369  1418470 out.writeByte(MAGICNUMBER_STRING);
 370  1418470 out.writeShort(refId);
 371  1418470 marshallString((String) o, out);
 372    }
 373  55840 else if (o instanceof NodeDataMarker)
 374    {
 375  2201 out.writeByte(MAGICNUMBER_NODEDATA_MARKER);
 376  2201 ((Externalizable) o).writeExternal(out);
 377    }
 378  53639 else if (o instanceof NodeDataExceptionMarker)
 379    {
 380  2 out.writeByte(MAGICNUMBER_NODEDATA_EXCEPTION_MARKER);
 381  2 ((Externalizable) o).writeExternal(out);
 382    }
 383  53637 else if (o instanceof NodeData)
 384    {
 385  11438 out.writeByte(MAGICNUMBER_NODEDATA);
 386  11438 ((Externalizable) o).writeExternal(out);
 387    }
 388  42199 else if (o instanceof GravitateResult)
 389    {
 390  52 out.writeByte(MAGICNUMBER_GRAVITATERESULT);
 391  52 marshallGravitateResult((GravitateResult) o, out, refMap);
 392    }
 393  42147 else if (o instanceof Serializable)
 394    {
 395  42147 int refId = createReference(o, refMap);
 396  42147 if (log.isTraceEnabled())
 397    {
 398  0 log.trace("Warning: using object serialization for " + o.getClass());
 399    }
 400  42147 out.writeByte(MAGICNUMBER_SERIALIZABLE);
 401  42147 out.writeShort(refId);
 402  42147 out.writeObject(o);
 403    }
 404    else
 405    {
 406  0 throw new Exception("Don't know how to marshall object of type " + o.getClass());
 407    }
 408    }
 409   
 410  52 private void marshallGravitateResult(GravitateResult gravitateResult, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 411    {
 412  52 marshallObject(gravitateResult.isDataFound(), out, refMap);
 413  52 if (gravitateResult.isDataFound())
 414    {
 415  36 marshallObject(gravitateResult.getNodeData(), out, refMap);
 416  36 marshallObject(gravitateResult.getBuddyBackupFqn(), out, refMap);
 417    }
 418   
 419    }
 420   
 421  1766172 private int createReference(Object o, Map<Object, Integer> refMap)
 422    {
 423  1766172 int reference = refMap.size();
 424  1766172 refMap.put(o, reference);
 425  1766172 return reference;
 426    }
 427   
 428  1418470 private void marshallString(String s, ObjectOutputStream out) throws Exception
 429    {
 430    //StringUtil.saveString(out, s);
 431  1418464 out.writeObject(s);
 432    }
 433   
 434  331206 private void marshallMethodCall(MethodCall methodCall, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 435    {
 436  331206 out.writeShort(methodCall.getMethodId());
 437  331206 Object[] args = methodCall.getArgs();
 438  331204 byte numArgs = (byte) (args == null ? 0 : args.length);
 439  331206 out.writeByte(numArgs);
 440   
 441  331206 for (int i = 0; i < numArgs; i++)
 442    {
 443  634705 marshallObject(args[i], out, refMap);
 444    }
 445    }
 446   
 447  1444 private void marshallGlobalTransaction(GlobalTransaction globalTransaction, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 448    {
 449  1444 out.writeLong(globalTransaction.getId());
 450  1444 marshallObject(globalTransaction.getAddress(), out, refMap);
 451    }
 452   
 453   
 454  304111 private void marshallFqn(Fqn fqn, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 455    {
 456  304105 boolean isRoot = fqn.isRoot();
 457  304111 out.writeBoolean(isRoot);
 458  304111 if (!isRoot)
 459    {
 460  303837 out.writeShort(fqn.size());
 461  303837 for (int i = 0; i < fqn.size(); i++)
 462    {
 463  671573 marshallObject(fqn.get(i), out, refMap);
 464    }
 465    }
 466    }
 467   
 468  2457 private void marshallIpAddress(IpAddress ipAddress, ObjectOutputStream out) throws Exception
 469    {
 470  2457 ipAddress.writeExternal(out);
 471    }
 472   
 473  161678 private void marshallCollection(Collection c, ObjectOutputStream out, Map refMap) throws Exception
 474    {
 475  161678 out.writeInt(c.size());
 476  161678 for (Object o : c)
 477    {
 478  875777 marshallObject(o, out, refMap);
 479    }
 480    }
 481   
 482  73444 private void marshallMap(Map map, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
 483    {
 484  73444 int mapSize = map.size();
 485  73444 out.writeInt(mapSize);
 486  11621 if (mapSize == 0) return;
 487   
 488  61823 for (Map.Entry me : (Set<Map.Entry>) map.entrySet())
 489    {
 490  114977 marshallObject(me.getKey(), out, refMap);
 491  114977 marshallObject(me.getValue(), out, refMap);
 492    }
 493    }
 494   
 495    // --------- Unmarshalling methods
 496   
 497  140518 private Object unmarshallObject(ObjectInputStream in, ClassLoader loader, Map<Integer, Object> refMap) throws Exception
 498    {
 499  140518 if (loader == null)
 500    {
 501  0 return unmarshallObject(in, refMap);
 502    }
 503    else
 504    {
 505  140518 Thread currentThread = Thread.currentThread();
 506  140518 ClassLoader old = currentThread.getContextClassLoader();
 507  140518 try
 508    {
 509  140518 currentThread.setContextClassLoader(loader);
 510  140518 return unmarshallObject(in, refMap);
 511    }
 512    finally
 513    {
 514  140518 currentThread.setContextClassLoader(old);
 515    }
 516    }
 517    }
 518   
 519  2956297 private Object unmarshallObject(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 520    {
 521  2956289 byte magicNumber = in.readByte();
 522  2956297 Integer reference;
 523  2956297 Object retVal;
 524  2956297 switch (magicNumber)
 525    {
 526  106379 case MAGICNUMBER_NULL:
 527  106379 return null;
 528  148165 case MAGICNUMBER_REF:
 529  148165 reference = (int) in.readShort();
 530  148165 if (!refMap.containsKey(reference))
 531    {
 532  0 throw new IOException("Unable to locate object reference " + reference + " in byte stream!");
 533    }
 534  148165 return refMap.get(reference);
 535  42451 case MAGICNUMBER_SERIALIZABLE:
 536  42451 reference = (int) in.readShort();
 537  42451 retVal = in.readObject();
 538  42451 refMap.put(reference, retVal);
 539  42451 return retVal;
 540  331817 case MAGICNUMBER_METHODCALL:
 541  331817 retVal = unmarshallMethodCall(in, refMap);
 542  331817 return retVal;
 543  304219 case MAGICNUMBER_FQN:
 544  304219 reference = (int) in.readShort();
 545  304219 retVal = unmarshallFqn(in, refMap);
 546  304219 refMap.put(reference, retVal);
 547  304219 return retVal;
 548  1457 case MAGICNUMBER_GTX:
 549  1457 reference = (int) in.readShort();
 550  1457 retVal = unmarshallGlobalTransaction(in, refMap);
 551  1457 refMap.put(reference, retVal);
 552  1457 return retVal;
 553  2687 case MAGICNUMBER_IPADDRESS:
 554  2687 retVal = unmarshallIpAddress(in);
 555  2687 return retVal;
 556  176 case MAGICNUMBER_DEFAULT_DATA_VERSION:
 557  176 retVal = new DefaultDataVersion(in.readLong());
 558  176 return retVal;
 559  120228 case MAGICNUMBER_ARRAY_LIST:
 560  120228 return unmarshallArrayList(in, refMap);
 561  1404 case MAGICNUMBER_LINKED_LIST:
 562  1404 return unmarshallLinkedList(in, refMap);
 563  36618 case MAGICNUMBER_HASH_MAP:
 564  36618 return unmarshallHashMap(in, refMap);
 565  0 case MAGICNUMBER_TREE_MAP:
 566  0 return unmarshallTreeMap(in, refMap);
 567  40001 case MAGICNUMBER_HASH_SET:
 568  40001 return unmarshallHashSet(in, refMap);
 569  0 case MAGICNUMBER_TREE_SET:
 570  0 return unmarshallTreeSet(in, refMap);
 571  40243 case MAGICNUMBER_MAPCOPY:
 572  40243 return unmarshallMapCopy(in, refMap);
 573  287634 case MAGICNUMBER_BOOLEAN:
 574  287634 return in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
 575  53525 case MAGICNUMBER_INTEGER:
 576  53525 return in.readInt();
 577  55 case MAGICNUMBER_LONG:
 578  55 return in.readLong();
 579  730 case MAGICNUMBER_SHORT:
 580  730 return in.readShort();
 581  1425537 case MAGICNUMBER_STRING:
 582  1425533 reference = (int) in.readShort();
 583  1425537 retVal = unmarshallString(in);
 584  1425537 refMap.put(reference, retVal);
 585  1425537 return retVal;
 586  1501 case MAGICNUMBER_NODEDATA_MARKER:
 587  1501 retVal = new NodeDataMarker();
 588  1501 ((NodeDataMarker) retVal).readExternal(in);
 589  1501 return retVal;
 590  2 case MAGICNUMBER_NODEDATA_EXCEPTION_MARKER:
 591  2 retVal = new NodeDataExceptionMarker();
 592  2 ((NodeDataExceptionMarker) retVal).readExternal(in);
 593  2 return retVal;
 594  11416 case MAGICNUMBER_NODEDATA:
 595  11416 retVal = new NodeData();
 596  11416 ((NodeData) retVal).readExternal(in);
 597  11416 return retVal;
 598  52 case MAGICNUMBER_GRAVITATERESULT:
 599  52 return unmarshallGravitateResult(in, refMap);
 600  0 default:
 601  0 if (log.isErrorEnabled())
 602    {
 603  0 log.error("Unknown Magic Number " + magicNumber);
 604    }
 605  0 throw new Exception("Unknown magic number " + magicNumber);
 606    }
 607    }
 608   
 609  52 private GravitateResult unmarshallGravitateResult(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 610    {
 611  52 Boolean found = (Boolean) unmarshallObject(in, refMap);
 612  52 if (found)
 613    {
 614  36 List<NodeData> stuff = (List<NodeData>) unmarshallObject(in, refMap);
 615  36 Fqn fqn = (Fqn) unmarshallObject(in, refMap);
 616  36 return GravitateResult.subtreeResult(stuff, fqn);
 617    }
 618    else
 619    {
 620  16 return GravitateResult.noDataFound();
 621    }
 622    }
 623   
 624  1425537 private String unmarshallString(ObjectInputStream in) throws Exception
 625    {
 626    //return StringUtil.readString(in, null);
 627  1425537 return (String) in.readObject();
 628    }
 629   
 630  331817 private MethodCall unmarshallMethodCall(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 631    {
 632  331817 short methodId = in.readShort();
 633  331817 byte numArgs = in.readByte();
 634  331815 Object[] args = null;
 635   
 636  331817 if (numArgs > 0)
 637    {
 638  331817 args = new Object[numArgs];
 639   
 640  331817 for (int i = 0; i < numArgs; i++)
 641    {
 642  635836 args[i] = unmarshallObject(in, refMap);
 643    }
 644    }
 645  331817 return MethodCallFactory.create(MethodDeclarations.lookupMethod(methodId), args);
 646    }
 647   
 648  1457 private GlobalTransaction unmarshallGlobalTransaction(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 649    {
 650  1457 GlobalTransaction gtx = new GlobalTransaction();
 651  1457 long id = in.readLong();
 652  1457 Object address = unmarshallObject(in, refMap);
 653  1457 gtx.setId(id);
 654  1457 gtx.setAddress((Address) address);
 655  1457 return gtx;
 656    }
 657   
 658  304219 private Fqn unmarshallFqn(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 659    {
 660   
 661  304219 boolean isRoot = in.readBoolean();
 662  304219 Fqn fqn;
 663  304219 if (!isRoot)
 664    {
 665  303919 int numElements = in.readShort();
 666  303919 List<Object> elements = new ArrayList<Object>(numElements);
 667  303919 for (int i = 0; i < numElements; i++)
 668    {
 669  671830 elements.add(unmarshallObject(in, refMap));
 670    }
 671  303919 fqn = new Fqn(elements);
 672    }
 673    else
 674    {
 675  300 fqn = Fqn.ROOT;
 676    }
 677  304219 return fqn;
 678    }
 679   
 680  2687 private IpAddress unmarshallIpAddress(ObjectInputStream in) throws Exception
 681    {
 682  2687 IpAddress ipAddress = new IpAddress();
 683  2687 ipAddress.readExternal(in);
 684  2687 return ipAddress;
 685    }
 686   
 687  120228 private List unmarshallArrayList(ObjectInputStream in, Map refMap) throws Exception
 688    {
 689  120228 int listSize = in.readInt();
 690  120228 List list = new ArrayList(listSize);
 691  120228 populateFromStream(in, refMap, list, listSize);
 692  120228 return list;
 693    }
 694   
 695  1404 private List unmarshallLinkedList(ObjectInputStream in, Map refMap) throws Exception
 696    {
 697  1404 List list = new LinkedList();
 698  1404 populateFromStream(in, refMap, list, in.readInt());
 699  1404 return list;
 700    }
 701   
 702  76861 private Map unmarshallHashMap(ObjectInputStream in, Map refMap) throws Exception
 703    {
 704  76861 Map map = new HashMap();
 705  76861 populateFromStream(in, refMap, map);
 706  76861 return map;
 707    }
 708   
 709  40243 private Map unmarshallMapCopy(ObjectInputStream in, Map<Integer, Object> refMap) throws Exception
 710    {
 711    // read in as a HashMap first
 712  40243 Map m = unmarshallHashMap(in, refMap);
 713  40243 MapCopy mc = new MapCopy(m);
 714  40243 return mc;
 715    }
 716   
 717  0 private Map unmarshallTreeMap(ObjectInputStream in, Map refMap) throws Exception
 718    {
 719  0 Map map = new TreeMap();
 720  0 populateFromStream(in, refMap, map);
 721  0 return map;
 722    }
 723   
 724  40001 private Set unmarshallHashSet(ObjectInputStream in, Map refMap) throws Exception
 725    {
 726  40001 Set set = new HashSet();
 727  40001 populateFromStream(in, refMap, set);
 728  40001 return set;
 729    }
 730   
 731  0 private Set unmarshallTreeSet(ObjectInputStream in, Map refMap) throws Exception
 732    {
 733  0 Set set = new TreeSet();
 734  0 populateFromStream(in, refMap, set);
 735  0 return set;
 736    }
 737   
 738  76861 private void populateFromStream(ObjectInputStream in, Map refMap, Map mapToPopulate) throws Exception
 739    {
 740  76861 int size = in.readInt();
 741  76861 for (int i = 0; i < size; i++)
 742    {
 743  121315 mapToPopulate.put(unmarshallObject(in, refMap), unmarshallObject(in, refMap));
 744    }
 745    }
 746   
 747  40001 private void populateFromStream(ObjectInputStream in, Map refMap, Set setToPopulate) throws Exception
 748    {
 749  40001 int size = in.readInt();
 750  40001 for (int i = 0; i < size; i++)
 751    {
 752  619959 setToPopulate.add(unmarshallObject(in, refMap));
 753    }
 754    }
 755   
 756  121632 private void populateFromStream(ObjectInputStream in, Map refMap, List listToPopulate, int listSize) throws Exception
 757    {
 758  121632 for (int i = 0; i < listSize; i++)
 759    {
 760  255744 listToPopulate.add(unmarshallObject(in, refMap));
 761    }
 762    }
 763    }