Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TRYING TO IMPLEMENT StringBuilder FOR OPTIMIZATION PURPOSES
- public void geteditsinbatches(final List<String> idforeditslist) {
- if (idforeditslist.size() == 0) {
- return;
- }
- final int maxedits = 100;
- int n = 1;
- String editUrl = "https://maxis-service-prod-pdx.amazon.com/edits?";
- StringBuilder stringBuilder = new StringBuilder(editUrl);
- for (String id : idforeditslist) {
- if (n <= maxedits) {
- if (n > 1) {
- stringBuilder.append("&");
- }
- stringBuilder.append("documentId.")
- .append(n)
- .append("=")
- .append(id);
- n++;
- }
- if (n == maxedits) {
- getalleditbatches(editUrl);
- editUrl = "https://maxis-service-prod-pdx.amazon.com/edits?";
- n = 1;
- }
- }
- editUrl = stringBuilder.toString();
- getalleditbatches(editUrl);
- }
- // TRYING TO IMPLEMENT MULTITHREADING FOR OPTMIZATION PURPOSES
- public void sendtoSOTDATAAPIwParams(final String sotdataapimethodname, final List<NameValuePair> params) {
- int threadCounter = Runtime.getRuntime().availableProcessors();
- ExecutorService threadPool = Executors.newFixedThreadPool(threadCounter);
- try {
- Runnable r = () -> {
- InputStream instream = null;
- try {
- String pacsurlstr = String.format("%s%s%s", SOTSIGSIMAPI.getsotdataapiURL(), sotdataapimethodname, SOTSIGSIMAPI.getsotdataapiRegion());
- HttpClient httpclient = HttpClients.createDefault();
- HttpPost httppost = new HttpPost(pacsurlstr);
- httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
- //Execute and get the response.
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- instream = entity.getContent();
- //System.out.println(instream.toString());
- String[] parts = response.toString().split(" ");
- if (!parts[2].equals("OK")) {
- mutils.logdata("error", "SOT DATA API Method name: " + sotdataapimethodname);
- mutils.logdata("error", response.toString());
- for (NameValuePair valuepair : params) {
- mutils.logdata("error", "ValuePair: " + valuepair.getName() + " " + valuepair.getValue());
- }
- }
- instream.close();
- }
- } catch (Exception e) {
- mutils.logdata("error", "sendtoSOTDATAAPIwParams");
- mutils.logdata("error", e.toString() + " " + Arrays.toString(e.getStackTrace()));
- }
- };
- threadPool.execute(r);
- } catch (Exception e) {
- mutils.logdata("error", "sendtoSOTDATAAPIwParams");
- mutils.logdata("error", e.toString() + " " + Arrays.toString(e.getStackTrace()));
- }
- threadPool.shutdown();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement