AMPS C# Client  5.3.5.0
AMPS C# Client for .NET
AMPS.Client.ExponentialDelayStrategy Class Reference

ExponentialDelayStrategy is an implementation that exponentially "backs off" when reconnecting to the same server, including optional jitter when backing off and a maximum amount of time to attempt reconnection before giving up entirely. More...

+ Inheritance diagram for AMPS.Client.ExponentialDelayStrategy:

Classes

class  MaximumRetryExceeded
 A specialized exception type thrown by ExponentialDelayStrategy to indicate that the client should "give up" on attempting to reconnect to a server. More...
 

Public Member Functions

 ExponentialDelayStrategy ()
 Constructs an ExponentialDelayStrategy, the default strategy for HAClient, using the default values for the class. More...
 
ExponentialDelayStrategy setInitialDelay (int initialDelay_)
 Sets the time (in milliseconds) to wait before reconnecting to a server for the first time after a failed connection. More...
 
ExponentialDelayStrategy setMaximumDelay (int maximumDelay_)
 Sets the maximum time to wait between any reconnection attempts. Exponential backoff will not exceed this maximum. More...
 
ExponentialDelayStrategy setBackoffExponent (double exponent_)
 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. More...
 
ExponentialDelayStrategy setMaximumRetryTime (int maximumRetryTime_)
 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. More...
 
ExponentialDelayStrategy setJitter (double jitter_)
 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. More...
 
int getConnectWaitDuration (String uri_)
 Gets the connection wait duration based on the provided URI. More...
 
void reset ()
 Resets the exponential delay strategy. More...
 

Static Public Attributes

const int DEFAULT_DELAY = 200
 The default time (in milliseconds) to wait before reconnecting to a server for the first time after a failed connection. More...
 
const int DEFAULT_MAXIMUM_DELAY = 20 * 1000
 The default maximum time to wait between any reconnection attempts. Exponential backoff will not exceed this maximum. More...
 
const double DEFAULT_BACKOFF_EXPONENT = 2.0
 The default 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. More...
 
const double DEFAULT_MAXIMUM_RETRY_TIME = -1.0
 The default 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. More...
 
const double DEFAULT_JITTER = 1.0
 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. More...
 

Protected Member Functions

void _throwIfMaximumExceeded ()
 An internal function used to check if the configured retry has been exceeded, and if so, throw MaximumRetryExceeded to cause the calling HAClient to give up on reconnecting to a server. More...
 
int _currentDurationAndIncrease ()
 Returns the _currentDelay, and also expands _currentDelay based on the configured exponent and maximum. More...
 

Protected Attributes

int _initialDelay
 
int _maximumDelay
 
double _backoffExponent
 
double _maximumRetryTime
 
double _jitter
 
int _currentDelay
 
String _lastUri
 
String _firstUri
 
DateTime _endTime
 
Random _random = new Random()
 

Detailed Description

ExponentialDelayStrategy is an implementation that exponentially "backs off" when reconnecting to the same server, including optional jitter when backing off and a maximum amount of time to attempt reconnection before giving up entirely.

Constructor & Destructor Documentation

◆ ExponentialDelayStrategy()

AMPS.Client.ExponentialDelayStrategy.ExponentialDelayStrategy ( )
inline

Constructs an ExponentialDelayStrategy, the default strategy for HAClient, using the default values for the class.

For example, when constructed, the new object will use DEFAULT_DELAY as the initial delay, DEFAULT_BACKOFF_EXPONENT as the backoff exponent, DEFAULT_MAXIMUM_RETRY_TIME as the maximum retry time, and so on. You can use the setters provided on the class to adjust these settings.

Member Function Documentation

◆ _currentDurationAndIncrease()

int AMPS.Client.ExponentialDelayStrategy._currentDurationAndIncrease ( )
inlineprotected

Returns the _currentDelay, and also expands _currentDelay based on the configured exponent and maximum.

Returns
The delay that should be used, prior to increasing it.

◆ _throwIfMaximumExceeded()

void AMPS.Client.ExponentialDelayStrategy._throwIfMaximumExceeded ( )
inlineprotected

An internal function used to check if the configured retry has been exceeded, and if so, throw MaximumRetryExceeded to cause the calling HAClient to give up on reconnecting to a server.

◆ getConnectWaitDuration()

int AMPS.Client.ExponentialDelayStrategy.getConnectWaitDuration ( String  uri_)
inline

Gets the connection wait duration based on the provided URI.

Parameters
uri_The URI string.
Returns
The connection wait duration.

Implements AMPS.Client.ReconnectDelayStrategy.

◆ reset()

void AMPS.Client.ExponentialDelayStrategy.reset ( )
inline

Resets the exponential delay strategy.

Implements AMPS.Client.ReconnectDelayStrategy.

◆ setBackoffExponent()

ExponentialDelayStrategy AMPS.Client.ExponentialDelayStrategy.setBackoffExponent ( double  exponent_)
inline

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
exponent_The new exponent value.
Returns
self

◆ setInitialDelay()

ExponentialDelayStrategy AMPS.Client.ExponentialDelayStrategy.setInitialDelay ( int  initialDelay_)
inline

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

Parameters
initialDelay_The new initial delay value, in milliseconds.
Returns
Self.

◆ setJitter()

ExponentialDelayStrategy AMPS.Client.ExponentialDelayStrategy.setJitter ( double  jitter_)
inline

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
jitter_The jitter factor, in multiples of the initial delay.
Returns
Self.

◆ setMaximumDelay()

ExponentialDelayStrategy AMPS.Client.ExponentialDelayStrategy.setMaximumDelay ( int  maximumDelay_)
inline

Sets the maximum time to wait between any reconnection attempts. Exponential backoff will not exceed this maximum.

Parameters
maximumDelay_The new maximum delay value, in milliseconds.
Returns
Self.

◆ setMaximumRetryTime()

ExponentialDelayStrategy AMPS.Client.ExponentialDelayStrategy.setMaximumRetryTime ( int  maximumRetryTime_)
inline

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
maximumRetryTime_The new maximum retry time, in milliseconds.
Returns
Self.

Member Data Documentation

◆ DEFAULT_BACKOFF_EXPONENT

const double AMPS.Client.ExponentialDelayStrategy.DEFAULT_BACKOFF_EXPONENT = 2.0
static

The default 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.

◆ DEFAULT_DELAY

const int AMPS.Client.ExponentialDelayStrategy.DEFAULT_DELAY = 200
static

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

◆ DEFAULT_JITTER

const double AMPS.Client.ExponentialDelayStrategy.DEFAULT_JITTER = 1.0
static

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.

◆ DEFAULT_MAXIMUM_DELAY

const int AMPS.Client.ExponentialDelayStrategy.DEFAULT_MAXIMUM_DELAY = 20 * 1000
static

The default maximum time to wait between any reconnection attempts. Exponential backoff will not exceed this maximum.

◆ DEFAULT_MAXIMUM_RETRY_TIME

const double AMPS.Client.ExponentialDelayStrategy.DEFAULT_MAXIMUM_RETRY_TIME = -1.0
static

The default 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.


The documentation for this class was generated from the following file: