class LocalFirstLoadBalance extends RoundRobinLoadBalance {
    static Logger logger = LoggerFactory.getLogger(LocalFirstLoadBalance.class);

    static String ip = "0.0.0.0";

    static{
    	// get the address of the localhost
        InetAddress inetAddress = Util.getInetAddress();
        // get ip address for this host.
        ip = inetAddress.getHostAddress();
    }

    public LocalFirstLoadBalance() {
        if(logger.isInfoEnabled()) logger.info("A LocalFirstLoadBalance instance is started");
    }

    /**
     * Local first requestKey is not used as it is ip on the localhost. It first needs to
     * find a list of urls on the localhost for the service, and then round robin in the
     * list to pick up one.
     *
     * Currently, this load balance is only used if you deploy the service as standalone
     * java process on data center hosts. We need to find a way to identify two VMs or two
     * docker containers sitting on the same physical machine in the future to improve it.
     *
     * It is also suitable if your services are built on top of light-hybrid-4j and want
     * to use the remote interface for service to service communication.
     *
     * @param urls List
     * @param serviceId String
     * @param tag String
     * @param requestKey String
     * @return URL
     */
    @Override
    public URL select(List<URL> urls, String serviceId, String tag, String requestKey) {
        String key = tag == null ? serviceId : serviceId + "|" + tag;
    	// search for a URL in the same ip first
        List<URL> localUrls = searchLocalUrls(urls, ip);
        if(localUrls.size() > 0) {
             if(localUrls.size() == 1) {
                 return localUrls.get(0);
             } else {
                // round robin within localUrls
                 return doSelect(localUrls, key);
             }
        } else {
            // round robin within urls
            return doSelect(urls, key);
        }
    }

    private List<URL> searchLocalUrls(List<URL> urls, String ip) {
        List<URL> localUrls = new ArrayList<URL>();
        long local = ipToLong(ip);
        for (URL url : urls) {
            long tmp = ipToLong(url.getHost());
            if (local != 0 && local == tmp) {
                localUrls.add(url);
            }
        }
        return localUrls;
    }

    public static long ipToLong(final String address) {<FILL_FUNCTION_BODY>}
}

        final String[] addressBytes = address.split("\\.");
        int length = addressBytes.length;
        if (length < 3) {
            return 0;
        }
        long ip = 0;
        try {
            for (int i = 0; i < 4; i++) {
                ip <<= 8;
                ip |= Integer.parseInt(addressBytes[i]);
            }
        } catch (Exception e) {
            logger.warn("Warn ipToLong address is wrong: address =" + address);
        }
        return ip;
    
<methods>public void <init>() ,public com.networknt.registry.URL select(List<com.networknt.registry.URL>, java.lang.String, java.lang.String, java.lang.String) <variables>static Logger logger,Map<java.lang.String,java.util.concurrent.atomic.AtomicInteger> serviceIdx