-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from scribd/kabliz/APT-10467-retry
[APT-10467] Retry with Exponential Backoff
- Loading branch information
Showing
6 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...llo/src/main/java/com/scribd/armadillo/playback/error/ArmadilloHttpErrorHandlingPolicy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.scribd.armadillo.playback.error | ||
|
||
import com.google.android.exoplayer2.C | ||
import com.google.android.exoplayer2.ParserException | ||
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy | ||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy | ||
import java.net.SocketTimeoutException | ||
import java.net.UnknownHostException | ||
|
||
class ArmadilloHttpErrorHandlingPolicy : DefaultLoadErrorHandlingPolicy(DEFAULT_MIN_LOADABLE_RETRY_COUNT) { | ||
override fun getRetryDelayMsFor(loadErrorInfo: LoadErrorHandlingPolicy.LoadErrorInfo): Long { | ||
return if (loadErrorInfo.exception is UnknownHostException || loadErrorInfo.exception is SocketTimeoutException) { | ||
//retry every 10 seconds for potential loss of internet -keep buffering - internet may later succeed. | ||
if (loadErrorInfo.errorCount > 6) { | ||
C.TIME_UNSET //stop retrying after around 10 minutes | ||
} else { | ||
//exponential backoff based on a 10 second interval | ||
(1 shl (loadErrorInfo.errorCount - 1)) * 10 * 1000L | ||
} | ||
} else if (loadErrorInfo.exception is ParserException) { | ||
/* | ||
Exoplayer by default assumes ParserExceptions only occur because source content is malformed, | ||
so Exoplayer will never retry ParserExceptions. | ||
We care about content failing to checksum correctly over the internet, so we wish to retry these. | ||
*/ | ||
if (loadErrorInfo.errorCount > 3) { | ||
C.TIME_UNSET //stop retrying, the content is likely malformed | ||
} else { | ||
//This is exponential backoff based on a 1 second interval | ||
(1 shl (loadErrorInfo.errorCount - 1)) * 1000L | ||
} | ||
} else { | ||
super.getRetryDelayMsFor(loadErrorInfo) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters