File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed
src/main/java/io/opensergo Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments