Class Disconnection
java.lang.Object
org.mqtt4j.hato.Disconnection
The end of an established connection, or of a connection attempt that established none.
An empty cause means no failure is reported; it does not indicate a graceful MQTT
disconnect. userRequested identifies disconnect or close, including a
failed DISCONNECT write. These fields do not distinguish a successful disconnect from an
immediate close.
Locally detected packet failures use
MqttProtocolException as the cause, and a DISCONNECT
from an MQTT 5.0 broker uses MqttBrokerDisconnectException.
reconnectDelay() tells whether the client scheduled another attempt.
Equality compares the cause by identity, because exceptions have no value equality.-
Method Summary
Modifier and TypeMethodDescriptioncause()Returns the original failure, or empty when no failure is reported.longReturns the number of the attempt that established the ended connection or that failed.booleaninthashCode()static DisconnectionDescribes an ending of connection attempt numberconnectionAttemptafter which the client does not reconnect, with the originalcause, or no reported failure when it is null.static Disconnectionof(@Nullable Throwable cause, boolean userRequested, long connectionAttempt, Duration reconnectDelay) Likeof(Throwable, boolean, long), but the client attempts to connect again afterreconnectDelay.Returns the delay, counted from when the client handled this ending, until its next connection attempt, or empty when it will not attempt to connect again unless the application callsMqttClient.connect().toString()booleanReturns whether disconnect or close was requested by the application.
-
Method Details
-
of
public static Disconnection of(@Nullable Throwable cause, boolean userRequested, long connectionAttempt) Describes an ending of connection attempt numberconnectionAttemptafter which the client does not reconnect, with the originalcause, or no reported failure when it is null.userRequestedis true when disconnect or close was requested, even if that failed.- Parameters:
cause- the original failure, or null when no failure is reporteduserRequested- whether disconnect or close was requestedconnectionAttempt- the number of the connection attempt- Returns:
the ending- Throws:
IllegalArgumentException-if `connectionAttempt` is not positive
-
of
public static Disconnection of(@Nullable Throwable cause, boolean userRequested, long connectionAttempt, Duration reconnectDelay) Likeof(Throwable, boolean, long), but the client attempts to connect again afterreconnectDelay.- Parameters:
cause- the original failure, or null when no failure is reporteduserRequested- whether disconnect or close was requestedconnectionAttempt- the number of the connection attemptreconnectDelay- the delay until the next connection attempt- Returns:
the ending- Throws:
IllegalArgumentException-if `connectionAttempt` is not positive or the delay is negative
-
cause
-
userRequested
public boolean userRequested()Returns whether disconnect or close was requested by the application.- Returns:
- whether disconnect or close was requested by the application
-
connectionAttempt
public long connectionAttempt()Returns the number of the attempt that established the ended connection or that failed. When a stop cancels a wait to reconnect, it is the number reserved for the cancelled attempt. SeeConnAck.connectionAttempt().- Returns:
- the number of the attempt that established the ended connection or that failed
-
reconnectDelay
Returns the delay, counted from when the client handled this ending, until its next connection attempt, or empty when it will not attempt to connect again unless the application callsMqttClient.connect(). A slow listener can receive the ending after the delay has passed.- Returns:
- the delay, counted from when the client handled this ending, until its next
connection attempt, or empty when it will not attempt to connect again unless the
application calls
MqttClient.connect()
-
equals
-
hashCode
-
toString
-