1 package org.jacorb.orb.factory; 2 3 22 23 import java.net.*; 24 import java.io.IOException ; 25 26 import org.apache.avalon.framework.logger.Logger; 27 import org.apache.avalon.framework.configuration.*; 28 29 import org.jacorb.util.*; 30 import org.jacorb.orb.*; 31 32 public class PortRangeSocketFactory 33 extends PortRangeFactory 34 implements SocketFactory 35 { 36 public static final String MIN_PROP = "jacorb.net.socket_factory.port.min"; 37 public static final String MAX_PROP = "jacorb.net.socket_factory.port.max"; 38 39 private Logger logger; 40 41 public void configure(Configuration configuration) 42 throws ConfigurationException 43 { 44 this.configuration = (org.jacorb.config.Configuration)configuration; 45 logger = this.configuration.getNamedLogger("jacorb.orb.port_range_fcty"); 46 47 portMin = getPortProperty(MIN_PROP); 49 portMax = getPortProperty(MAX_PROP); 50 51 if (portMin > portMax) 53 { 54 throw new ConfigurationException("PortRangeFactory: minimum port number not less than or equal to maximum"); 55 } 56 } 57 58 public Socket createSocket (String host, int port) 59 throws IOException , UnknownHostException 60 { 61 int localPort; 62 InetAddress localHost = InetAddress.getLocalHost (); 63 Socket socket; 64 65 for (localPort = portMin; localPort <= portMax; localPort++) 66 { 67 try 68 { 69 socket = new Socket (host, port, localHost, localPort); 70 if (logger.isDebugEnabled()) 71 logger.debug("PortRangeSocketFactory: Created server socket at " 72 + ":" + localPort); 73 74 return socket; 75 } 76 catch (IOException ex) 77 { 78 } 80 } 81 82 if (logger.isDebugEnabled()) 83 logger.debug("Cannot bind socket between ports " + portMin + " and " 84 + portMax + " to target " + host + ":" + port); 85 86 throw new BindException ("PortRangeSocketFactory: no free port between " 87 + portMin + " and " + portMax); 88 } 89 90 public boolean isSSL (Socket socket) 91 { 92 return false; 93 } 94 } 95 | Popular Tags |