Skip to content

Commit 014f0f6

Browse files
committed
remove recursive and add error handle
Signed-off-by: Jiangnan Jia <[email protected]>
1 parent b937eb4 commit 014f0f6

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/main/java/io/opensergo/OpenSergoClient.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,28 @@ public void start() throws Exception {
102102
}
103103

104104
private void keepAlive() {
105-
try {
106-
if (status != OpenSergoClientStatus.STARTING
107-
&& status != OpenSergoClientStatus.STARTED
108-
&& status != OpenSergoClientStatus.SHUTDOWN) {
109-
OpenSergoLogger.info("try to restart openSergoClient...");
110-
this.start();
105+
// TODO change to event-based design, instead of for-loop.
106+
for (;;) {
107+
if (status == OpenSergoClientStatus.SHUTDOWN) {
108+
return;
111109
}
112-
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
113-
if( status != OpenSergoClientStatus.SHUTDOWN) {
114-
keepAlive();
110+
111+
try {
112+
if (status == OpenSergoClientStatus.INTERRUPTED) {
113+
OpenSergoLogger.info("try to restart openSergoClient...");
114+
this.start();
115+
}
116+
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
117+
} catch (InterruptedException e) {
118+
OpenSergoLogger.error(e.toString(), e);
119+
} catch (Exception e) {
120+
try {
121+
this.close();
122+
} catch (Exception ex) {
123+
status = OpenSergoClientStatus.SHUTDOWN;
124+
}
125+
OpenSergoLogger.error("close OpenSergoClient because of " + e, e);
115126
}
116-
} catch (Exception e) {
117-
e.printStackTrace();
118127
}
119128
}
120129

0 commit comments

Comments
 (0)