Skip to content

Commit

Permalink
remove recursive and add error handle
Browse files Browse the repository at this point in the history
Signed-off-by: Jiangnan Jia <[email protected]>
  • Loading branch information
jnan806 committed Nov 22, 2022
1 parent b937eb4 commit 014f0f6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/java/io/opensergo/OpenSergoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,28 @@ public void start() throws Exception {
}

private void keepAlive() {
try {
if (status != OpenSergoClientStatus.STARTING
&& status != OpenSergoClientStatus.STARTED
&& status != OpenSergoClientStatus.SHUTDOWN) {
OpenSergoLogger.info("try to restart openSergoClient...");
this.start();
// TODO change to event-based design, instead of for-loop.
for (;;) {
if (status == OpenSergoClientStatus.SHUTDOWN) {
return;
}
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
if( status != OpenSergoClientStatus.SHUTDOWN) {
keepAlive();

try {
if (status == OpenSergoClientStatus.INTERRUPTED) {
OpenSergoLogger.info("try to restart openSergoClient...");
this.start();
}
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
} catch (InterruptedException e) {
OpenSergoLogger.error(e.toString(), e);
} catch (Exception e) {
try {
this.close();
} catch (Exception ex) {
status = OpenSergoClientStatus.SHUTDOWN;
}
OpenSergoLogger.error("close OpenSergoClient because of " + e, e);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down

0 comments on commit 014f0f6

Please sign in to comment.