net.sf.xenqtt.client
Class ProgressiveReconnectionStrategy

java.lang.Object
  extended by net.sf.xenqtt.client.ProgressiveReconnectionStrategy
All Implemented Interfaces:
Cloneable, ReconnectionStrategy

public final class ProgressiveReconnectionStrategy
extends Object
implements ReconnectionStrategy

A ReconnectionStrategy implementation that allows for progressive reconnection attempts to the broker. Reconnect attempts begin at an aggressive (configurable) interval. Subsequent attempts back off in aggressiveness with the assumption that if the broker is not nearly immediate available that an issue might prevent a reconnect in the near-term but perhaps not in the longer-term.

This class is thread-safe.


Constructor Summary
ProgressiveReconnectionStrategy(long baseReconnectMillis, int progressiveFactor, int maxNumberOfReconnects, long maxReconnectMillis)
          Create a new instance of this class.
 
Method Summary
 ReconnectionStrategy clone()
           
 void connectionEstablished()
          Called by an MqttClient instance when a connection to the broker is established.
 long connectionLost(MqttClient client, Throwable cause)
          Called by an MqttClient each time the connection to the broker is lost other than by an intentional disconnect.
 long getBaseReconnectMillis()
           
 int getCurrentRetry()
           
 int getMaxNumberOfReconnects()
           
 long getMaxReconnectMillis()
           
 int getProgressiveFactor()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressiveReconnectionStrategy

public ProgressiveReconnectionStrategy(long baseReconnectMillis,
                                       int progressiveFactor,
                                       int maxNumberOfReconnects,
                                       long maxReconnectMillis)
Create a new instance of this class.

Parameters:
baseReconnectMillis - The base reconnect millis to start at. The first retry is attempted at this interval
progressiveFactor - The progressive factor. This defines how to increase the amount of time between reconnects. For example, if the base is 100 and this is 2 the reconnects will occur as such: 100, 200, 400, 800, 1600, ...
maxNumberOfReconnects - The maximum number of reconnect attempts to make
maxReconnectMillis - maximum number of millis to wait. Once the progression has reached this value all future retries will be at this interval.
Method Detail

connectionLost

public long connectionLost(MqttClient client,
                           Throwable cause)
Description copied from interface: ReconnectionStrategy
Called by an MqttClient each time the connection to the broker is lost other than by an intentional disconnect.

Specified by:
connectionLost in interface ReconnectionStrategy
cause - The exception that cause the connection to close or resulted from the connection closing. May be null.
Returns:
Milliseconds the client should wait before trying to connect to the broker again. If <= 0 the client will stop trying to connect to the broker.
See Also:
ReconnectionStrategy.connectionLost(net.sf.xenqtt.client.MqttClient, java.lang.Throwable)

connectionEstablished

public void connectionEstablished()
Description copied from interface: ReconnectionStrategy
Called by an MqttClient instance when a connection to the broker is established.

Specified by:
connectionEstablished in interface ReconnectionStrategy
See Also:
ReconnectionStrategy.connectionEstablished()

clone

public ReconnectionStrategy clone()
Specified by:
clone in interface ReconnectionStrategy
Overrides:
clone in class Object
Returns:
A new instance of the same type as this object. This is used to create a new strategy for each client created by the MqttClientFactory.
See Also:
Object.clone(), ReconnectionStrategy.clone()

getBaseReconnectMillis

public long getBaseReconnectMillis()
Returns:
The base reconnect millis to start at. The first retry is attempted at this interval

getProgressiveFactor

public int getProgressiveFactor()
Returns:
The progressive factor. This defines how to increase the amount of time between reconnects. For example, if the base is 100 and this is 2 the reconnects will occur as such: 100, 200, 400, 800, 1600, ...

getMaxNumberOfReconnects

public int getMaxNumberOfReconnects()
Returns:
The maximum number of reconnect attempts to make

getMaxReconnectMillis

public long getMaxReconnectMillis()
Returns:
The maximum number of millis to wait. Once the progression has reached this value all future retries will be at this interval

getCurrentRetry

public int getCurrentRetry()
Returns:
The current retry count. 0 if no retries have been scheduled.


Copyright © 2013. All Rights Reserved.