Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 197   Methods: 8
NCLOC: 137   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractMarshaller.java 64.3% 70.4% 62.5% 68.8%
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.BuddyManager;
 15    import org.jboss.cache.transaction.GlobalTransaction;
 16   
 17    import java.io.ByteArrayOutputStream;
 18    import java.io.InputStream;
 19    import java.io.ObjectInputStream;
 20    import java.io.ObjectOutputStream;
 21    import java.util.List;
 22    import java.util.Map;
 23    import java.util.concurrent.ConcurrentHashMap;
 24   
 25    /**
 26    * Abstract AbstractMarshaller for JBoss Cache.
 27    *
 28    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 29    */
 30    public abstract class AbstractMarshaller implements Marshaller
 31    {
 32    protected boolean useRegionBasedMarshalling;
 33    protected RegionManager regionManager;
 34    protected boolean defaultInactive;
 35    private static Log log = LogFactory.getLog(AbstractMarshaller.class);
 36   
 37    /**
 38    * Map<GlobalTransaction, Fqn> for prepared tx that have not committed
 39    */
 40    private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
 41   
 42  1504 protected void init(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
 43    {
 44  1504 this.useRegionBasedMarshalling = useRegionBasedMarshalling;
 45  1504 this.defaultInactive = defaultInactive;
 46  1504 this.regionManager = manager;
 47    }
 48   
 49    // implement the basic contract set in RPcDispatcher.AbstractMarshaller
 50  0 public byte[] objectToByteBuffer(Object obj) throws Exception
 51    {
 52  0 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 53  0 ObjectOutputStream out = ObjectSerializationFactory.createObjectOutputStream(baos);
 54  0 objectToObjectStream(obj, out);
 55  0 out.close();
 56  0 return baos.toByteArray();
 57    }
 58   
 59  0 public Object objectFromByteBuffer(byte[] bytes) throws Exception
 60    {
 61  0 ObjectInputStream in = ObjectSerializationFactory.createObjectInputStream(bytes);
 62  0 return objectFromObjectStream(in);
 63    }
 64   
 65  0 public Object objectFromStream(InputStream in) throws Exception
 66    {
 67    // by default just create an OIS from this IS and pass in to the relevant method
 68  0 if (in instanceof ObjectInputStream)
 69    {
 70  0 return objectFromObjectStream((ObjectInputStream) in);
 71    }
 72    else
 73    {
 74  0 return objectFromObjectStream(ObjectSerializationFactory.createObjectInputStream(in));
 75    }
 76    }
 77   
 78    /**
 79    * This is "replicate" call with a single MethodCall argument.
 80    *
 81    * @param call
 82    */
 83  20225 protected Fqn extractFqnFromMethodCall(MethodCall call)
 84    {
 85  20225 MethodCall c0 = (MethodCall) call.getArgs()[0];
 86  20225 return extractFqn(c0);
 87    }
 88   
 89    /**
 90    * This is "replicate" call with a list of MethodCall argument.
 91    *
 92    * @param call
 93    */
 94  1 protected Fqn extractFqnFromListOfMethodCall(MethodCall call)
 95    {
 96  1 Object[] args = call.getArgs();
 97    // We simply pick the first one and assume everyone will need to operate under the same region!
 98  1 MethodCall c0 = (MethodCall) ((List) args[0]).get(0);
 99  1 return extractFqn(c0);
 100    }
 101   
 102  140292 protected Fqn extractFqn(MethodCall methodCall)
 103    {
 104  140292 if (methodCall == null)
 105    {
 106  0 throw new NullPointerException("method call is null");
 107    }
 108   
 109  140292 Fqn fqn = null;
 110  140292 Object[] args = methodCall.getArgs();
 111  140292 switch (methodCall.getMethodId())
 112    {
 113  0 case MethodDeclarations.optimisticPrepareMethod_id:
 114  10 case MethodDeclarations.prepareMethod_id:
 115    // Prepare method has a list of modifications. We will just take the first one and extract.
 116  10 List modifications = (List) args[1];
 117  10 fqn = extractFqn((MethodCall) modifications.get(0));
 118   
 119    // the last arg of a prepare call is the one-phase flag
 120  10 boolean one_phase_commit = (Boolean) args[args.length - 1];
 121   
 122    // If this is two phase commit, map the FQN to the GTX so
 123    // we can find it when the commit/rollback comes through
 124  10 if (!one_phase_commit)
 125    {
 126  4 transactions.put((GlobalTransaction) args[0], fqn);
 127    }
 128  10 break;
 129  1 case MethodDeclarations.rollbackMethod_id:
 130  3 case MethodDeclarations.commitMethod_id:
 131    // We stored the fqn in the transactions map during the prepare phase
 132  4 fqn = transactions.remove(args[0]);
 133  4 break;
 134  0 case MethodDeclarations.getPartialStateMethod_id:
 135  1 case MethodDeclarations.dataGravitationMethod_id:
 136  8 case MethodDeclarations.evictNodeMethodLocal_id:
 137  0 case MethodDeclarations.evictVersionedNodeMethodLocal_id:
 138  40005 case MethodDeclarations.getChildrenNamesMethodLocal_id:
 139  20017 case MethodDeclarations.getDataMapMethodLocal_id:
 140  0 case MethodDeclarations.getKeysMethodLocal_id:
 141  1 case MethodDeclarations.getKeyValueMethodLocal_id:
 142  5 case MethodDeclarations.existsMethod_id:
 143  60037 fqn = (Fqn) args[0];
 144  60037 break;
 145  0 case MethodDeclarations.dataGravitationCleanupMethod_id:
 146  0 fqn = (Fqn) args[1];
 147  0 break;
 148  8 case MethodDeclarations.remoteAnnounceBuddyPoolNameMethod_id:
 149  8 case MethodDeclarations.remoteAssignToBuddyGroupMethod_id:
 150  0 case MethodDeclarations.remoteRemoveFromBuddyGroupMethod_id:
 151  16 break;
 152  1 case MethodDeclarations.replicateMethod_id:
 153  60028 case MethodDeclarations.clusteredGetMethod_id:
 154    // possible when we have a replication queue.
 155  60029 fqn = extractFqn((MethodCall) args[0]);
 156  60029 break;
 157  20196 default:
 158  20196 if (MethodDeclarations.isCrudMethod(methodCall.getMethodId()))
 159    {
 160  20196 fqn = (Fqn) args[1];
 161    }
 162    else
 163    {
 164  0 throw new IllegalArgumentException("AbstractMarshaller.extractFqn(): Unknown id in method call: " + methodCall);
 165    }
 166  20196 break;
 167   
 168    }
 169   
 170  140292 if (log.isTraceEnabled())
 171    {
 172  0 log.trace("extract(): received " + methodCall + "extracted fqn: " + fqn);
 173    }
 174   
 175  140292 return fqn;
 176    }
 177   
 178    /**
 179    * Retrieves the {@link Region} from the {@link RegionManager} after taking into account that this may be a Buddy Backup Fqn.
 180    * If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.
 181    *
 182    * @param fqn of the region to locate
 183    * @return a region
 184    */
 185  220865 protected Region getRegion(Fqn fqn)
 186    {
 187  16 if (fqn == null) return null;
 188  220849 if (BuddyManager.isBackupFqn(fqn))
 189    {
 190    // Strip out the buddy group portion
 191  4 fqn = BuddyManager.getActualFqn(fqn);
 192    }
 193  220849 Region r = regionManager.getRegion(fqn, Region.Type.MARSHALLING, false);
 194  220847 return r;
 195    //return r != null && r.isActive() ? r : null;
 196    }
 197    }