Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 142   Methods: 15
NCLOC: 90   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
GlobalTransaction.java 100% 100% 100% 100%
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.transaction;
 8   
 9   
 10    import org.jgroups.Address;
 11   
 12    import java.io.Externalizable;
 13    import java.io.IOException;
 14    import java.io.ObjectInput;
 15    import java.io.ObjectOutput;
 16   
 17   
 18    /**
 19    * Uniquely identifies a transaction that spans all nodes in a cluster. This is used when
 20    * replicating all modifications in a transaction; the PREPARE and COMMIT (or ROLLBACK)
 21    * messages have to have a unique identifier to associate the changes with<br>
 22    *
 23    * @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 12, 2003
 24    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 25    * @version $Revision: 1.2 $
 26    */
 27    public class GlobalTransaction implements Externalizable
 28    {
 29   
 30    private static final long serialVersionUID = 8011434781266976149L;
 31   
 32    private static long sid = 0;
 33   
 34    private Address addr = null;
 35    private long id = -1;
 36    private transient boolean remote = false;
 37   
 38    // cache the hashcode
 39    private transient int hash_code = -1; // in the worst case, hashCode() returns 0, then increases, so we're safe here
 40   
 41    /**
 42    * empty ctor used by externalization
 43    */
 44  1474 public GlobalTransaction()
 45    {
 46    }
 47   
 48  1121243 private GlobalTransaction(Address addr)
 49    {
 50  1121243 this.addr = addr;
 51  1121243 id = newId();
 52    }
 53   
 54  1121243 private static synchronized long newId()
 55    {
 56  1121243 return ++sid;
 57    }
 58   
 59  1121243 public static GlobalTransaction create(Address addr)
 60    {
 61  1121243 return new GlobalTransaction(addr);
 62    }
 63   
 64  4491 public Object getAddress()
 65    {
 66  4491 return addr;
 67    }
 68   
 69  1469 public void setAddress(Address address)
 70    {
 71  1469 addr = address;
 72    }
 73   
 74  1444 public long getId()
 75    {
 76  1444 return id;
 77    }
 78   
 79  12094771 public int hashCode()
 80    {
 81  12094254 if (hash_code == -1)
 82    {
 83  1122699 hash_code = (addr != null ? addr.hashCode() : 0) + (int) id;
 84    }
 85  12094788 return hash_code;
 86    }
 87   
 88  13113017 public boolean equals(Object other)
 89    {
 90  13112958 if (this == other)
 91  12777724 return true;
 92  335293 if (!(other instanceof GlobalTransaction))
 93  734 return false;
 94   
 95  334559 GlobalTransaction otherGtx = (GlobalTransaction) other;
 96  334559 boolean aeq = (addr == null) ? (otherGtx.addr == null) : addr.equals(otherGtx.addr);
 97  334559 return aeq && (id == otherGtx.id);
 98    }
 99   
 100  1018 public String toString()
 101    {
 102  1018 StringBuffer sb = new StringBuffer();
 103  1018 sb.append("GlobalTransaction:<").append(addr).append(">:").append(id);
 104  1018 return sb.toString();
 105    }
 106   
 107  2 public void writeExternal(ObjectOutput out) throws IOException
 108    {
 109  2 out.writeObject(addr);
 110  2 out.writeLong(id);
 111    // out.writeInt(hash_code);
 112    }
 113   
 114  2 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 115    {
 116  2 addr = (Address) in.readObject();
 117  2 id = in.readLong();
 118  2 hash_code = -1;
 119    }
 120   
 121    /**
 122    * @return Returns the remote.
 123    */
 124  1249403 public boolean isRemote()
 125    {
 126  1249403 return remote;
 127    }
 128   
 129    /**
 130    * @param remote The remote to set.
 131    */
 132  1473 public void setRemote(boolean remote)
 133    {
 134  1473 this.remote = remote;
 135    }
 136   
 137   
 138  1457 public void setId(long id)
 139    {
 140  1457 this.id = id;
 141    }
 142    }