/** * Find a port that is available. This method starts a {@link ServerSocket} and obtains the port on which the socket is * listening, and then shuts down the socket so the port becomes available. * * @return the number of the now-available port */ public static int getAvailablePort() { return IoUtil.getAvailablePort(); }
if (factory != null) throw new IllegalStateException("" + this + " is already running"); if (this.port == -1) this.port = IoUtil.getAvailablePort(); this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024); if ( this.dataDir == null ) {
port = desiredPort > 0 ? desiredPort : IoUtil.getAvailablePort(); config.setProperty(KafkaConfig.PortProp(), Integer.toString(port));