32
32
* <p>In particular, when the client is trying to connect to the backend, we allow up to
33
33
* MAX_WATCH_STREAM_FAILURES within ONLINE_STATE_TIMEOUT_MS for a connection to succeed. If we have
34
34
* too many failures or the timeout elapses, then we set the OnlineState to OFFLINE, and the client
35
- * will behave as if it is offline (get() calls will return cached data, etc.).
35
+ * will behave as if it is offline (get() calls will return cached data, etc.). The client will
36
+ * continue to attempt reconnecting, restarting the underlying connection every
37
+ * CONNECTIVITY_ATTEMPT_TIMEOUT_MS.
36
38
*/
37
39
class OnlineStateTracker {
38
40
@@ -149,7 +151,7 @@ void handleWatchStreamFailure(Status status) {
149
151
hardAssert (this .onlineStateTimer == null , "onlineStateTimer must be null" );
150
152
} else {
151
153
watchStreamFailures ++;
152
- clearConnectivityAttemptTimer ();
154
+ clearTimers ();
153
155
if (watchStreamFailures >= MAX_WATCH_STREAM_FAILURES ) {
154
156
logClientOfflineWarningIfNecessary (
155
157
String .format (
@@ -169,7 +171,7 @@ void handleWatchStreamFailure(Status status) {
169
171
* it must not be used in place of handleWatchStreamStart() and handleWatchStreamFailure().
170
172
*/
171
173
void updateState (OnlineState newState ) {
172
- clearConnectivityAttemptTimer ();
174
+ clearTimers ();
173
175
watchStreamFailures = 0 ;
174
176
175
177
if (newState == OnlineState .ONLINE ) {
@@ -205,8 +207,8 @@ private void logClientOfflineWarningIfNecessary(String reason) {
205
207
}
206
208
}
207
209
208
- /** Clears the connectivity attempt timer that has been passed in. */
209
- private void clearConnectivityAttemptTimer () {
210
+ /** Clears the OnlineStateTimer and the passed in ConnectivityAttemptTimer . */
211
+ private void clearTimers () {
210
212
if (connectivityAttemptTimer != null ) {
211
213
connectivityAttemptTimer .cancel ();
212
214
connectivityAttemptTimer = null ;
@@ -217,7 +219,7 @@ private void clearConnectivityAttemptTimer() {
217
219
}
218
220
}
219
221
220
- /** Set the connectivity attempt timer to track. */
222
+ /** Sets the connectivity attempt timer to track. */
221
223
void setConnectivityAttemptTimer (DelayedTask connectivityAttemptTimer ) {
222
224
this .connectivityAttemptTimer = connectivityAttemptTimer ;
223
225
}
0 commit comments