Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ExponentialDelayStrategy

ExponentialDelayStrategy is an implementation that exponentially backs off when reconnecting to the same server, with a maximum time to retry before it gives up entirely.

// create the strategy with all default values
var strategy = new amps.ExponentialDelayStrategy();

// set jitter to 3.5, and keep other parameters default
var strategy = new amps.ExponentialDelayStrategy({jitter: 3.5});

// set all params as arguments...
var strategy = new amps.ExponentialDelayStrategy(400, 25000, 1.5, 0, 2.5);

// ... or using the object with values
var strategy = new amps.ExponentialDelayStrategy({
    initialDelay: 400,
    maximumDelay: 25000,
    backoffExponent: 1.5,
    maximumRetryTime: 0,
    jitter: 2.5
});

// ... or using setter methods
var strategy = new amps.ExponentialDelayStrategy()
    .initialDelay(400)
    .maximumDelay(25000)
    .backoffExponent(1.5)
    .maximumRetryTime(0)
    .jitter(2.5);

 // Setters can also be used after initialization of the strategy to change values dynamically
});

Hierarchy

  • ExponentialDelayStrategy

Implements

Index

Constructors

constructor


  • Parameters

    • Optional initialDelay: number

      The time (in milliseconds) to wait before reconnecting to a server for the first time after a failed connection. The default value is 200 ms.

    • Optional maximumDelay: number

      The maximum time to wait for any reconnect attempt (milliseconds). Exponential backoff will not exceed this maximum. The default value is 20 s.

    • Optional backoffExponent: number

      The exponent to use for calculating the next delay time. For example, if the initial time is 200ms and the exponent is 2.0, the next delay will be 400ms, then 800ms, etc. The default value is 2.0.

    • Optional maximumRetryTime: number

      The maximum time (milliseconds) to allow reconnect attempts to continue without a successful connection, before giving up and abandoning the connection attempt. If zero, the client never gives up. The default value is 0.

    • Optional jitter: number

      The amount of 'jitter' to apply when calculating a delay time, measured in multiples of the initial delay. Jitter is used to reduce the number of simultaneous reconnects that may be issued from multiple clients. The default value is 1.0.

    Returns ExponentialDelayStrategy


  • Parameters

    Returns ExponentialDelayStrategy

Methods

backoffExponent

  • This method sets the exponent to use for calculating the next delay time. For example if the initial time is 200ms and the exponent is 2.0, the next delay will be 400ms, then 800ms, etc.

    Parameters

    • Default value backoffExponent: number = 2

      The exponent to use for calculating the next delay time. For example, if the initial time is 200ms and the exponent is 2.0, the next delay will be 400ms, then 800ms, etc.

    Returns ExponentialDelayStrategy

    The Delay object.

getConnectWaitDuration

  • getConnectWaitDuration(uri: string): number
  • This method returns the time (in milliseconds) that the client should delay before connecting to the given server URI.

    Parameters

    • uri: string

      The URI of the server.

    Returns number

    The time (in milliseconds) that the client should delay.

initialDelay

  • This method sets the time (in milliseconds) to wait before reconnecting to a server for the first time after a failed connection.

    Parameters

    • Default value initialDelay: number = 200

      The time (in milliseconds) to wait before reconnecting to a server for the first time after a failed connection.

    Returns ExponentialDelayStrategy

    The Delay object.

jitter

  • This method sets the jitter factor used to add randomness to the delay time. Jitter is represented as a multiple of the initial delay time; a random number from [ 0, (JITTER * INITIAL_DELAY) ) is added to nonzero time delays.

    Parameters

    • Default value jitter: number = 1

      The amount of 'jitter' to apply when calculating a delay time, measured in multiples of the initial delay. Jitter is used to reduce the number of simultaneous reconnects that may be issued from multiple clients.

    Returns ExponentialDelayStrategy

    The Delay object.

maximumDelay

  • This method sets the maximum time to wait between any reconnection attempts. Exponential backoff will not exceed this maximum.

    Parameters

    • Default value maximumDelay: number = 20000

      The maximum time to wait for any reconnect attempt (milliseconds). Exponential backoff will not exceed this maximum.

    Returns ExponentialDelayStrategy

    The Delay object.

maximumRetryTime

  • This method sets the time (in millseconds) to allow reconnect attempts to continue without a successful connection, before "giving up" and abandoning the connection attempt. 0 means never give up.

    Parameters

    • Default value maximumRetryTime: number = 0

      The maximum time (milliseconds) to allow econnect attempts to continue without a successful connection, before giving up and abandoning the connection attempt. If zero, the client never gives up.

    Returns ExponentialDelayStrategy

    The Delay object.

reset

  • reset(): void
  • This method resets the state of this reconnect delay. AMPS calls this method when a connection is established.

    Returns void