Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. // TRYING TO IMPLEMENT StringBuilder FOR OPTIMIZATION PURPOSES
  2.  
  3. public void geteditsinbatches(final List<String> idforeditslist) {
  4.        if (idforeditslist.size() == 0) {
  5.            return;
  6.        }
  7.         final int maxedits = 100;
  8.         int n = 1;
  9.         String editUrl = "https://maxis-service-prod-pdx.amazon.com/edits?";
  10.         StringBuilder stringBuilder = new StringBuilder(editUrl);
  11.        
  12.         for (String id : idforeditslist) {
  13.             if (n <= maxedits) {
  14.                 if (n > 1) {
  15.                     stringBuilder.append("&");
  16.                 }
  17.                 stringBuilder.append("documentId.")
  18.                 .append(n)
  19.                 .append("=")
  20.                 .append(id);
  21.                 n++;
  22.             }
  23.             if (n == maxedits) {
  24.                 getalleditbatches(editUrl);
  25.                 editUrl = "https://maxis-service-prod-pdx.amazon.com/edits?";
  26.                 n = 1;
  27.             }
  28.         }
  29.         editUrl = stringBuilder.toString();
  30.         getalleditbatches(editUrl);
  31. }
  32.  
  33. // TRYING TO IMPLEMENT MULTITHREADING FOR OPTMIZATION PURPOSES
  34.  
  35. public void sendtoSOTDATAAPIwParams(final String sotdataapimethodname, final List<NameValuePair> params) {
  36.       int threadCounter = Runtime.getRuntime().availableProcessors();
  37.       ExecutorService threadPool = Executors.newFixedThreadPool(threadCounter);
  38.  
  39.       try {
  40.            Runnable r = () -> {
  41.                   InputStream instream = null;
  42.                   try {
  43.                         String pacsurlstr = String.format("%s%s%s", SOTSIGSIMAPI.getsotdataapiURL(), sotdataapimethodname, SOTSIGSIMAPI.getsotdataapiRegion());
  44.                         HttpClient httpclient = HttpClients.createDefault();
  45.                         HttpPost httppost = new HttpPost(pacsurlstr);
  46.                         httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
  47.  
  48.                         //Execute and get the response.
  49.                         HttpResponse response = httpclient.execute(httppost);
  50.                         HttpEntity entity = response.getEntity();
  51.  
  52.                         if (entity != null) {
  53.                             instream = entity.getContent();
  54.                             //System.out.println(instream.toString());
  55.                             String[] parts = response.toString().split(" ");
  56.                             if (!parts[2].equals("OK")) {
  57.                                 mutils.logdata("error", "SOT DATA API Method name: " + sotdataapimethodname);
  58.                                 mutils.logdata("error", response.toString());
  59.                                 for (NameValuePair valuepair : params) {
  60.                                     mutils.logdata("error", "ValuePair: " + valuepair.getName() + "   " + valuepair.getValue());
  61.                                 }
  62.                             }
  63.                             instream.close();
  64.                         }
  65.                     } catch (Exception e) {
  66.                         mutils.logdata("error", "sendtoSOTDATAAPIwParams");
  67.                         mutils.logdata("error", e.toString() + "  " +  Arrays.toString(e.getStackTrace()));
  68.                     }
  69.                 };
  70.                 threadPool.execute(r);
  71.         } catch (Exception e) {
  72.             mutils.logdata("error", "sendtoSOTDATAAPIwParams");
  73.             mutils.logdata("error", e.toString() + "  " +  Arrays.toString(e.getStackTrace()));
  74.         }
  75.         threadPool.shutdown();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement