1 22 package org.jboss.net.sockets; 23 24 import java.io.IOException ; 25 import java.io.Serializable ; 26 import java.net.InetAddress ; 27 import java.net.ServerSocket ; 28 import java.net.UnknownHostException ; 29 import java.rmi.server.RMIServerSocketFactory ; 30 31 38 public class TimeoutServerSocketFactory 39 implements RMIServerSocketFactory , Serializable 40 { 41 42 static final long serialVersionUID = 7006964274840965634L; 43 protected transient InetAddress bindAddress; 44 protected int backlog = 200; 45 46 50 public TimeoutServerSocketFactory() 51 { 52 this(null, 200); 53 } 54 55 58 public TimeoutServerSocketFactory(InetAddress bindAddress) 59 { 60 this(bindAddress, 200); 61 } 62 63 66 public TimeoutServerSocketFactory(int backlog) 67 { 68 this(null, backlog); 69 } 70 71 74 public TimeoutServerSocketFactory(InetAddress bindAddress, int backlog) 75 { 76 this.bindAddress = bindAddress; 77 this.backlog = backlog; 78 } 79 80 public String getBindAddress() 81 { 82 String address = null; 83 if (bindAddress != null) 84 address = bindAddress.getHostAddress(); 85 return address; 86 } 87 88 public void setBindAddress(String host) throws UnknownHostException 89 { 90 bindAddress = InetAddress.getByName(host); 91 } 92 public void setBindAddress(InetAddress bindAddress) 93 { 94 this.bindAddress = bindAddress; 95 } 96 97 107 public ServerSocket createServerSocket(int port) throws IOException 108 { 109 ServerSocket activeSocket = new TimeoutServerSocket(port, backlog, bindAddress); 110 return activeSocket; 111 } 112 113 public boolean equals(Object obj) 114 { 115 return obj instanceof TimeoutServerSocketFactory; 116 } 117 118 public int hashCode() 119 { 120 return getClass().getName().hashCode(); 121 } 122 } | Popular Tags |