package com.raskasa.metrics.okhttp.sample;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.MetricRegistry;
import com.raskasa.metrics.okhttp.InstrumentedOkHttpClients;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

/** Fetches user information from the GitHub public API */
public final class App {
  public static void main(String[] args) throws Exception {
    MetricRegistry metrics = new MetricRegistry();

    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .build();
    reporter.start(15, TimeUnit.SECONDS);

    OkHttpClient client = InstrumentedOkHttpClients.create(metrics);

    // noinspection InfiniteLoopStatement
    for (;;) {

      Request request = new Request.Builder()
          .url("https://api.github.com/repos/raskasa/metrics-okhttp")
          .build();

      client.newCall(request).enqueue(new Callback() {
        @Override public void onFailure(Call call, IOException e) {
          throw new RuntimeException("call failed");
        }

        @Override public void onResponse(Call call, Response response) throws IOException {
          ResponseBody body = response.body();
          if (body != null) {
            System.out.println(body.string());
          } else {
            throw new RuntimeException("Body not expected to be closed");
          }
        }
      });

      Thread.sleep(15_000);  // 15 seconds
    }
  }
}

@@ -203,106 +203,32 @@
 ava.
-io.IOException;%0Aimport java.util.concurrent.TimeUnit;%0Aimport okhttp3.Call;%0Aimport okhttp3.Callback
+util.concurrent.TimeUnit
 ;%0Aim
@@ -1021,16 +1021,36 @@
 ;%0A%0A     
+ Response response =
  client.
@@ -1071,260 +1071,19 @@
 t).e
-nqueue(new Callback() %7B%0A        @Override public void onFailure(Call call, IOException e) %7B%0A          throw new RuntimeException(%22call failed%22);%0A        %7D%0A%0A        @Override public void onResponse(Call call, Response response) throws IOException %7B%0A    
+xecute();%0A%0A
     
@@ -1127,20 +1127,16 @@
 ;%0A      
-   
- 
 if (body
@@ -1147,20 +1147,16 @@
 null) %7B%0A
-    
         
@@ -1196,20 +1196,16 @@
 ;%0A      
-    
 %7D else %7B
@@ -1213,20 +1213,16 @@
         
- 
-   
 throw ne
@@ -1285,33 +1285,9 @@
     
-    %7D%0A        %7D%0A      %7D);
+%7D
 %0A%0A  

Revert "Update sample to use execute async calls."