示例#1
0
 public static boolean validateProxy(HttpHost p) {
   if (localAddr == null) {
     logger.error("cannot get local IP");
     return false;
   }
   boolean isReachable = false;
   Socket socket = null;
   try {
     socket = new Socket();
     socket.bind(new InetSocketAddress(localAddr, 0));
     InetSocketAddress endpointSocketAddr =
         new InetSocketAddress(p.getAddress().getHostAddress(), p.getPort());
     socket.connect(endpointSocketAddr, 3000);
     logger.debug(
         "SUCCESS - connection established! Local: "
             + localAddr.getHostAddress()
             + " remote: "
             + p);
     isReachable = true;
   } catch (IOException e) {
     logger.warn(
         "FAILRE - CAN not connect! Local: " + localAddr.getHostAddress() + " remote: " + p);
   } finally {
     if (socket != null) {
       try {
         socket.close();
       } catch (IOException e) {
         logger.warn("Error occurred while closing socket of validating proxy", e);
       }
     }
   }
   return isReachable;
 }
示例#2
0
  @Override
  public String toString() {

    String re =
        String.format(
            "host: %15s >> %5dms >> success: %-3.2f%% >> borrow: %d",
            httpHost.getAddress().getHostAddress(),
            responseTime,
            successNum * 100.0 / borrowNum,
            borrowNum);
    return re;
  }