1 package org.sapia.ubik.net; 2 3 import java.io.IOException ; 4 import java.io.ObjectInput ; 5 import java.io.ObjectOutput ; 6 7 8 18 public class TCPAddress implements java.io.Externalizable , ServerAddress { 19 static final long serialVersionUID = 1L; 20 public static final String TRANSPORT_TYPE = "tcp/socket"; 21 private String _host; 22 private int _port; 23 private int _hashCode; 24 protected String _transportType = TRANSPORT_TYPE; 25 26 27 public TCPAddress() { 28 } 29 30 38 public TCPAddress(String host, int port) { 39 _host = host; 40 _port = port; 41 _hashCode = (host + port).hashCode(); 42 } 43 44 50 public boolean equals(Object obj) { 51 TCPAddress other; 52 53 try { 54 other = (TCPAddress) obj; 55 56 return (other._port == _port) && other._host.equals(_host); 57 } catch (ClassCastException e) { 58 return false; 59 } 60 } 61 62 67 public String getHost() { 68 return _host; 69 } 70 71 76 public int getPort() { 77 return _port; 78 } 79 80 85 public int hashCode() { 86 return _hashCode; 87 } 88 89 92 public void readExternal(ObjectInput in) 93 throws IOException , ClassNotFoundException { 94 _host = in.readUTF(); 95 _port = in.readInt(); 96 _hashCode = in.readInt(); 97 _transportType = in.readUTF(); 98 } 99 100 103 public void writeExternal(ObjectOutput out) throws IOException { 104 out.writeUTF(_host); 105 out.writeInt(_port); 106 out.writeInt(_hashCode); 107 out.writeUTF(_transportType); 108 } 109 110 113 public String getTransportType() { 114 return _transportType; 115 } 116 117 122 public String toString() { 123 return "[ host=" + _host + ", port=" + _port + ", type=" + _transportType + 124 " ]"; 125 } 126 } 127 | Popular Tags |