package com.yasikstudio.devrank.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class ESLauncher {
  private static final String USAGE =
      "Usage: java jar esclient-xxx-with-dependencies.jar [hostname] [filename]";

  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      usageWithExit();
    }
    ESClient es = new ESClient(args[0]);
    BufferedReader r =
        new BufferedReader(new InputStreamReader(new FileInputStream(args[1])));
    updateRanks(es, r);
    r.close();
  }

  private static void updateRanks(ESClient es, BufferedReader r)
      throws Exception {
    String line = null;
    while ((line = r.readLine()) != null) {
      String[] data = line.split(",");
      String uid = data[0];
      double folValue = Double.parseDouble(data[1]);
      double actValue = Double.parseDouble(data[2]);
      double v = folValue + actValue;
      System.out.print(String.format("%s : %.30f => ", uid, v));
      String result = null;
      int retry = 5;
      while (retry > 0) {
        try {
          result = es.update(uid, v);
        } catch (Exception e) {
          if (retry <= 0) {
            throw e;
          }
        }
        retry--;
      }
      System.out.println(result);
    }
  }

  private static void usageWithExit() {
    System.out.println(USAGE);
    System.exit(-1);
  }
}

@@ -1067,9 +1067,10 @@
 y = 
-5
+20
 ;%0A  
@@ -1226,16 +1226,137 @@
 hrow e;%0A
+          %7D else %7B%0A            try %7B%0A              Thread.sleep(1000);%0A            %7D catch (Throwable t) %7B%0A            %7D%0A
         

Increase retry and add sleep to devrank-esclient