class HostRegistry implements HostValidator<T> {

    public synchronized void update(T key, Collection<String> newHosts) {
        verifyHosts(key, newHosts);
        Collection<String> currentHosts = getHostsForKey(key);
        log.log(Level.FINE, () -> "Setting hosts for key '" + key + "', " +
                "newHosts: " + newHosts + ", " +
                "currentHosts: " + currentHosts);
        Collection<String> removedHosts = getRemovedHosts(newHosts, currentHosts);
        removeHosts(removedHosts);
        addHosts(key, newHosts);
    }

}