Add comments for debug vars
This commit is contained in:
parent
43605d28ec
commit
d290b790d6
|
@ -5,9 +5,20 @@ import java.util.concurrent.atomic.AtomicBoolean
|
|||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
object AppCompanion {
|
||||
/**
|
||||
* Check if we are started with ACTION_BOOT_COMPLETED,
|
||||
* to avoid testing buffered responses on boot.
|
||||
*/
|
||||
val booting = AtomicBoolean(false)
|
||||
/**
|
||||
* Check if we have internet access.
|
||||
* The initial value is true, because the first time we check it is before
|
||||
* [RestartNetworkCallback] is registered.
|
||||
*/
|
||||
val hasInternet = AtomicBoolean(true)
|
||||
/** Have we received the start event ? To check the reverse proxy timeout is high enough */
|
||||
val started = AtomicBoolean(false)
|
||||
/** Have we received the ping event ? To check the reverse proxy timeout is high enough */
|
||||
val pinged = AtomicBoolean(false)
|
||||
val bufferedResponseChecked = AtomicBoolean(false)
|
||||
val keepalive = AtomicInteger(900)
|
||||
|
|
|
@ -115,7 +115,7 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||
eventSource.cancel()
|
||||
if (!shouldRestart()) return
|
||||
if (FailureHandler.newFail(context, eventSource)) {
|
||||
clearVars()
|
||||
clearDebugVars()
|
||||
RestartWorker.run(context, delay = 0)
|
||||
}
|
||||
}
|
||||
|
@ -133,12 +133,12 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||
if (!AppCompanion.hasInternet.get()) {
|
||||
Log.d(TAG, "No Internet: do not restart")
|
||||
if (FailureHandler.once(eventSource)) {
|
||||
clearVars()
|
||||
clearDebugVars()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (FailureHandler.newFail(context, eventSource)) {
|
||||
clearVars()
|
||||
clearDebugVars()
|
||||
val delay = when (FailureHandler.nFails()) {
|
||||
1 -> 2 // 2sec
|
||||
2 -> 5 // 5sec
|
||||
|
@ -153,22 +153,37 @@ class SSEListener(val context: Context) : EventSourceListener() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if service is started and call [clearDebugVars] if the service has not started.
|
||||
*
|
||||
* @return [StartService.isServiceStarted]
|
||||
*/
|
||||
private fun shouldRestart(): Boolean {
|
||||
if (!StartService.isServiceStarted) {
|
||||
Log.d(TAG, "StartService not started")
|
||||
clearVars()
|
||||
clearDebugVars()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun clearVars() {
|
||||
/**
|
||||
* Remove [startingTimer], set the service has not [started][AppCompanion.started] and not
|
||||
* [pinged][AppCompanion.pinged]. The 3 elements are used to debug the user setup.
|
||||
* The startingTimer to check buffering response, and started/ping to check the reverse proxy
|
||||
* timeout is high enough.
|
||||
*/
|
||||
private fun clearDebugVars() {
|
||||
startingTimer.getAndSet(null)?.cancel()
|
||||
AppCompanion.started.set(false)
|
||||
AppCompanion.pinged.set(false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Timer to stop the service if we don't receive the `start` event within 45 seconds.
|
||||
* Used to check if there is a reverse proxy buffering responses.
|
||||
*/
|
||||
private var startingTimer: AtomicReference<TimerTask?> = AtomicReference(null)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue