Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 164   Methods: 16
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PojoInstance.java 64.3% 61.3% 56.2% 60.7%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.pojo.impl;
 8   
 9    import org.jboss.cache.Fqn;
 10   
 11    import java.io.Serializable;
 12    import java.util.ArrayList;
 13    import java.util.Collections;
 14    import java.util.List;
 15   
 16    /**
 17    * POJO class metadata information.
 18    * When an object is looked up or put in PojoCache, this object will be advised with a CacheFieldInterceptor.
 19    * The underlying cache stores a reference to this object (for example to update the instance variables, etc.).
 20    * Since this reference need to be transactional but never replicated (the reference is only valid
 21    * within the VM this reference is thus stored into an PojoReference (as a transient field).
 22    * In addition, this instance also serves as a metadata for PojoCache. E.g., it has a reference counting for
 23    * multiple references and reference FQN.
 24    *
 25    * @author Ben Wang
 26    */
 27    public class PojoInstance implements Serializable // Externalizable is no more efficient
 28    {
 29    // protected static Log log=LogFactory.getLog(PojoReference.class.getLastElementAsString());
 30    public static final String KEY = InternalConstant.POJOCACHE_KEY_PREFIX + "PojoInstance";
 31    public static final int INITIAL_COUNTER_VALUE = -1;
 32   
 33    static final long serialVersionUID = 6492134565825613209L;
 34   
 35    // The instance is transient to avoid replication outside the VM
 36    private transient Object instance_;
 37   
 38    // If not null, it signifies that this is a reference that points to this fqn.
 39    // Note that this will get replicated.
 40    private String internalFqn_ = null;
 41   
 42    // Reference counting. THis will get replicated as well. This keep track of number of
 43    // other instances that referenced this fqn.
 44    private int refCount_ = INITIAL_COUNTER_VALUE;
 45   
 46    // List of fqns that reference this fqn. Assume list size is not big since it may not be efficient.
 47    private List<Fqn> referencedBy_ = null;
 48    private Class clazz_ = null;
 49    private transient PojoUtil util_ = new PojoUtil();
 50   
 51  7439 public PojoInstance()
 52    {
 53    }
 54   
 55  0 public PojoInstance(Object instance)
 56    {
 57  0 set(instance);
 58    }
 59   
 60  7439 public void setPojoClass(Class clazz)
 61    {
 62  7439 clazz_ = clazz;
 63    }
 64   
 65  321 public Class getPojoClass()
 66    {
 67  321 return clazz_;
 68    }
 69   
 70  19363 public Object get()
 71    {
 72  19363 return instance_;
 73    }
 74   
 75  9432 public void set(Object instance)
 76    {
 77  9432 instance_ = instance;
 78    }
 79   
 80  0 public String getInternalFqn()
 81    {
 82  0 return internalFqn_;
 83    }
 84   
 85  0 public void setInternalFqn(String refFqn)
 86    {
 87  0 internalFqn_ = refFqn;
 88    }
 89   
 90  0 public void removeInternalFqn()
 91    {
 92  0 internalFqn_ = null;
 93    }
 94   
 95  4134 synchronized public int incrementRefCount(Fqn sourceFqn)
 96    {
 97  4134 if (sourceFqn == null)
 98    {
 99  0 throw new IllegalStateException("PojoInstance.incrementRefCount(): null sourceFqn");
 100    }
 101   
 102  4134 if (referencedBy_ == null)
 103    {
 104  3942 referencedBy_ = new ArrayList();
 105    }
 106   
 107  4134 if (referencedBy_.contains(sourceFqn))
 108  0 throw new IllegalStateException("PojoReference.incrementRefCount(): source fqn: " +
 109    sourceFqn + " is already present.");
 110   
 111  0 if (util_ == null) util_ = new PojoUtil();
 112  4134 refCount_ = util_.incrementReferenceCount(sourceFqn, refCount_, referencedBy_);
 113    // referencedBy_.add(sourceFqn);
 114   
 115    // refCount_ += 1;
 116    //logger_.info("incrementRefCount(): current ref count " +refCount_);
 117  4134 return refCount_;
 118    }
 119   
 120  38 synchronized public int decrementRefCount(Fqn sourceFqn)
 121    {
 122  38 if (sourceFqn == null)
 123    {
 124  0 throw new IllegalStateException("PojoInstance.incrementRefCount(): null sourceFqn");
 125    }
 126   
 127  38 if (!referencedBy_.contains(sourceFqn))
 128  0 throw new IllegalStateException("PojoReference.decrementRefCount(): source fqn: " +
 129    sourceFqn + " is not present.");
 130   
 131  10 if (util_ == null) util_ = new PojoUtil();
 132  38 refCount_ = util_.decrementReferenceCount(sourceFqn, refCount_, referencedBy_);
 133    // referencedBy_.remove(sourceFqn);
 134   
 135    // refCount_ -= 1;
 136    //logger_.info("decrementRefCount(): current ref count " +refCount_);
 137  38 return refCount_;
 138    }
 139   
 140  6316 synchronized public int getRefCount()
 141    {
 142  6316 return refCount_;
 143    }
 144   
 145  0 public List<Fqn> getReferences()
 146    {
 147  0 return Collections.unmodifiableList(referencedBy_);
 148    }
 149   
 150  0 synchronized public Fqn getAndRemoveFirstFqnInList()
 151    {
 152  0 return (Fqn) referencedBy_.remove(0);
 153    }
 154   
 155  0 synchronized public void addXFqnIntoList(Fqn fqn)
 156    {
 157  0 referencedBy_.add(0, fqn);
 158    }
 159   
 160  160 public String toString()
 161    {
 162  160 return "PI[fqn=" + internalFqn_ + " ref=" + refCount_ + " class=" + clazz_.getName() + "]";
 163    }
 164    }