@DoNotImplement public interface MqttClientReconnector
MqttClientDisconnectedContext and can be used for reconnecting.
The client will reconnect only if at least one of the methods reconnect(boolean) or reconnectWhen(CompletableFuture, BiConsumer) is called.
All methods must only be called in MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext).
Some methods can also be called in the callback supplied to reconnectWhen(CompletableFuture, BiConsumer).
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_DELAY_MS
Default delay in milliseconds the client will wait for before trying to reconnect.
|
static boolean |
DEFAULT_RECONNECT
If reconnect is enabled by default.
|
static boolean |
DEFAULT_REPUBLISH_IF_SESSION_EXPIRED
If republish when the session expired before the client reconnected successfully is enabled by default.
|
static boolean |
DEFAULT_RESUBSCRIBE_IF_SESSION_EXPIRED
If resubscribe when the session expired before the client reconnected successfully is enabled by default.
|
| Modifier and Type | Method and Description |
|---|---|
@NotNull MqttClientReconnector |
delay(long delay,
@NotNull TimeUnit timeUnit)
Sets a delay the client will wait for before trying to reconnect.
|
int |
getAttempts() |
long |
getDelay(@NotNull TimeUnit timeUnit)
Returns the currently set delay the client will wait for before trying to reconnect.
|
@NotNull MqttClientTransportConfig |
getTransportConfig()
Returns the currently set transport configuration the client will try to reconnect with.
|
boolean |
isReconnect() |
boolean |
isRepublishIfSessionExpired() |
boolean |
isResubscribeIfSessionExpired() |
@NotNull MqttClientReconnector |
reconnect(boolean reconnect)
Instructs the client to reconnect or not.
|
<T> @NotNull MqttClientReconnector |
reconnectWhen(@NotNull CompletableFuture<T> future,
@Nullable BiConsumer<? super T,? super Throwable> callback)
Instructs the client to reconnect after a future completes.
|
@NotNull MqttClientReconnector |
republishIfSessionExpired(boolean republish)
Instructs the client to queue pending Publish messages and automatically publish them even if the session expired
before reconnected successfully.
|
@NotNull MqttClientReconnector |
resubscribeIfSessionExpired(boolean resubscribe)
Instructs the client to automatically restore its subscriptions when the session expired before it reconnected
successfully.
|
MqttClientTransportConfigBuilder.Nested<? extends MqttClientReconnector> |
transportConfig()
Fluent counterpart of
transportConfig(MqttClientTransportConfig). |
@NotNull MqttClientReconnector |
transportConfig(@NotNull MqttClientTransportConfig transportConfig)
Sets a different transport configuration the client will try to reconnect with.
|
static final boolean DEFAULT_RECONNECT
static final boolean DEFAULT_RESUBSCRIBE_IF_SESSION_EXPIRED
static final boolean DEFAULT_REPUBLISH_IF_SESSION_EXPIRED
static final long DEFAULT_DELAY_MS
int getAttempts()
@NotNull @NotNull MqttClientReconnector reconnect(boolean reconnect)
reconnect - whether to reconnect.@NotNull <T> @NotNull MqttClientReconnector reconnectWhen(@NotNull @NotNull CompletableFuture<T> future, @Nullable @Nullable BiConsumer<? super T,? super Throwable> callback)
If additionally a delay is supplied, the client will reconnect after both are
complete.
This method must only be called in MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext)
and not in the supplied callback.
T - the result type of the future.future - the client will reconnect only after the future completes.callback - the callback that will be called after the future completes and before the client will reconnect.
It can be used to set new connect properties (e.g. credentials).UnsupportedOperationException - if called outside of MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext).boolean isReconnect()
@NotNull @NotNull MqttClientReconnector resubscribeIfSessionExpired(boolean resubscribe)
When the client reconnected successfully and its session is still present, the server still knows its subscriptions and they do not need to be restored.
This setting only has effect if the client will reconnect (at least one of the methods reconnect(boolean) or reconnectWhen(CompletableFuture, BiConsumer) is called).
This method must only be called in MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext)
and not in the callback supplied to reconnectWhen(CompletableFuture, BiConsumer).
resubscribe - whether to resubscribe when the session expired before the client reconnected successfully.UnsupportedOperationException - if called outside of MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext).boolean isResubscribeIfSessionExpired()
@NotNull @NotNull MqttClientReconnector republishIfSessionExpired(boolean republish)
When the client reconnected successfully and its session is still present, the client will always queue pending Publish messages and automatically publish them to ensure the QoS guarantees.
This setting only has effect if the client will reconnect (at least one of the methods reconnect(boolean) or reconnectWhen(CompletableFuture, BiConsumer) is called).
This method must only be called in MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext)
and not in the callback supplied to reconnectWhen(CompletableFuture, BiConsumer).
republish - whether to republish when the session expired before the client reconnected successfully.UnsupportedOperationException - if called outside of MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext).boolean isRepublishIfSessionExpired()
@NotNull @NotNull MqttClientReconnector delay(long delay, @NotNull @NotNull TimeUnit timeUnit)
This setting only has effect if the client will reconnect (at least one of the methods reconnect(boolean) or reconnectWhen(CompletableFuture, BiConsumer) is called).
If additionally a future is supplied, the client will
reconnect after both are complete.
This method must only be called in MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext)
and not in the callback supplied to reconnectWhen(CompletableFuture, BiConsumer).
delay - delay which the client will wait before trying to reconnect.timeUnit - the time unit of the delay.UnsupportedOperationException - if called outside of MqttClientDisconnectedListener.onDisconnected(MqttClientDisconnectedContext).long getDelay(@NotNull
@NotNull TimeUnit timeUnit)
If the delay(long, TimeUnit) method has not been called before (including previous MqttClientDisconnectedListeners) it will be DEFAULT_DELAY_MS.
timeUnit - the time unit of the returned delay.@NotNull @NotNull MqttClientReconnector transportConfig(@NotNull @NotNull MqttClientTransportConfig transportConfig)
transportConfig - the transport configuration the client will try to reconnect with.@CheckReturnValue MqttClientTransportConfigBuilder.Nested<? extends MqttClientReconnector> transportConfig()
transportConfig(MqttClientTransportConfig).
Calling MqttClientTransportConfigBuilder.Nested#applyTransportConfig() on the returned builder has the
effect of extending the current transport configuration.
transportConfig(MqttClientTransportConfig)@NotNull @NotNull MqttClientTransportConfig getTransportConfig()
If the transportConfig(MqttClientTransportConfig) method has not been called before (including previous
MqttClientDisconnectedListeners) it will be the transport configuration
the client was connected with or the default
transport configuration if it has not been connected yet.