Package com.castlabs.android.network

## Class RetryConfiguration

- java.lang.Object
- - com.castlabs.android.network.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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `RetryConfiguration.Builder` | Use this builder to create new instances of the retry configuration

    - ### Nested classes/interfaces inherited from interface android.os.Parcelable

      `Parcelable.ClassLoaderCreator<T extends Object>, Parcelable.Creator<T extends Object>`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `float` | `backoffFactor` | The multiplication factor between retries applied after the first retry
    `long` | `baseDelayMs` | The initial delay applied to the first retry
    `static Parcelable.Creator<RetryConfiguration>` | `CREATOR` |
    `static float` | `DEFAULT_BACKOFF_FACTOR_MS` | The default backoff factor of 2
    `static int` | `DEFAULT_BASE_DELAY_MS` | The default base delay of 1 second
    `static float` | `DEFAULT_FUZZY_FACTOR` | The default fuzzy factor of 0.5
    `static RetryConfiguration` | `DEFAULT_LIVE_CONFIGURATION` | Default retry parameters for Live playback.
    `static int` | `DEFAULT_MAX_ATTEMPTS` | The default number of permitted attempts
    `static int` | `DEFAULT_MAX_DELAY_MS` | The default maximum delay of 5 seconds.
    `static RetryConfiguration` | `DEFAULT_NO_RETRIES_CONFIGURATION` | Retry parameter configuration that does not permit any retries
    `static RetryConfiguration` | `DEFAULT_VOD_CONFIGURATION` | Default retry parameters for VOD playback.
    `float` | `fuzzFactor` | The fuzzy factor applied to each retry delay
    `int` | `maxAttempts` | The maximum number of requests before the request will fail.
    `long` | `maxDelayMs` | The upper bound for delays.

    - ### Fields inherited from interface android.os.Parcelable

      `CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RetryConfiguration​(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs)` | Create a new instance of the counter
    `RetryConfiguration​(int maxAttempts, long baseDelayMs, float backoffFactor, float fuzzFactor, long maxDelayMs, int[] retryCodes, String[] retryExceptionNames)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `describeContents()` |
    `boolean` | `equals​(Object obj)` |
    `int` | `hashCode()` |
    `boolean` | `retryCode​(int code)` | Checks whether the provided code triggers retries or not
    `boolean` | `retryException​(Exception exception)` |
    `com.google.android.exoplayer2.upstream.RetryCounter` | `toCounter()` | INTERNAL: Converts this configuration to the retry counter that will be used by the player
    `void` | `writeToParcel​(Parcel dest, int flags)` |

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### 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)

    - #### CREATOR

          public static final Parcelable.Creator<RetryConfiguration> CREATOR

    - #### 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

    - #### describeContents

          public int describeContents()

      Specified by:
        `describeContents` in interface `Parcelable`

    - #### writeToParcel

          public void writeToParcel​(Parcel dest,
                                    int flags)

      Specified by:
        `writeToParcel` in interface `Parcelable`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals​(Object obj)

      Overrides:
        `equals` 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)