X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=restapi-call-node%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fccsdk%2Fsli%2Fplugins%2Frestapicall%2FRetryPolicy.java;h=65684d9379383e91a9b013dc620d29422c166f60;hb=a7430938d2b83b6fe9b03360ff54206fd1259885;hp=3059a4457764283b79da4e09845015e7916c670a;hpb=4515ffa52bc89b1bf40c791749fe518930441d82;p=ccsdk%2Fsli%2Fplugins.git diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java index 3059a445..65684d93 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java @@ -2,8 +2,9 @@ * ============LICENSE_START======================================================= * openECOMP : SDN-C * ================================================================================ - * Copyright (C) 2017 ONAP Intellectual Property. All rights - * reserved. + * 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. @@ -20,40 +21,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]; + } +} \ No newline at end of file