1 22 package org.jboss.net.sockets; 23 24 import java.io.IOException ; 25 import java.io.Serializable ; 26 import java.rmi.server.RMIClientSocketFactory ; 27 import java.net.InetAddress ; 28 import java.net.Socket ; 29 import java.net.UnknownHostException ; 30 31 38 public class DefaultClientSocketFactory 39 implements RMIClientSocketFactory , Serializable 40 { 41 private static final long serialVersionUID = -920483051658660269L; 42 43 private InetAddress bindAddress; 44 45 public DefaultClientSocketFactory() 46 { 47 } 48 49 public String getBindAddress() 50 { 51 String address = null; 52 if( bindAddress != null ) 53 address = bindAddress.getHostAddress(); 54 return address; 55 } 56 public void setBindAddress(String host) throws UnknownHostException 57 { 58 bindAddress = InetAddress.getByName(host); 59 } 60 61 70 public Socket createSocket(String host, int port) throws IOException 71 { 72 InetAddress addr = null; 73 if( bindAddress != null ) 74 addr = bindAddress; 75 else 76 addr = InetAddress.getByName(host); 77 Socket s = new Socket (addr, port); 78 return s; 79 } 80 81 public boolean equals(Object obj) 82 { 83 boolean equals = obj instanceof DefaultClientSocketFactory; 84 if( equals && bindAddress != null ) 85 { 86 DefaultClientSocketFactory dcsf = (DefaultClientSocketFactory) obj; 87 InetAddress dcsfa = dcsf.bindAddress; 88 if( dcsfa != null ) 89 equals = bindAddress.equals(dcsfa); 90 else 91 equals = false; 92 } 93 return equals; 94 } 95 public int hashCode() 96 { 97 int hashCode = getClass().getName().hashCode(); 98 if( bindAddress != null ) 99 hashCode += bindAddress.toString().hashCode(); 100 return hashCode; 101 } 102 public String toString() 103 { 104 StringBuffer tmp = new StringBuffer (super.toString()); 105 tmp.append('['); 106 tmp.append("bindAddress="); 107 tmp.append(bindAddress); 108 tmp.append(']'); 109 return tmp.toString(); 110 } 111 } 112 | Popular Tags |