Code Review
/
holmes
/
common.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Optimized retry in the exception branch
[holmes/common.git]
/
holmes-actions
/
src
/
main
/
java
/
org
/
onap
/
holmes
/
common
/
utils
/
MsbRegister.java
diff --git
a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
index
b8f6b86
..
33b53c7
100644
(file)
--- a/
holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
+++ b/
holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
@@
-60,9
+60,9
@@
public class MsbRegister {
MicroServiceFullInfo microServiceFullInfo = null;
int retry = 0;
while (null == microServiceFullInfo && retry < totalRetryTimes) {
MicroServiceFullInfo microServiceFullInfo = null;
int retry = 0;
while (null == microServiceFullInfo && retry < totalRetryTimes) {
+ int time = interval * ++retry;
try {
try {
- log.info("Holmes Service Registration. Times: " + ++retry);
- int time = interval * retry;
+ log.info("Holmes Service Registration. Times: " + retry);
microServiceFullInfo = client
.header("Accept", MediaType.APPLICATION_JSON)
.queryParam("createOrUpdate", true)
microServiceFullInfo = client
.header("Accept", MediaType.APPLICATION_JSON)
.queryParam("createOrUpdate", true)
@@
-72,14
+72,14
@@
public class MsbRegister {
MicroServiceFullInfo.class);
if (null == microServiceFullInfo) {
MicroServiceFullInfo.class);
if (null == microServiceFullInfo) {
- log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", time));
- threadSleep(TimeUnit.SECONDS.toSeconds(time));
+ retry(time);
} else {
log.info("Registration succeeded!");
break;
}
} catch (Exception e) {
log.warn("Unexpected exception: " + e.getMessage(), e);
} else {
log.info("Registration succeeded!");
break;
}
} catch (Exception e) {
log.warn("Unexpected exception: " + e.getMessage(), e);
+ retry(time);
}
}
}
}
@@
-90,6
+90,11
@@
public class MsbRegister {
log.info("Service registration completed.");
}
log.info("Service registration completed.");
}
+ private void retry(int intervalInSecond) {
+ log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", intervalInSecond));
+ threadSleep(TimeUnit.SECONDS.toSeconds(intervalInSecond));
+ }
+
private void threadSleep(long second) {
log.info("Start sleeping...");
try {
private void threadSleep(long second) {
log.info("Start sleeping...");
try {