1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Address; 6 import org.jgroups.util.Util; 7 8 import java.io.*; 9 10 11 14 public class WanPipeAddress implements Address { 15 String logical_name=null; 16 17 18 public WanPipeAddress() { 20 } 21 22 23 public WanPipeAddress(String logical_name) { 24 this.logical_name=logical_name; 25 } 26 27 28 public boolean isMulticastAddress() { 29 return true; 30 } 31 32 public int size() { 33 return logical_name != null? logical_name.length()+2 : 22; 34 } 35 36 37 42 public int compareTo(Object other) throws ClassCastException { 43 if(other == null) { 44 System.err.println("WanPipeAddress.compareTo(): other address is null !"); 45 return -1; 46 } 47 48 if(!(other instanceof WanPipeAddress)) { 49 System.err.println("WanPipeAddress.compareTo(): other address is not of type WanPipeAddress !"); 50 return -1; 51 } 52 53 if(((WanPipeAddress)other).logical_name == null) { 54 System.err.println("WanPipeAddress.compareTo(): other address is null !"); 55 return -1; 56 } 57 58 return logical_name.compareTo(((WanPipeAddress)other).logical_name); 59 } 60 61 62 public boolean equals(Object obj) { 63 return compareTo(obj) == 0 ? true : false; 64 } 65 66 67 public int hashCode() { 68 return logical_name.hashCode(); 69 } 70 71 72 public String toString() { 73 return logical_name; 74 } 75 76 77 public void writeExternal(ObjectOutput out) throws IOException { 78 out.writeObject(logical_name); 79 } 80 81 82 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 83 logical_name=(String )in.readObject(); 84 } 85 86 87 88 public static void main(String args[]) { 89 90 WanPipeAddress a=new WanPipeAddress("daddy"); 91 System.out.println(a); 92 93 WanPipeAddress b=new WanPipeAddress("daddy.nms.fnc.fujitsu.com"); 94 System.out.println(b); 95 96 97 if(a.equals(b)) 98 System.out.println("equals"); 99 else 100 System.out.println("does not equal"); 101 } 102 103 104 public void writeTo(DataOutputStream outstream) throws IOException { 105 Util.writeString(logical_name, outstream); 106 } 107 108 public void readFrom(DataInputStream instream) throws IOException, IllegalAccessException , InstantiationException { 109 logical_name=Util.readString(instream); 110 } 111 } 112 | Popular Tags |