Package com.castlabs.android.network
Class RetryConfiguration
java.lang.Object
com.castlabs.android.network.RetryConfiguration
- All Implemented Interfaces:
Parcelable
Configures the network request retry behaviour. When components of the player
perform network requests, and the request fails, for example the server responds
with a 404, the component that issues the request might decide to retry the request again
before a fatal error is raised. Instances of this class are used to configure how
often the component will retry and how much time the component will wait
between tries.
The delay between the tries will increase based on the
backoffFactor. The delay for the first retry is defined as baseDelayMs
Every following retry delay is calculated as the previous retry delay
times the backoffFactor. Hence we get
- Attempt 0 (first request) = 0 (no delay)
- Attempt 1 (first retry) = 1s (base delay)
- Attempt 2 (second retry) = (delay of attempt 1) * backoffFactor = 1s * 2 = 2s
- Attempt 3 (third retry) = (delay of attempt 2) * backoffFactor = 2s * 2 = 4s
- delay of 1 ± 50% (0.5 to 1.5)
- delay of 2 ± 50% (1 to 3)
- delay of 4 ± 50% (2 to 6)
You can create instances of this class either using the public constructor
RetryConfiguration(int, long, float, float, long, int[], String[]) or through the RetryConfiguration.Builder.
- Since:
- 4.1.11
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUse this builder to create new instances of the retry configurationNested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal floatThe multiplication factor between retries applied after the first retryfinal longThe initial delay applied to the first retrystatic final Parcelable.Creator<RetryConfiguration> Creator for Parcelable.static final floatThe default backoff factor of 2static final intThe default base delay of 1 secondstatic final floatThe default fuzzy factor of 0.5static final RetryConfigurationDefault retry parameters for Live playback.static final intThe default number of permitted attemptsstatic final intThe default maximum delay of 5 seconds.static final RetryConfigurationRetry parameter configuration that does not permit any retriesstatic final RetryConfigurationDefault retry parameters for VOD playback.final floatThe fuzzy factor applied to each retry delayfinal intThe maximum number of requests before the request will fail.final longThe upper bound for delays.Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionRetryConfiguration(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs) Create a new instance of the counterRetryConfiguration(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs, int[] retryCodes, String[] retryExceptionNames) Create a new instance of the counter -
Method Summary
Modifier and TypeMethodDescriptionintbooleaninthashCode()booleanretryCode(int code) Checks whether the provided code triggers retries or notbooleanretryException(Exception exception) Checks whether the provided exception triggers retries or not.com.google.android.exoplayer2.upstream.RetryCounterINTERNAL: Converts this configuration to the retry counter that will be used by the playervoidwriteToParcel(Parcel dest, int flags)
-
Field Details
-
DEFAULT_MAX_ATTEMPTS
public static final int DEFAULT_MAX_ATTEMPTSThe default number of permitted attempts- See Also:
-
DEFAULT_BASE_DELAY_MS
public static final int DEFAULT_BASE_DELAY_MSThe default base delay of 1 second- See Also:
-
DEFAULT_FUZZY_FACTOR
public static final float DEFAULT_FUZZY_FACTORThe default fuzzy factor of 0.5- See Also:
-
DEFAULT_BACKOFF_FACTOR_MS
public static final float DEFAULT_BACKOFF_FACTOR_MSThe default backoff factor of 2- See Also:
-
DEFAULT_MAX_DELAY_MS
public static final int DEFAULT_MAX_DELAY_MSThe default maximum delay of 5 seconds.- See Also:
-
DEFAULT_NO_RETRIES_CONFIGURATION
Retry parameter configuration that does not permit any retries -
DEFAULT_VOD_CONFIGURATION
Default retry parameters for VOD playback. This uses all the default values and permits 3 attempts (2 retries) -
DEFAULT_LIVE_CONFIGURATION
Default retry parameters for Live playback. This uses all the default values and permits 6 attempts (5 retries) -
CREATOR
Creator for Parcelable. -
maxAttempts
public final int maxAttemptsThe maximum number of requests before the request will fail. A value of 1 will disable any retry attempts. -
baseDelayMs
public final long baseDelayMsThe initial delay applied to the first retry -
backoffFactor
public final float backoffFactorThe multiplication factor between retries applied after the first retry -
fuzzFactor
public final float fuzzFactorThe fuzzy factor applied to each retry delay -
maxDelayMs
public final long maxDelayMsThe upper bound for delays. The player will never delay a retry longer than this value.
-
-
Constructor Details
-
RetryConfiguration
public RetryConfiguration(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs) Create a new instance of the counter- Parameters:
maxAttempts- The maximum number of requests before the request will fail. A value of 1 will disable any retry attempts.baseDelayMs- The initial delay applied to the first retrybackoffFactor- The multiplication factor between retries applied after the first retryfuzzFactor- The fuzzy factor applied to each retry delaymaxDelayMs- The upper bound for delays. The player will never delay a retry longer than this value.
-
RetryConfiguration
public RetryConfiguration(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs, @Nullable int[] retryCodes, @Nullable String[] retryExceptionNames) Create a new instance of the counter- Parameters:
maxAttempts- The maximum number of requests before the request will fail. A value of 1 will disable any retry attempts.baseDelayMs- The initial delay applied to the first retrybackoffFactor- The multiplication factor between retries applied after the first retryfuzzFactor- The fuzzy factor applied to each retry delaymaxDelayMs- The upper bound for delays. The player will never delay a retry longer than this value.retryCodes- Error codes triggering retriesretryExceptionNames- Exception names triggering retries
-
-
Method Details
-
describeContents
public int describeContents()- Specified by:
describeContentsin interfaceParcelable
-
writeToParcel
- Specified by:
writeToParcelin interfaceParcelable
-
hashCode
public int hashCode() -
equals
-
toCounter
public com.google.android.exoplayer2.upstream.RetryCounter toCounter()INTERNAL: Converts this configuration to the retry counter that will be used by the player- Returns:
- The retry counter
-
retryCode
public boolean retryCode(int code) Checks whether the provided code triggers retries or not- Parameters:
code- The code- Returns:
truein case the retry will be triggered andfalseotherwise
-
retryException
Checks whether the provided exception triggers retries or not.- Parameters:
exception- The exception to check.- Returns:
trueif the exception triggers a retry,falseotherwise.
-