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.orb.*; 30 31 public class PortRangeServerSocketFactory 32 extends PortRangeFactory 33 implements ServerSocketFactory 34 { 35 public static final String MIN_PROP = "jacorb.net.server_socket_factory.port.min"; 36 public static final String MAX_PROP = "jacorb.net.server_socket_factory.port.max"; 37 38 private Logger logger; 39 40 public void configure(Configuration configuration) 41 throws ConfigurationException 42 { 43 this.configuration = (org.jacorb.config.Configuration)configuration; 44 logger = this.configuration.getNamedLogger("jacorb.orb.port_rang_fctry"); 45 46 portMin = getPortProperty(MIN_PROP); 48 portMax = getPortProperty(MAX_PROP); 49 50 if (portMin > portMax) 52 { 53 throw new ConfigurationException("PortRangeFactory: minimum port number not less than or equal to maximum"); 54 } 55 } 56 57 public ServerSocket createServerSocket (int port, int backlog) 58 throws IOException 59 { 60 int localPort; 61 ServerSocket socket; 62 63 for (localPort = portMin; localPort <= portMax; localPort++) 64 { 65 try 66 { 67 socket = new ServerSocket (localPort, backlog); 68 if (logger.isDebugEnabled()) 69 logger.debug("PortRangeServerSocketFactory: Created server socket at " 70 + ":" + localPort); 71 return socket; 72 } 73 catch (IOException ex) 74 { 75 } 77 } 78 79 if (logger.isDebugEnabled()) 80 { 81 logger.debug("Cannot create server socket between ports " + 82 portMin + " and " + portMax); 83 } 84 85 throw new BindException ("PortRangeServerSocketFactory: no free port between " 86 + portMin + " and " + portMax); 87 } 88 89 public ServerSocket createServerSocket 90 (int port, int backlog, InetAddress ifAddress) 91 throws IOException 92 { 93 int localPort; 94 ServerSocket socket; 95 96 for (localPort = portMin; localPort <= portMax; localPort++) 97 { 98 try 99 { 100 socket = new ServerSocket(localPort, backlog, ifAddress); 101 if (logger.isDebugEnabled()) 102 { 103 logger.debug("Created server socket at " 104 + ":" + localPort); 105 } 106 return socket; 107 } 108 catch (IOException ex) 109 { 110 } 112 } 113 114 if (logger.isDebugEnabled()) 115 { 116 logger.debug("Cannot create server socket between ports " + 117 portMin + " and " + portMax); 118 } 119 120 throw new BindException ("PortRangeServerSocketFactory: no free port between " 121 + portMin + " and " + portMax); 122 } 123 124 public ServerSocket createServerSocket(int port) 125 throws IOException 126 { 127 int localPort; 128 ServerSocket socket; 129 130 for (localPort = portMin; localPort <= portMax; localPort++) 131 { 132 try 133 { 134 socket = new ServerSocket(localPort); 135 if (logger.isDebugEnabled()) 136 { 137 logger.debug("Created server socket at " 138 + ":" + localPort); 139 } 140 return socket; 141 } 142 catch (IOException ex) 143 { 144 } 146 } 147 148 if (logger.isDebugEnabled()) 149 { 150 logger.debug("Cannot create server socket between ports " + 151 portMin + " and " + portMax); 152 } 153 throw new BindException ("PortRangeServerSocketFactory: no free port between " 154 + portMin + " and " + portMax); 155 } 156 } 157 158 | Popular Tags |