Class Disconnection

java.lang.Object
org.mqtt4j.hato.Disconnection

public final class Disconnection extends Object
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 Details

    • of

      public static Disconnection of(@Nullable Throwable cause, boolean userRequested, long connectionAttempt)
      Describes an ending of connection attempt number connectionAttempt after which the client does not reconnect, with the original cause, or no reported failure when it is null. userRequested is true when disconnect or close was requested, even if that failed.
      Parameters:
      cause - the original failure, or null when no failure is reported
      userRequested - whether disconnect or close was requested
      connectionAttempt - 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)
      Like of(Throwable, boolean, long), but the client attempts to connect again after reconnectDelay.
      Parameters:
      cause - the original failure, or null when no failure is reported
      userRequested - whether disconnect or close was requested
      connectionAttempt - the number of the connection attempt
      reconnectDelay - the delay until the next connection attempt
      Returns:
      the ending
      
      Throws:
      IllegalArgumentException -
      if `connectionAttempt` is not positive or the delay is negative
      
    • cause

      public Optional<Throwable> cause()
      Returns the original failure, or empty when no failure is reported.
      Returns:
      the original failure, or empty when no failure is reported
    • 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. See ConnAck.connectionAttempt().
      Returns:
      the number of the attempt that established the ended connection or that failed
    • reconnectDelay

      public Optional<Duration> 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 calls MqttClient.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

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object