package org.jboss.cache;
import org.jgroups.Address;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
public class GlobalTransaction implements Externalizable {
static final long serialVersionUID = 8011434781266976149L;
Address addr=null;
long id=-1;
private static long sid=0;
public GlobalTransaction() {
; }
private GlobalTransaction(Address addr) {
this.addr=addr;
id=newId();
}
private static synchronized long newId() {
return ++sid;
}
public static synchronized GlobalTransaction create(Address addr) {
return new GlobalTransaction(addr);
}
public Object getAddress() {
return addr;
}
public long getId() {
return id;
}
public int hashCode() {
return (addr != null ? addr.hashCode() : 0) + (int)id;
}
public boolean equals(Object other) {
if(other == null || !(other instanceof GlobalTransaction))
return false;
return compareTo(other) == 0;
}
public int compareTo(Object o) {
GlobalTransaction other;
int comp;
if(o == null || !(o instanceof GlobalTransaction))
throw new ClassCastException("GlobalTransaction.compareTo(): other object is " + o);
other=(GlobalTransaction)o;
comp=addr != null ? addr.compareTo(other.addr) : 0;
if(comp != 0) return comp;
if(id < other.getId()) return -1;
if(id > other.getId()) return 1;
return 0;
}
public String toString() {
StringBuffer sb=new StringBuffer();
sb.append('<').append(addr).append(">:").append(id);
return sb.toString();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(addr);
out.writeLong(id);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
addr=(Address)in.readObject();
id=in.readLong();
}
}