File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
core/src/main/java/com/minekube/connect Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -145,9 +145,10 @@ private class WatcherImpl implements Watcher {
145
145
146
146
@ Override
147
147
public void onOpen () {
148
- // Reset the retry backoff after a successful connection
149
- resetBackOff ();
150
148
logger .translatedInfo ("connect.watch.started" );
149
+
150
+ // Reset the retry backoff after the connection is healthy for some seconds
151
+ startResetBackOffTimer ();
151
152
}
152
153
153
154
@ Override
@@ -194,7 +195,39 @@ public void onError(Throwable t) {
194
195
: " (cause: " + t .getCause ().toString () + ")"
195
196
)
196
197
);
198
+ cancelResetBackOffTimer ();
197
199
retry ();
198
200
}
201
+
202
+ @ Override
203
+ public void onCompleted () {
204
+ cancelResetBackOffTimer ();
205
+ retry ();
206
+ }
207
+
208
+ private Timer resetBackOffTimer ;
209
+
210
+ void startResetBackOffTimer () {
211
+ if (resetBackOffTimer != null ) {
212
+ resetBackOffTimer .cancel ();
213
+ }
214
+ resetBackOffTimer = new Timer ();
215
+ resetBackOffTimer .schedule (new TimerTask () {
216
+ @ Override
217
+ public void run () {
218
+ if (started .get ()) {
219
+ resetBackOff ();
220
+ }
221
+ }
222
+ }, Duration .ofSeconds (10 ).toMillis ());
223
+ }
224
+
225
+ void cancelResetBackOffTimer () {
226
+ if (resetBackOffTimer != null ) {
227
+ resetBackOffTimer .cancel ();
228
+ resetBackOffTimer = null ;
229
+ }
230
+ }
231
+
199
232
}
200
233
}
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ public WebSocket watch(Watcher watcher) {
71
71
return httpClient .newWebSocket (req , new WebSocketListener () {
72
72
@ Override
73
73
public void onClosed (@ NotNull WebSocket webSocket , int code , @ NotNull String reason ) {
74
+ if (code != 1000 ) {
75
+ watcher .onError (new RuntimeException ("Watch closed with code " + code + ": " + reason ));
76
+ return ;
77
+ }
74
78
watcher .onCompleted ();
75
79
}
76
80
You can’t perform that action at this time.
0 commit comments