Class PeriodicReconnectStrategy
java.lang.Object
org.openhab.core.io.transport.mqtt.reconnect.AbstractReconnectStrategy
org.openhab.core.io.transport.mqtt.reconnect.PeriodicReconnectStrategy
This is an implementation of the
AbstractReconnectStrategy
. This
strategy tries to reconnect after 10 seconds and then every 60 seconds
after a broker connection has been lost.- Author:
- David Graeff - Initial contribution
-
Field Summary
Fields inherited from class org.openhab.core.io.transport.mqtt.reconnect.AbstractReconnectStrategy
brokerConnection
-
Constructor Summary
ConstructorDescriptionUse a default 60s reconnect frequency and try the first reconnect after 10s.PeriodicReconnectStrategy
(int reconnectFrequency, int firstReconnectAfter) Create aPeriodicReconnectStrategy
with the given reconnect frequency and first reconnect time parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
TheMqttConnectionObserver
will call this method if a broker connection has been successfully established.int
int
boolean
Return true if your implementation is trying to establish a connection, false otherwise.boolean
Returns if the reconnect strategy has been started.void
TheMqttConnectionObserver
will call this method if a broker connection has been lost or couldn't be established.void
start()
Start the reconnect strategy handling.void
stop()
Stop the reconnect strategy handling.Methods inherited from class org.openhab.core.io.transport.mqtt.reconnect.AbstractReconnectStrategy
getBrokerConnection, setBrokerConnection
-
Constructor Details
-
PeriodicReconnectStrategy
public PeriodicReconnectStrategy()Use a default 60s reconnect frequency and try the first reconnect after 10s. -
PeriodicReconnectStrategy
public PeriodicReconnectStrategy(int reconnectFrequency, int firstReconnectAfter) Create aPeriodicReconnectStrategy
with the given reconnect frequency and first reconnect time parameters.- Parameters:
reconnectFrequency
- This strategy tries to reconnect in this frequency in ms.firstReconnectAfter
- After a connection is lost, the very first reconnect attempt will be performed after this time in ms.
-
-
Method Details
-
start
public void start()Description copied from class:AbstractReconnectStrategy
Start the reconnect strategy handling.- Specified by:
start
in classAbstractReconnectStrategy
-
stop
public void stop()Description copied from class:AbstractReconnectStrategy
Stop the reconnect strategy handling.It must be possible to restart a reconnect strategy again after it has been stopped.
- Specified by:
stop
in classAbstractReconnectStrategy
-
isStarted
public boolean isStarted()Returns if the reconnect strategy has been started.- Returns:
- true if started
-
lostConnection
public void lostConnection()Description copied from class:AbstractReconnectStrategy
TheMqttConnectionObserver
will call this method if a broker connection has been lost or couldn't be established. Your implementation should start trying to reestablish a connection.- Specified by:
lostConnection
in classAbstractReconnectStrategy
-
connectionEstablished
public void connectionEstablished()Description copied from class:AbstractReconnectStrategy
TheMqttConnectionObserver
will call this method if a broker connection has been successfully established. Your implementation should stop reconnection attempts and release resources.- Specified by:
connectionEstablished
in classAbstractReconnectStrategy
-
isReconnecting
public boolean isReconnecting()Description copied from class:AbstractReconnectStrategy
Return true if your implementation is trying to establish a connection, false otherwise.- Specified by:
isReconnecting
in classAbstractReconnectStrategy
-
getReconnectFrequency
public int getReconnectFrequency() -
getFirstReconnectAfter
public int getFirstReconnectAfter()
-