1 3 package org.jgroups.protocols.pbcast; 4 5 import org.jgroups.Address; 6 7 import java.io.Serializable ; 8 import java.util.Vector ; 9 10 11 public class Gossip implements Serializable { 12 Address sender=null; 13 long id=-1; 14 Digest digest=null; 15 Vector not_seen=null; Vector seen=new Vector (11); 18 19 public Gossip(Address obj, long id) { 20 sender=obj; 21 this.id=id; 22 } 23 24 public Gossip(Address obj, long id, Digest d, Vector not_seen) { 25 sender=obj; 26 this.id=id; 27 digest=d; 28 this.not_seen=not_seen; 29 } 30 31 32 35 public void removeFromNotSeenList(Address mbr) { 36 if(not_seen != null && mbr != null) 37 not_seen.removeElement(mbr); 38 } 39 40 public void addToSeenList(Address mbr) { 41 if(mbr != null && !seen.contains(mbr)) 42 seen.addElement(mbr); 43 } 44 45 46 public int sizeOfNotSeenList() { 47 return not_seen == null ? 0 : not_seen.size(); 48 } 49 50 51 public Vector getNotSeenList() { 52 return not_seen; 53 } 54 55 public Vector getSeenList() { 56 return seen; 57 } 58 59 60 public boolean equals(Object o) { 61 Gossip other=null; 62 63 if(sender != null && o != null) { 64 other=(Gossip)o; 65 return sender.equals(other.sender) && id == other.id; 66 } 67 return false; 68 } 69 70 71 public int hashCode() { 72 if(sender != null) 73 return sender.hashCode() + (int)id; 74 else 75 return (int)id; 76 } 77 78 79 public Gossip copy() { 80 Gossip ret=new Gossip(sender, id); 81 if(digest != null) 82 ret.digest=digest.copy(); 83 if(not_seen != null) 84 ret.not_seen=(Vector )not_seen.clone(); 85 if(seen != null) 86 ret.seen=(Vector )seen.clone(); 87 return ret; 88 } 89 90 91 public String toString() { 92 StringBuffer sb=new StringBuffer (); 93 sb.append("sender="); 94 if(sender != null) 95 sb.append(sender); 96 else 97 sb.append("<null>"); 98 if(digest != null) sb.append(", digest=" + digest); 99 if(not_seen != null) sb.append(", not_seen=" + not_seen); 100 if(seen != null) sb.append(", seen=" + seen); 101 sb.append(", id=" + id); 102 return sb.toString(); 103 } 104 105 106 public String shortForm() { 107 StringBuffer sb=new StringBuffer (); 108 if(sender != null) 109 sb.append(sender); 110 else 111 sb.append("<null>"); 112 sb.append("#" + id); 113 return sb.toString(); 114 } 115 116 117 public static void main(String [] args) { 118 Gossip id1, id2; 119 120 id1=new Gossip(new org.jgroups.stack.IpAddress("daddy", 4567), 23); 121 id2=new Gossip(new org.jgroups.stack.IpAddress("133.164.130.19", 4567), 23); 122 123 System.out.println(id1.equals(id2)); 124 } 125 } 126 | Popular Tags |