Java Code Examples for org.apache.servicecomb.foundation.common.net.NetUtils#canTcpListen()

The following examples show how to use org.apache.servicecomb.foundation.common.net.NetUtils#canTcpListen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static boolean canPublishEndpoint(String listenAddress) {
  if (StringUtils.isEmpty(listenAddress)) {
    LOGGER.info("listenAddress is null, can not publish.");
    return false;
  }

  IpPort ipPort = NetUtils.parseIpPortFromURI("http://" + listenAddress);
  if (ipPort == null) {
    LOGGER.info("invalid listenAddress {}, can not publish, format should be ip:port.", listenAddress);
    return false;
  }

  if (NetUtils.canTcpListen(ipPort.getSocketAddress().getAddress(), ipPort.getPort())) {
    LOGGER.info("{} is not listened, can not publish.", ipPort.getSocketAddress());
    return false;
  }

  return true;
}
 
Example 2
Source File: VertxRestTransport.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canInit() {
  setListenAddressWithoutSchema(TransportConfig.getAddress());

  URIEndpointObject ep = (URIEndpointObject) getEndpoint().getAddress();
  if (ep == null) {
    return true;
  }

  if (!NetUtils.canTcpListen(ep.getSocketAddress().getAddress(), ep.getPort())) {
    LOGGER.warn(
        "Can not start VertxRestTransport, the port:{} may have been occupied. You can ignore this message if you are using a web container like tomcat.",
        ep.getPort());
    return false;
  }

  return true;
}