class ConsistentHashLoadBalance implements LoadBalance {
    static Logger logger = LoggerFactory.getLogger(ConsistentHashLoadBalance.class);

    // TODO need to keep a lookup table to map the hash to host:ip, using index in the
    // urls is not reliable as the sequence will be changed after service restart.
    // maybe we need somehow to have an instanceId for each service instance. UUID will
    // do the job. It will be registered as extra parameter like public key and public
    // key certificate of the service.

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


    @Override
    public URL select(List<URL> urls, String serviceId, String tag, String requestKey) {
        URL url = null;
        if (urls.size() > 1) {
            url = doSelect(urls, requestKey);
        } else if (urls.size() == 1) {
            url = urls.get(0);
        }
        return url;
    }

    private URL doSelect(List<URL> urls, String requestKey) {<FILL_FUNCTION_BODY>}

    private int getHash(String hashKey) {
        int hashcode;
        if(hashKey != null) {
            hashcode = hashKey.hashCode();
        } else {
            hashcode = 0;
        }
        return getPositive(hashcode);
    }
}

        int hash = getHash(requestKey);
        // convert hash to an index in urls. This assumes there are the same number
        // This will be changed later on.
        return urls.get(hash % urls.size());
    
<no_super_class>