package com.netflix.ribbon.examples.netty.http;

import java.util.concurrent.CountDownLatch;

import rx.Observer;

import com.google.common.collect.Lists;
import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpResponse;
import com.netflix.client.netty.http.NettyHttpClientBuilder.NettyHttpLoadBalancingClientBuilder;
import com.netflix.client.netty.http.NettyHttpLoadBalancingClient;
import com.netflix.loadbalancer.AbstractLoadBalancer;
import com.netflix.loadbalancer.Server;

public class LoadBalancingExample {
    public static void main(String[] args) throws Exception {
        NettyHttpLoadBalancingClient client = NettyHttpLoadBalancingClientBuilder.newBuilder()
                .withFixedServerList(Lists.newArrayList(new Server("www.google.com:80"), new Server("www.microsoft.com:80"), new Server("www.yahoo.com:80")))
                .build();
        HttpRequest request = HttpRequest.newBuilder().uri("/").build();
        final CountDownLatch latch = new CountDownLatch(3); 
        Observer<HttpResponse> observer = new Observer<HttpResponse>() {

            @Override
            public void onCompleted() {
                latch.countDown();
            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(HttpResponse args) {
                System.out.println("Got response from: " + args.getRequestedURI());                
            }
        };
        for (int i = 0; i < 3; i++) {
            client.observeHttpResponse(request, observer);
        }
        latch.await();        
        System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
    }
}

@@ -293,38 +293,56 @@
 ient
-Builder.NettyHttpLoadBalancing
+;%0Aimport com.netflix.client.netty.http.NettyHttp
 Clie
@@ -625,37 +625,24 @@
    NettyHttp
-LoadBalancing
 Client clien
@@ -650,37 +650,24 @@
  = NettyHttp
-LoadBalancing
 ClientBuilde
@@ -1635,32 +1635,119 @@
 wait();        %0A
+        NettyHttpLoadBalancingClient lbClient = (NettyHttpLoadBalancingClient) client;%0A
         System.o
@@ -1781,17 +1781,19 @@
 lancer) 
-c
+lbC
 lient.ge

Improve load balancing example.