1 7 package org.jboss.cache; 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 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 private transient int hash_code = -1; 41 44 public GlobalTransaction() 45 { 46 } 47 48 private GlobalTransaction(Address addr) 49 { 50 this.addr = addr; 51 id = newId(); 52 } 53 54 private static synchronized long newId() 55 { 56 return ++sid; 57 } 58 59 public static GlobalTransaction create(Address addr) 60 { 61 return new GlobalTransaction(addr); 62 } 63 64 public Object getAddress() 65 { 66 return addr; 67 } 68 69 public void setAddress(Address address) 70 { 71 addr = address; 72 } 73 74 public long getId() 75 { 76 return id; 77 } 78 79 public int hashCode() 80 { 81 if (hash_code == -1) 82 { 83 hash_code = (addr != null ? addr.hashCode() : 0) + (int) id; 84 } 85 return hash_code; 86 } 87 88 public boolean equals(Object other) 89 { 90 if (this == other) 91 return true; 92 if (!(other instanceof GlobalTransaction)) 93 return false; 94 95 GlobalTransaction otherGtx = (GlobalTransaction) other; 96 97 return ((addr == null && otherGtx.addr == null) || (addr != null && otherGtx.addr != null && addr.compareTo(otherGtx.addr) == 0)) && 98 id == otherGtx.id; 99 } 100 101 public String toString() 102 { 103 StringBuffer sb = new StringBuffer (); 104 sb.append("GlobalTransaction:<").append(addr).append(">:").append(id); 105 return sb.toString(); 106 } 107 108 public void writeExternal(ObjectOutput out) throws IOException 109 { 110 out.writeObject(addr); 111 out.writeLong(id); 112 } 114 115 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 116 { 117 addr = (Address) in.readObject(); 118 id = in.readLong(); 119 hash_code = -1; 120 } 121 122 125 public boolean isRemote() 126 { 127 return remote; 128 } 129 130 133 public void setRemote(boolean remote) 134 { 135 this.remote = remote; 136 } 137 138 139 public void setId(long id) 140 { 141 this.id = id; 142 } 143 } 144 | Popular Tags |