Store dummy eventSource when setting one failure
This commit is contained in:
parent
2e1e309ebb
commit
b8012ae2af
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.util.Log
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import okhttp3.Request
|
||||
import okhttp3.sse.EventSource
|
||||
import org.unifiedpush.distributor.nextpush.AppCompanion
|
||||
import org.unifiedpush.distributor.nextpush.utils.DisconnectedNotification
|
||||
|
@ -97,12 +98,27 @@ object FailureCounter {
|
|||
*
|
||||
* Used when there is no Internet access, or we want to restart the sync request to ack messages.
|
||||
*
|
||||
* The eventSource isn't closed, else it would call _onFailure_ and try to restart, which will
|
||||
* be redundant
|
||||
* We replace the eventSource with a dummy eventSource because when closing, this source will call _onFailure_
|
||||
* and we don't want to add a new failure when it does.
|
||||
*/
|
||||
fun setFailOnce() {
|
||||
Log.d(TAG, "setFailOnce")
|
||||
Atomics.nFails.set(1)
|
||||
val dummyEventSource = getDummyEventSource()
|
||||
Atomics.eventSource.getAndSet(dummyEventSource)?.cancel()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return dummy event source, used when we don't want the next fail to be
|
||||
* counted
|
||||
*/
|
||||
private fun getDummyEventSource(): EventSource {
|
||||
return object : EventSource {
|
||||
override fun cancel() {}
|
||||
override fun request(): Request {
|
||||
return Request.Builder().build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearFails() {
|
||||
|
|
Loading…
Reference in New Issue