Release version 1.1.0 of sli/plugins
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / main / java / org / onap / ccsdk / sli / plugins / restapicall / RetryPolicy.java
index 5cee077..8d5143b 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *                     reserved.
+ *     Modifications Copyright © 2018 IBM
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,38 +24,41 @@ package org.onap.ccsdk.sli.plugins.restapicall;
 
 public class RetryPolicy {
     private String[] hostnames;
-    private Integer maximumRetries;  
+    private Integer maximumRetries;
+    private int position;
+    private int retryCount;
+
+    public RetryPolicy(String[] hostnames, Integer maximumRetries) {
+    this.hostnames = hostnames;
+    this.maximumRetries = maximumRetries;
+    this.position = 0;
+    this.retryCount = 0;
+
+    }
 
     public Integer getMaximumRetries() {
-        return maximumRetries;
+    return maximumRetries;
     }
-    
-    public String getNextHostName(String uri) throws RetryException {
-        Integer position = null;
-
-        for (int i = 0; i < hostnames.length; i++) {
-            if (uri.contains(hostnames[i])) {
-                position = i;
-                break;
-            }
-        }
-
-        if(position == null){
-            throw new RetryException("No match found for the provided uri[" + uri + "] " +
-                    "so the next host name could not be retreived");
-        }
-        position++;
-
-        if (position > hostnames.length - 1) {
-            position = 0;
-        }
-        return hostnames[position];
+
+    public int getRetryCount() {
+    return retryCount;
     }
 
-    public RetryPolicy(String[] hostnames, Integer maximumRetries){
-        this.hostnames = hostnames;
-        this.maximumRetries = maximumRetries;
+    public Boolean shouldRetry() {
+    return retryCount < maximumRetries + 1;
+    }
+
+    public String getRetryMessage() {
+    return retryCount + " retry attempts were made out of " + maximumRetries + " maximum retry attempts.";
     }
     
+    public String getNextHostName() throws RetryException {
+    retryCount++;
+    position++;
+    if (position > hostnames.length - 1) {
+        position = 0;
+    }
+    return hostnames[position];
+    }
 
 }