java.net.BindException#initCause ( )源码实例Demo

下面列出了java.net.BindException#initCause ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop-ozone   文件: HttpServer2.java
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener
 * @param ex
 * @return
 */
private static BindException constructBindException(ServerConnector listener,
    IOException ex) {
  BindException be = new BindException("Port in use: "
      + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}
 
源代码2 项目: hadoop   文件: HttpServer.java
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListener() throws Exception {
  if (listener.getLocalPort() != -1) { // it's already bound
    return;
  }
  if (listenerStartedExternally) { // Expect that listener was started securely
    throw new Exception("Expected webserver's listener to be started " +
        "previously but wasn't");
  }
  int port = listener.getPort();
  while (true) {
    // jetty has a bug where you can't reopen a listener that previously
    // failed to open w/o issuing a close first, even if the port is changed
    try {
      listener.close();
      listener.open();
      break;
    } catch (BindException ex) {
      if (port == 0 || !findPort) {
        BindException be = new BindException(
            "Port in use: " + listener.getHost() + ":" + listener.getPort());
        be.initCause(ex);
        throw be;
      }
    }
    // try the next port number
    listener.setPort(++port);
    Thread.sleep(100);
  }
}
 
源代码3 项目: hadoop   文件: HttpServer2.java
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListeners() throws Exception {
  for (Connector listener : listeners) {
    if (listener.getLocalPort() != -1) {
      // This listener is either started externally or has been bound
      continue;
    }
    int port = listener.getPort();
    while (true) {
      // jetty has a bug where you can't reopen a listener that previously
      // failed to open w/o issuing a close first, even if the port is changed
      try {
        listener.close();
        listener.open();
        LOG.info("Jetty bound to port " + listener.getLocalPort());
        break;
      } catch (BindException ex) {
        if (port == 0 || !findPort) {
          BindException be = new BindException("Port in use: "
              + listener.getHost() + ":" + listener.getPort());
          be.initCause(ex);
          throw be;
        }
      }
      // try the next port number
      listener.setPort(++port);
      Thread.sleep(100);
    }
  }
}
 
源代码4 项目: big-c   文件: HttpServer.java
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListener() throws Exception {
  if (listener.getLocalPort() != -1) { // it's already bound
    return;
  }
  if (listenerStartedExternally) { // Expect that listener was started securely
    throw new Exception("Expected webserver's listener to be started " +
        "previously but wasn't");
  }
  int port = listener.getPort();
  while (true) {
    // jetty has a bug where you can't reopen a listener that previously
    // failed to open w/o issuing a close first, even if the port is changed
    try {
      listener.close();
      listener.open();
      break;
    } catch (BindException ex) {
      if (port == 0 || !findPort) {
        BindException be = new BindException(
            "Port in use: " + listener.getHost() + ":" + listener.getPort());
        be.initCause(ex);
        throw be;
      }
    }
    // try the next port number
    listener.setPort(++port);
    Thread.sleep(100);
  }
}
 
源代码5 项目: big-c   文件: HttpServer2.java
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListeners() throws Exception {
  for (Connector listener : listeners) {
    if (listener.getLocalPort() != -1) {
      // This listener is either started externally or has been bound
      continue;
    }
    int port = listener.getPort();
    while (true) {
      // jetty has a bug where you can't reopen a listener that previously
      // failed to open w/o issuing a close first, even if the port is changed
      try {
        listener.close();
        listener.open();
        LOG.info("Jetty bound to port " + listener.getLocalPort());
        break;
      } catch (BindException ex) {
        if (port == 0 || !findPort) {
          BindException be = new BindException("Port in use: "
              + listener.getHost() + ":" + listener.getPort());
          be.initCause(ex);
          throw be;
        }
      }
      // try the next port number
      listener.setPort(++port);
      Thread.sleep(100);
    }
  }
}
 
源代码6 项目: lucene-solr   文件: HttpServer2.java
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener listener to check
 * @param ex exception to check
 * @return returns the exception
 */
private static BindException constructBindException(ServerConnector listener,
                                                    BindException ex) {
  BindException be = new BindException("Port in use: "
      + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}
 
源代码7 项目: hbase   文件: HttpServer.java
/**
 * Open the main listener for the server
 * @throws Exception if the listener cannot be opened or the appropriate port is already in use
 */
@VisibleForTesting
void openListeners() throws Exception {
  for (ListenerInfo li : listeners) {
    ServerConnector listener = li.listener;
    if (!li.isManaged || (li.listener.getLocalPort() != -1 && li.listener.getLocalPort() != -2)) {
      // This listener is either started externally, or has not been opened, or has been closed
      continue;
    }
    int port = listener.getPort();
    while (true) {
      // jetty has a bug where you can't reopen a listener that previously
      // failed to open w/o issuing a close first, even if the port is changed
      try {
        listener.close();
        listener.open();
        LOG.info("Jetty bound to port " + listener.getLocalPort());
        break;
      } catch (IOException ex) {
        if(!(ex instanceof BindException) && !(ex.getCause() instanceof BindException)) {
          throw ex;
        }
        if (port == 0 || !findPort) {
          BindException be = new BindException("Port in use: "
              + listener.getHost() + ":" + listener.getPort());
          be.initCause(ex);
          throw be;
        }
      }
      // try the next port number
      listener.setPort(++port);
      Thread.sleep(100);
    }
  }
}
 
源代码8 项目: knox   文件: HttpServer2.java
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener listener to check
 * @param ex exception to check
 * @return returns the exception
 */
private static BindException constructBindException(ServerConnector listener,
                                                    BindException ex) {
  BindException be = new BindException("Port in use: "
                                           + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}
 
源代码9 项目: knox   文件: HttpServer2.java
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener listener to check
 * @param ex exception to check
 * @return returns the exception
 */
private static BindException constructBindException(ServerConnector listener,
                                                    BindException ex) {
  BindException be = new BindException("Port in use: "
                                           + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}
 
源代码10 项目: Tomcat7.0.67   文件: JIoEndpoint.java
@Override
public void bind() throws Exception {

    // Initialize thread count defaults for acceptor
    if (acceptorThreadCount == 0) {
        acceptorThreadCount = 1;
    }
    // Initialize maxConnections
    if (getMaxConnections() == 0) {
        // User hasn't set a value - use the default
        setMaxConnections(getMaxThreadsExecutor(true));
    }

    if (serverSocketFactory == null) {
        if (isSSLEnabled()) {
            serverSocketFactory =
                handler.getSslImplementation().getServerSocketFactory(this);
        } else {
            serverSocketFactory = new DefaultServerSocketFactory(this);
        }
    }

    if (serverSocket == null) {
        try {
            if (getAddress() == null) {
                serverSocket = serverSocketFactory.createSocket(getPort(),
                        getBacklog());
            } else {
                serverSocket = serverSocketFactory.createSocket(getPort(),
                        getBacklog(), getAddress());
            }
        } catch (BindException orig) {
            String msg;
            if (getAddress() == null)
                msg = orig.getMessage() + " <null>:" + getPort();
            else
                msg = orig.getMessage() + " " +
                        getAddress().toString() + ":" + getPort();
            BindException be = new BindException(msg);
            be.initCause(orig);
            throw be;
        }
    }

}
 
源代码11 项目: tomcatsrc   文件: JIoEndpoint.java
@Override
public void bind() throws Exception {

    // Initialize thread count defaults for acceptor
    if (acceptorThreadCount == 0) {
        acceptorThreadCount = 1;
    }
    // Initialize maxConnections
    if (getMaxConnections() == 0) {
        // User hasn't set a value - use the default
        setMaxConnections(getMaxThreadsInternal());
    }

    if (serverSocketFactory == null) {
        if (isSSLEnabled()) {
            serverSocketFactory =
                handler.getSslImplementation().getServerSocketFactory(this);
        } else {
            serverSocketFactory = new DefaultServerSocketFactory(this);
        }
    }

    if (serverSocket == null) {
        try {
            if (getAddress() == null) {
                serverSocket = serverSocketFactory.createSocket(getPort(),
                        getBacklog());
            } else {
                serverSocket = serverSocketFactory.createSocket(getPort(),
                        getBacklog(), getAddress());
            }
        } catch (BindException orig) {
            String msg;
            if (getAddress() == null)
                msg = orig.getMessage() + " <null>:" + getPort();
            else
                msg = orig.getMessage() + " " +
                        getAddress().toString() + ":" + getPort();
            BindException be = new BindException(msg);
            be.initCause(orig);
            throw be;
        }
    }

}