java.net.BindException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中java.net.BindException.getMessage()方法的一些代码示例,展示了BindException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.getMessage()方法的具体详情如下:
包路径:java.net.BindException
类名称:BindException
方法名:getMessage

BindException.getMessage介绍

暂无

代码示例

代码示例来源:origin: apache/hbase

/**
 * A convenience method to bind to a given address and report
 * better exceptions if the address is not a valid host.
 * @param socket the socket to bind
 * @param address the address to bind to
 * @param backlog the number of connections allowed in the queue
 * @throws BindException if the address can't be bound
 * @throws UnknownHostException if the address isn't a valid host name
 * @throws IOException other random errors from bind
 */
public static void bind(ServerSocket socket, InetSocketAddress address,
            int backlog) throws IOException {
 try {
  socket.bind(address, backlog);
 } catch (BindException e) {
  BindException bindException =
   new BindException("Problem binding to " + address + " : " +
     e.getMessage());
  bindException.initCause(e);
  throw bindException;
 } catch (SocketException e) {
  // If they try to bind to a different host's address, give a better
  // error message.
  if ("Unresolved address".equals(e.getMessage())) {
   throw new UnknownHostException("Invalid hostname for server: " +
                   address.getHostName());
  }
  throw e;
 }
}

代码示例来源:origin: apache/hbase

protected RpcServerInterface createRpcServer(Server server, Configuration conf,
  RpcSchedulerFactory rpcSchedulerFactory, InetSocketAddress bindAddress, String name)
  throws IOException {
 boolean reservoirEnabled = conf.getBoolean(RESERVOIR_ENABLED_KEY, true);
 try {
  return RpcServerFactory.createRpcServer(server, name, getServices(),
    bindAddress, // use final bindAddress for this server.
    conf, rpcSchedulerFactory.create(conf, this, server), reservoirEnabled);
 } catch (BindException be) {
  throw new IOException(be.getMessage() + ". To switch ports use the '"
    + HConstants.REGIONSERVER_PORT + "' configuration property.",
    be.getCause() != null ? be.getCause() : be);
 }
}

代码示例来源:origin: apache/hbase

@Override
protected RpcServerInterface createRpcServer(Server server, Configuration conf,
  RpcSchedulerFactory rpcSchedulerFactory, InetSocketAddress bindAddress, String name)
  throws IOException {
 // RpcServer at HM by default enable ByteBufferPool iff HM having user table region in it
 boolean reservoirEnabled = conf.getBoolean(RESERVOIR_ENABLED_KEY,
   LoadBalancer.isMasterCanHostUserRegions(conf));
 try {
  return RpcServerFactory.createRpcServer(server, name, getServices(),
    bindAddress, // use final bindAddress for this server.
    conf, rpcSchedulerFactory.create(conf, this, server), reservoirEnabled);
 } catch (BindException be) {
  throw new IOException(be.getMessage() + ". To switch ports use the '"
    + HConstants.MASTER_PORT + "' configuration property.",
    be.getCause() != null ? be.getCause() : be);
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void onSetUp() throws Exception {
  runTests = false;
  Assume.group(TestGroup.JMXMP);
  runTests = true;
  super.onSetUp();
  this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer());
  try {
    this.connectorServer.start();
  }
  catch (BindException ex) {
    System.out.println("Skipping remote JMX tests because binding to local port ["
        + SERVICE_PORT + "] failed: " + ex.getMessage());
    runTests = false;
  }
}

代码示例来源:origin: apache/flink

log.debug("Failed to start {} on port {}: {}.", serverName, port, e.getMessage());
try {

代码示例来源:origin: spring-projects/spring-framework

+ port + "] failed: " + ex.getMessage());
return;

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

private static BindException appendMessageToBindException(BindException e,
   String msg) {
  BindException newBe = new BindException(e.getMessage() + " " + msg);
  newBe.initCause(e.getCause());
  newBe.setStackTrace(e.getStackTrace());
  return newBe;
 }
}

代码示例来源:origin: tking/JSTUN

public void run() {
  try {
    FastDiscoveryTest test = new FastDiscoveryTest(iaddress, port, "jstun.javawi.de", 3478);
    //DiscoveryTest test = new DiscoveryTest(iaddress, "stun.sipgate.net", 10000);
    // iphone-stun.freenet.de:3478
    // larry.gloo.net:3478
    // stun.xten.net:3478
    // stun.sipgate.net:10000
    System.out.println(test.test());
  } catch (BindException be) {
    System.out.println(iaddress.toString() + ": " + be.getMessage());
  } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
  }
}

代码示例来源:origin: tking/JSTUN

