@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE")
    @Override
    public Server choose(ILoadBalancer lb, Object key) {
        if (lb == null) {
            return null;
        }
        Server server = null;

        while (server == null) {
            // get hold of the current reference in case it is changed from the other thread
            List<Double> currentWeights = accumulatedWeights;
            if (Thread.interrupted()) {
                return null;
            }
            List<Server> allList = lb.getAllServers();

            int serverCount = allList.size();

            if (serverCount == 0) {
                return null;
            }

            int serverIndex = 0;

            // last one in the list is the sum of all weights
            double maxTotalWeight = currentWeights.size() == 0 ? 0 : currentWeights.get(currentWeights.size() - 1); 
            // No server has been hit yet and total weight is not initialized
            // fallback to use round robin
            if (maxTotalWeight < 0.001d || serverCount != currentWeights.size()) {
                server =  super.choose(getLoadBalancer(), key);
                if(server == null) {
                    return server;
                }
            } else {
                // generate a random weight between 0 (inclusive) to maxTotalWeight (exclusive)
                double randomWeight = random.nextDouble() * maxTotalWeight;
                // pick the server index based on the randomIndex
                int n = 0;
                for (Double d : currentWeights) {
                    if (d >= randomWeight) {
                        serverIndex = n;
                        break;
                    } else {
                        n++;
                    }
                }

                server = allList.get(serverIndex);
            }

            if (server == null) {
                /* Transient. */
                Thread.yield();
                continue;
            }

            if (server.isAlive()) {
                return (server);
            }

            // Next.
            server = null;
        }
        return server;
    }
Rule that use the average/percentile response times
to assign dynamic "weights" per Server which is then used in 
the "Weighted Round Robin" fashion. 
<p>
The basic idea for weighted round robin has been obtained from JCS
The implementation for choosing the endpoint from the list of endpoints
is as follows:Let's assume 4 endpoints:A(wt=10), B(wt=30), C(wt=40), 
D(wt=20). 
<p>
Using the Random API, generate a random number between 1 and10+30+40+20.
Let's assume that the above list is randomized. Based on the weights, we
have intervals as follows:
<p>
1-----10 (A's weight)
<br>
11----40 (A's weight + B's weight)
<br>
41----80 (A's weight + B's weight + C's weight)
<br>
81----100(A's weight + B's weight + C's weight + C's weight)
<p>
Here's the psuedo code for deciding where to send the request:
<p>
if (random_number between 1 &amp; 10) {send request to A;}
<br>
else if (random_number between 11 &amp; 40) {send request to B;}
<br>
else if (random_number between 41 &amp; 80) {send request to C;}
<br>
else if (random_number between 81 &amp; 100) {send request to D;}
<p>
When there is not enough statistics gathered for the servers, this rule
will fall back to use {@link RoundRobinRule}. 
@author stonse
ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/WeightedResponseTimeRule.java