/**
 * 
 */
package com.github.phantomthief.failover.impl.checker;

import static org.slf4j.LoggerFactory.getLogger;

import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

import com.google.common.net.HostAndPort;

/**
 * @author w.vela
 */
public class SimplePortChecker {

    private static final int DEFAULT_CONNECTION_TIMEOUT = 5000;

    private static org.slf4j.Logger logger = getLogger(SimplePortChecker.class);

    public static boolean check(String host, int port) {
        return check(null, host, port);
    }

    @Deprecated
    public static boolean check(String friendlyName, String host, int port) {
        return check(friendlyName, host, port, DEFAULT_CONNECTION_TIMEOUT);
    }

    public static boolean check(HostAndPort hostAndPort) {
        return check(null, hostAndPort);
    }

    @Deprecated
    public static boolean check(String friendlyName, HostAndPort hostAndPort) {
        return check(friendlyName, hostAndPort.getHost(), hostAndPort.getPort(),
                DEFAULT_CONNECTION_TIMEOUT);
    }

    public static boolean check(String host, int port, int connectionTimeoutInMs) {
        return check(null, host, port, connectionTimeoutInMs);
    }

    @Deprecated
    public static boolean check(String friendlyName, String host, int port,
            int connectionTimeoutInMs) {
        String logName = friendlyName == null ? "" : "[" + friendlyName + "]";
        try (Socket socket = new Socket()) {
            SocketAddress sockaddr = new InetSocketAddress(host, port);
            socket.connect(sockaddr, connectionTimeoutInMs);
            logger.info("{}[{}:{}] is reachable.", logName, host, port);
            return true;
        } catch (Throwable e) {
            logger.warn("{}[{}:{}] is NOT reachable.", logName, host, port);
            return false;
        }
    }
}

@@ -65,58 +65,8 @@
 r;%0A%0A
-import static org.slf4j.LoggerFactory.getLogger;%0A%0A
 impo
@@ -123,39 +123,8 @@
 ket;
-%0Aimport java.net.SocketAddress;
 %0A%0Aim
@@ -298,1067 +298,346 @@
    p
-rivate static org.slf4j.Logger logger = getLogger(SimplePortChecker.class);%0A%0A    public static boolean check(String host, int port) %7B%0A        return check(null, host, port);%0A    %7D%0A%0A    @Deprecated%0A    public static boolean check(String friendlyName, String host, int port) %7B%0A        return check(friendlyName, host, port, DEFAULT_CONNECTION_TIMEOUT);%0A    %7D%0A%0A    public static boolean check(HostAndPort hostAndPort) %7B%0A        return check(null, hostAndPort);%0A    %7D%0A%0A    @Deprecated%0A    public static boolean check(String friendlyName, HostAndPort hostAndPort) %7B%0A        return check(friendlyName, hostAndPort.getHost(), hostAndPort.getPort(),%0A                DEFAULT_CONNECTION_TIMEOUT);%0A    %7D%0A%0A    public static boolean check(String host, int port, int connectionTimeoutInMs) %7B%0A        return check(null, host, port, connectionTimeoutInMs);%0A    %7D%0A%0A    @Deprecated%0A    public static boolean check(String friendlyName, String host, int port,%0A            int connectionTimeoutInMs) %7B%0A        String logName = friendlyName == null ? %22%22 : %22%5B%22 + friendlyName + %22%5D%22;
+ublic static boolean check(String host, int port) %7B%0A        return check(host, port, DEFAULT_CONNECTION_TIMEOUT);%0A    %7D%0A%0A    public static boolean check(HostAndPort hostAndPort) %7B%0A        return check(hostAndPort.getHost(), hostAndPort.getPort());%0A    %7D%0A%0A    public static boolean check(String host, int port, int connectionTimeoutInMs) %7B
 %0A   
@@ -694,33 +694,23 @@
     
-S
+s
 ocket
-Address sockaddr = 
+.connect(
 new 
@@ -742,45 +742,8 @@
 ort)
-;%0A            socket.connect(sockaddr
 , co
@@ -780,202 +780,52 @@
     
-logger.info(%22%7B%7D%5B%7B%7D:%7B%7D%5D is reachable.%22, logName, host, port);%0A            return true;%0A        %7D catch (Throwable e) %7B%0A            logger.warn(%22%7B%7D%5B%7B%7D:%7B%7D%5D is NOT reachable.%22, logName, host, port);
+return true;%0A        %7D catch (Throwable e) %7B
 %0A   

remove unnecessary log.