public class ExponentialDelayStrategy extends java.lang.Object implements ReconnectDelayStrategy
Modifier and Type | Class and Description |
---|---|
static class |
ExponentialDelayStrategy.MaximumRetryExceeded
A specialized exception type thrown by ExponentialDelayStrategy
to indicate that the client should "give up" on attempting to
reconnect to a server.
|
Modifier and Type | Field and Description |
---|---|
protected double |
_backoffExponent |
protected int |
_currentDelay |
protected java.lang.String |
_firstUri |
protected int |
_initialDelay |
protected double |
_jitter |
protected java.lang.String |
_lastUri |
protected int |
_maximumDelay |
protected int |
_maximumRetryTime |
protected long |
_startTime |
static double |
DEFAULT_BACKOFF_EXPONENT
The default exponent to use for calculating the next delay time.
|
static int |
DEFAULT_DELAY
The default time (in milliseconds) to wait before reconnecting to a
server for the first time after a failed connection.
|
static double |
DEFAULT_JITTER
The amount of 'jitter' to apply when calculating a delay time,
measured in multiples of the initial delay.
|
static int |
DEFAULT_MAXIMUM_DELAY
The default maximum time to wait between any reconnection attempts.
|
static int |
DEFAULT_MAXIMUM_RETRY_TIME
The default time (in milliseconds) to allow reconnect attempts to
continue without a successful connection, before "giving up" and
abandoning the connection attempt.
|
Constructor and Description |
---|
ExponentialDelayStrategy()
Constructs an ExponentialDelayStrategy, the default strategy for
HAClient, using the default values for the class.
|
Modifier and Type | Method and Description |
---|---|
protected int |
_currentDurationAndIncrease()
Returns the _currentDelay, and also expands _currentDelay based
on the configured exponent and maximum.
|
protected 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.
|
int |
getConnectWaitDuration(java.lang.String uri_)
Gets the connection wait duration based on the provided URI.
|
void |
reset()
Resets the exponential delay strategy.
|
ExponentialDelayStrategy |
setBackoffExponent(double exponent_)
Sets the exponent to use for calculating the next delay time.
|
ExponentialDelayStrategy |
setInitialDelay(int initialDelay_)
Sets the time (in milliseconds) to wait before reconnecting to
a server for the first time after a failed connection.
|
ExponentialDelayStrategy |
setJitter(double jitter_)
Sets the jitter factor used to add randomness to the delay time.
|
ExponentialDelayStrategy |
setMaximumDelay(int maximumDelay_)
Sets the maximum time to wait between any reconnection attempts.
|
ExponentialDelayStrategy |
setMaximumRetryTime(int maximumRetryTime_)
Sets the time (in milliseconds) to allow reconnect attempts to
continue without a successful connection, before "giving up" and
abandoning the connection attempt.
|
public static final int DEFAULT_DELAY
public static final int DEFAULT_MAXIMUM_DELAY
public static final double DEFAULT_BACKOFF_EXPONENT
public static final int DEFAULT_MAXIMUM_RETRY_TIME
public static final double DEFAULT_JITTER
protected int _initialDelay
protected int _maximumDelay
protected double _backoffExponent
protected int _maximumRetryTime
protected double _jitter
protected int _currentDelay
protected java.lang.String _lastUri
protected java.lang.String _firstUri
protected long _startTime
public ExponentialDelayStrategy()
DEFAULT_DELAY
(200 ms)
as the initial delay, the DEFAULT_BACKOFF_EXPONENT
(2.0)
as the backoff exponent, the DEFAULT_MAXIMUM_RETRY_TIME
(0 -- never time out) as the maximum
retry time, and so on. You can use the setters provided on the class to
adjust these settings.public ExponentialDelayStrategy setInitialDelay(int initialDelay_)
initialDelay_
- The new initial delay value, in milliseconds.public ExponentialDelayStrategy setMaximumDelay(int maximumDelay_)
maximumDelay_
- The new maximum delay value, in milliseconds.public ExponentialDelayStrategy setBackoffExponent(double exponent_)
exponent_
- The new exponent value.public ExponentialDelayStrategy setMaximumRetryTime(int maximumRetryTime_)
maximumRetryTime_
- The new maximum retry time, in milliseconds.public ExponentialDelayStrategy setJitter(double jitter_)
jitter_
- The jitter factor, in multiples of the initial delay.public int getConnectWaitDuration(java.lang.String uri_) throws java.lang.Exception
getConnectWaitDuration
in interface ReconnectDelayStrategy
uri_
- The URI string.java.lang.Exception
- Any exception thrown indicates no connection
should be attempted; the client in essence
should "give up."public void reset()
reset
in interface ReconnectDelayStrategy
protected void _throwIfMaximumExceeded() throws ExponentialDelayStrategy.MaximumRetryExceeded
ExponentialDelayStrategy.MaximumRetryExceeded
- The configured maximum retry time has
been exceeded.protected int _currentDurationAndIncrease() throws ExponentialDelayStrategy.MaximumRetryExceeded
ExponentialDelayStrategy.MaximumRetryExceeded
- The configured maximum retry time has
been exceeded.