public void run() {		
  try {
    DiscoveryTest test = new DiscoveryTest(iaddress, port, "jstun.javawi.de", 3478);
    //DiscoveryTest test = new DiscoveryTest(iaddress, "stun.sipgate.net", 10000);
    // iphone-stun.freenet.de:3478
    // larry.gloo.net:3478
    // stun.xten.net:3478
    // stun.sipgate.net:10000
    System.out.println(test.test());
  } catch (BindException be) {
    System.out.println(iaddress.toString() + ": " + be.getMessage());
  } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
  }
}

代码示例来源:origin: de.javawi.jstun/jstun

public void run() {		
  try {
    DiscoveryTest test = new DiscoveryTest(iaddress, port, "jstun.javawi.de", 3478);
    //DiscoveryTest test = new DiscoveryTest(iaddress, "stun.sipgate.net", 10000);
    // iphone-stun.freenet.de:3478
    // larry.gloo.net:3478
    // stun.xten.net:3478
    // stun.sipgate.net:10000
    System.out.println(test.test());
  } catch (BindException be) {
    System.out.println(iaddress.toString() + ": " + be.getMessage());
  } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
  }
}

代码示例来源:origin: de.javawi.jstun/jstun

public void run() {
  try {
    FastDiscoveryTest test = new FastDiscoveryTest(iaddress, port, "jstun.javawi.de", 3478);
    //DiscoveryTest test = new DiscoveryTest(iaddress, "stun.sipgate.net", 10000);
    // iphone-stun.freenet.de:3478
    // larry.gloo.net:3478
    // stun.xten.net:3478
    // stun.sipgate.net:10000
    System.out.println(test.test());
  } catch (BindException be) {
    System.out.println(iaddress.toString() + ": " + be.getMessage());
  } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public RaiseException newErrnoEADDRFromBindException(BindException be, String contextMessage) {
  String msg = be.getMessage();
  if (msg == null) {
    msg = "bind";
  } else {
    msg = "bind - " + msg;
  }
  if (contextMessage != null) {
    msg = msg + contextMessage;
  }
  // This is ugly, but what can we do, Java provides the same BindingException
  // for both EADDRNOTAVAIL and EADDRINUSE, so we differentiate the errors
  // based on BindException's message.
  if(ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    return newErrnoEADDRNOTAVAILError(msg);
  } else {
    return newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public RaiseException newErrnoEADDRFromBindException(BindException be, String contextMessage) {
  String msg = be.getMessage();
  if (msg == null) {
    msg = "bind";
  } else {
    msg = "bind - " + msg;
  }
  if (contextMessage != null) {
    msg = msg + contextMessage;
  }
  // This is ugly, but what can we do, Java provides the same BindingException
  // for both EADDRNOTAVAIL and EADDRINUSE, so we differentiate the errors
  // based on BindException's message.
  if(ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    return newErrnoEADDRNOTAVAILError(msg);
  } else {
    return newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: org.jruby/jruby-core

public RaiseException newErrnoEADDRFromBindException(BindException be, String contextMessage) {
  String msg = be.getMessage();
  if (msg == null) {
    msg = "bind";
  } else {
    msg = "bind - " + msg;
  }
  if (contextMessage != null) {
    msg = msg + contextMessage;
  }
  // This is ugly, but what can we do, Java provides the same BindingException
  // for both EADDRNOTAVAIL and EADDRINUSE, so we differentiate the errors
  // based on BindException's message.
  if(ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    return newErrnoEADDRNOTAVAILError(msg);
  } else {
    return newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public RaiseException newErrnoEADDRFromBindException(BindException be, String contextMessage) {
  String msg = be.getMessage();
  if (msg == null) {
    msg = "bind";
  } else {
    msg = "bind - " + msg;
  }
  if (contextMessage != null) {
    msg = msg + contextMessage;
  }
  // This is ugly, but what can we do, Java provides the same BindingException
  // for both EADDRNOTAVAIL and EADDRINUSE, so we differentiate the errors
  // based on BindException's message.
  if(ADDR_NOT_AVAIL_PATTERN.matcher(msg).find()) {
    return newErrnoEADDRNOTAVAILError(msg);
  } else {
    return newErrnoEADDRINUSEError(msg);
  }
}

代码示例来源:origin: io.leopard/leopard-jetty

protected void checkOpened(int port) throws BindException {
  try {
    Socket s = new Socket();
    s.bind(new InetSocketAddress("0.0.0.0", port));
    s.close();
  }
  catch (java.net.BindException e) {
    String message = e.getMessage();
    if ("权限不够".equals(message) || "Permission denied".equals(message)) {
      throw new BindException("您无权限绑定" + port + "端口");
    }
    e.printStackTrace();
    throw new BindException("端口[" + port + "]已被占用.");
  }
  catch (Exception e) {
    e.printStackTrace();
    throw new BindException("端口[" + port + "]已被占用.");
  }
}

代码示例来源:origin: com.facebook.hadoop/hadoop-core

/**
 * A convenience method to bind to a given address and report
 * better exceptions if the address is not a valid host.
 * @param socket the socket to bind
 * @param address the address to bind to
 * @param backlog the number of connections allowed in the queue
 * @throws BindException if the address can't be bound
 * @throws UnknownHostException if the address isn't a valid host name
 * @throws IOException other random errors from bind
 */
public static void bind(ServerSocket socket, InetSocketAddress address,
            int backlog) throws IOException {
 try {
  socket.bind(address, backlog);
 } catch (BindException e) {
  BindException bindException = new BindException("Problem binding to " + address
                          + " : " + e.getMessage());
  bindException.initCause(e);
  throw bindException;
 } catch (SocketException e) {
  // If they try to bind to a different host's address, give a better
  // error message.
  if ("Unresolved address".equals(e.getMessage())) {
   throw new UnknownHostException("Invalid hostname for server: " +
                   address.getHostName());
  } else {
   throw e;
  }
 }
}

代码示例来源:origin: com.github.groupon.monsoon/monsoon-collector-tcp

ConnectDatum tryConnect(SocketChannel dstSocket) {  // Package visibility for testing purposes.
  final Timer timer = new Timer();
  try {
    dstSocket.connect(dst);
    return new ConnectDatum(ConnectResult.OK, timer.getAsLong(), Optional.empty());
  } catch (SocketTimeoutException | ClosedByInterruptException ex) {
    return new ConnectDatum(ConnectResult.TIMED_OUT, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (NoRouteToHostException ex) {
    return new ConnectDatum(ConnectResult.NO_ROUTE_TO_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (PortUnreachableException ex) {
    return new ConnectDatum(ConnectResult.PORT_UNREACHABLE, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (UnknownHostException ex) {
    return new ConnectDatum(ConnectResult.UNKNOWN_HOST, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (UnknownServiceException ex) {
    return new ConnectDatum(ConnectResult.UNKNOWN_SERVICE, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (ProtocolException ex) {
    return new ConnectDatum(ConnectResult.PROTOCOL_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (BindException ex) {
    return new ConnectDatum(ConnectResult.BIND_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (ConnectException ex) {
    // ConnectException and SocketException seem to cover the same error cases..?
    return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (SocketException ex) {
    // ConnectException and SocketException seem to cover the same error cases..?
    return new ConnectDatum(ConnectResult.CONNECT_FAILED, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  } catch (IOException ex) {
    return new ConnectDatum(ConnectResult.IO_ERROR, timer.getAsLong(), Optional.ofNullable(ex.getMessage()));
  }
}

代码示例来源:origin: us.ihmc/IHMCSimulationToolkit

private void createPacketCommunicator() throws IOException
{
 if (useNetworking.get())
 {
   try
   {
    packetCommunicator = PacketCommunicator.createTCPPacketCommunicatorServer(NetworkPorts.CONTROLLER_PORT, netClassList.get());
    packetCommunicator.connect();
   }
   catch (BindException bindException)
   {
    PrintTools.error(this, bindException.getMessage());
    PrintTools.warn(this, "Continuing without networking");
    useNetworking.set(false);
   }
 }
}

代码示例来源:origin: org.jboss.as/jboss-as-remoting

@Override
public void start(final StartContext context) throws StartException {
  try {
    NetworkServerProvider networkServerProvider = endpointValue.getValue().getConnectionProviderInterface("remote", NetworkServerProvider.class);
    RemotingSecurityProvider rsp = securityProviderValue.getValue();
    ServerAuthenticationProvider sap = rsp.getServerAuthenticationProvider();
    OptionMap.Builder builder = OptionMap.builder();
    builder.addAll(rsp.getOptionMap());
    if (connectorPropertiesOptionMap != null) {
      builder.addAll(connectorPropertiesOptionMap);
    }
    OptionMap resultingMap = builder.getMap();
    if (log.isTraceEnabled()) {
      log.tracef("Resulting OptionMap %s", resultingMap.toString());
    }
    streamServer = networkServerProvider.createServer(getSocketAddress(), resultingMap, sap, rsp.getXnioSsl());
    SocketBindingManager sbm = socketBindingManagerValue.getOptionalValue();
    if (sbm != null) {
      managedBinding = registerSocketBinding(sbm);
    }
    ROOT_LOGGER.listeningOnSocket(NetworkUtils.formatAddress(getSocketAddress()));
  } catch (BindException e) {
    throw MESSAGES.couldNotBindToSocket(e.getMessage() + " " + NetworkUtils.formatAddress(getSocketAddress()), e);
  } catch (Exception e) {
    throw MESSAGES.couldNotStart(e);
  }
}

相关文章