use of java.net.BindException in project orientdb by orientechnologies.
the class OProxyServerListener method run.
public void run() {
// WAIT THE REMOTE SOCKET IS AVAILABLE FIRST. IN THIS WAY THE LOCAL SOCKET IS CREATED ONLY AFTER THE REMOTE SOCKET IS
// AVAILABLE. THIS ALLOWS TO RETURN A CONNECTION REFUSED TO THE CLIENT
OLogManager.instance().info(this, "Proxy server: local port %d is waiting for the remote port %s:%d to be available...", localPort, server.getRemoteHost(), remotePort);
if (server.isWaitUntilRemotePortsAreOpen()) {
while (running) {
try {
final Socket remoteSocket = connectTargetServer();
remoteSocket.close();
break;
} catch (Exception e) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
return;
}
}
}
}
OLogManager.instance().info(this, "Proxy server: remote port %s:%d is available, creating the channel...", server.getRemoteHost(), remotePort);
try {
localSocket = new ServerSocket(localPort);
} catch (Exception e) {
OLogManager.instance().error(this, "Proxy server: error on creating local socket for proxy channel %d->%s:%d", e, localPort, server.getRemoteHost(), remotePort);
}
while (running && !localSocket.isClosed()) try {
final Socket sourceSocket = localSocket.accept();
final OProxyChannel channel = new OProxyChannel(this, sourceSocket, localPort, remotePort);
channels.add(channel);
channel.start();
} catch (BindException e) {
OLogManager.instance().error(this, "Proxy server: error on listening port %d->%s:%d", e, localPort, server.getRemoteHost(), remotePort);
break;
} catch (SocketException e) {
OLogManager.instance().debug(this, "Proxy server: listening port %d is closed", e, localPort);
break;
} catch (Exception e) {
OLogManager.instance().error(this, "Proxy server: closing proxy server %d->%s:%d", e, localPort, server.getRemoteHost(), remotePort);
break;
}
shutdown();
}
use of java.net.BindException in project OpenRefine by OpenRefine.
the class ShutdownSignalHandler method init.
public void init(String host, int port) throws Exception {
logger.info("Starting Server bound to '" + host + ":" + port + "'");
String memory = Configurations.get("refine.memory");
if (memory != null) {
logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
}
int maxThreads = Configurations.getInteger("refine.queue.size", 30);
int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);
LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);
threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);
this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));
Connector connector = new SocketConnector();
connector.setPort(port);
connector.setHost(host);
connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
connector.setStatsOn(false);
this.addConnector(connector);
File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));
if (!isWebapp(webapp)) {
webapp = new File("main/webapp");
if (!isWebapp(webapp)) {
webapp = new File("webapp");
if (!isWebapp(webapp)) {
logger.warn("Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
System.exit(-1);
}
}
}
final String contextPath = Configurations.get("refine.context_path", "/");
final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);
logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
context.setMaxFormContentSize(maxFormContentSize);
this.setHandler(context);
this.setStopAtShutdown(true);
this.setSendServerVersion(true);
// Enable context autoreloading
if (Configurations.getBoolean("refine.autoreload", false)) {
scanForUpdates(webapp, context);
}
// start the server
try {
this.start();
} catch (BindException e) {
logger.error("Failed to start server - is there another copy running already on this port/address?");
throw e;
}
configure(context);
}
use of java.net.BindException in project flink by apache.
the class KafkaTestEnvironmentImpl method getKafkaServer.
/**
* Copied from com.github.sakserv.minicluster.KafkaLocalBrokerIntegrationTest (ASL licensed)
*/
protected KafkaServer getKafkaServer(int brokerId, File tmpFolder) throws Exception {
Properties kafkaProperties = new Properties();
// properties have to be Strings
kafkaProperties.put("advertised.host.name", KAFKA_HOST);
kafkaProperties.put("broker.id", Integer.toString(brokerId));
kafkaProperties.put("log.dir", tmpFolder.toString());
kafkaProperties.put("zookeeper.connect", zookeeperConnectionString);
kafkaProperties.put("message.max.bytes", String.valueOf(50 * 1024 * 1024));
kafkaProperties.put("replica.fetch.max.bytes", String.valueOf(50 * 1024 * 1024));
// for CI stability, increase zookeeper session timeout
kafkaProperties.put("zookeeper.session.timeout.ms", zkTimeout);
kafkaProperties.put("zookeeper.connection.timeout.ms", zkTimeout);
if (additionalServerProperties != null) {
kafkaProperties.putAll(additionalServerProperties);
}
final int numTries = 5;
for (int i = 1; i <= numTries; i++) {
int kafkaPort = NetUtils.getAvailablePort();
kafkaProperties.put("port", Integer.toString(kafkaPort));
//to support secure kafka cluster
if (secureMode) {
LOG.info("Adding Kafka secure configurations");
kafkaProperties.put("listeners", "SASL_PLAINTEXT://" + KAFKA_HOST + ":" + kafkaPort);
kafkaProperties.put("advertised.listeners", "SASL_PLAINTEXT://" + KAFKA_HOST + ":" + kafkaPort);
kafkaProperties.putAll(getSecureProperties());
}
KafkaConfig kafkaConfig = new KafkaConfig(kafkaProperties);
try {
scala.Option<String> stringNone = scala.Option.apply(null);
KafkaServer server = new KafkaServer(kafkaConfig, SystemTime$.MODULE$, stringNone);
server.startup();
return server;
} catch (KafkaException e) {
if (e.getCause() instanceof BindException) {
// port conflict, retry...
LOG.info("Port conflict when starting Kafka Broker. Retrying...");
} else {
throw e;
}
}
}
throw new Exception("Could not start Kafka after " + numTries + " retries due to port conflicts.");
}
use of java.net.BindException in project Openfire by igniterealtime.
the class RelayChannel method createLocalRelayChannel.
public static RelayChannel createLocalRelayChannel(final String host, final int minPort, final int maxPort) throws IOException {
int range = maxPort - minPort;
IOException be = null;
for (int t = 0; t < 50; t++) {
try {
int a = Math.round((int) (Math.random() * range)) + minPort;
a = a % 2 == 0 ? a : a + 1;
return new RelayChannel(host, a);
} catch (BindException e) {
be = e;
} catch (IOException e) {
be = e;
}
}
throw be;
}
use of java.net.BindException in project jdk8u_jdk by JetBrains.
the class RmiBootstrapTest method testConfigurationFile.
/**
* Test a configuration file. Determines whether the bootstrap
* should succeed or fail depending on the file name:
* *ok.properties: bootstrap should succeed.
* *ko.properties: bootstrap or connection should fail.
* @return null if the test succeeds, an error message otherwise.
**/
private String testConfigurationFile(String fileName) {
File file = new File(fileName);
final String portStr = System.getProperty("rmi.port", null);
final int port = portStr != null ? Integer.parseInt(portStr) : basePort;
if (fileName.endsWith("ok.properties")) {
String errStr = null;
for (int i = 0; i < PORT_TEST_LEN; i++) {
try {
errStr = testConfiguration(file, port + testPort++);
return errStr;
} catch (BindException e) {
// port conflict; try another port
}
}
return "Can not locate available port";
}
if (fileName.endsWith("ko.properties")) {
return testConfigurationKo(file, port + testPort++);
}
return fileName + ": test file suffix must be one of [ko|ok].properties";
}
Aggregations