Class RetryConfiguration

  • All Implemented Interfaces:
    Parcelable

    public class RetryConfiguration
    extends Object
    implements 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
    In addition, to avoid clients hitting the server always at the same time, the fuzz factor is applied. A fuzz factor of 0.5 means we fuzz the delay 50% in either direction. So for the example above, we would get retry delays as:
    • 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
    • Field Detail

      • DEFAULT_MAX_ATTEMPTS

        public static final int DEFAULT_MAX_ATTEMPTS
        The default number of permitted attempts
        See Also:
        Constant Field Values
      • DEFAULT_BASE_DELAY_MS

        public static final int DEFAULT_BASE_DELAY_MS
        The default base delay of 1 second
        See Also:
        Constant Field Values
      • DEFAULT_FUZZY_FACTOR

        public static final float DEFAULT_FUZZY_FACTOR
        The default fuzzy factor of 0.5
        See Also:
        Constant Field Values
      • DEFAULT_BACKOFF_FACTOR_MS

        public static final float DEFAULT_BACKOFF_FACTOR_MS
        The default backoff factor of 2
        See Also:
        Constant Field Values
      • DEFAULT_MAX_DELAY_MS

        public static final int DEFAULT_MAX_DELAY_MS
        The default maximum delay of 5 seconds.
        See Also:
        Constant Field Values
      • DEFAULT_NO_RETRIES_CONFIGURATION

        public static final RetryConfiguration DEFAULT_NO_RETRIES_CONFIGURATION
        Retry parameter configuration that does not permit any retries
      • DEFAULT_VOD_CONFIGURATION

        public static final RetryConfiguration DEFAULT_VOD_CONFIGURATION
        Default retry parameters for VOD playback. This uses all the default values and permits 3 attempts (2 retries)
      • DEFAULT_LIVE_CONFIGURATION

        public static final RetryConfiguration DEFAULT_LIVE_CONFIGURATION
        Default retry parameters for Live playback. This uses all the default values and permits 6 attempts (5 retries)
      • maxAttempts

        public final int maxAttempts
        The maximum number of requests before the request will fail. A value of 1 will disable any retry attempts.
      • baseDelayMs

        public final long baseDelayMs
        The initial delay applied to the first retry
      • backoffFactor

        public final float backoffFactor
        The multiplication factor between retries applied after the first retry
      • fuzzFactor

        public final float fuzzFactor
        The fuzzy factor applied to each retry delay
      • maxDelayMs

        public final long maxDelayMs
        The upper bound for delays. The player will never delay a retry longer than this value.
    • Constructor Detail

      • 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 retry
        backoffFactor - The multiplication factor between retries applied after the first retry
        fuzzFactor - The fuzzy factor applied to each retry delay
        maxDelayMs - 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)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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:
        true in case the retry will be triggered and false otherwise
      • retryException

        public boolean retryException​(@NonNull
                                      Exception exception)