Enum Class FailurePolicy

java.lang.Object
java.lang.Enum<FailurePolicy>
org.mqtt4j.hato.FailurePolicy
All Implemented Interfaces:
Serializable, Comparable<FailurePolicy>, Constable

public enum FailurePolicy extends Enum<FailurePolicy>

What a push subscription does when its handler throws for a delivery, and a hand-off subscription when its acceptor throws. Set it with Subscribe.withFailurePolicy(FailurePolicy); pull subscriptions have no handler and accept only STOP.

Either policy applies only to exceptions that escape the handler or the acceptor. To retry a transient failure, catch it and repeat the work inside the handler, which keeps the subscription's order and holds back the acknowledgement meanwhile. A skipped failure is logged, and ClientStats.Receiving.dropped() counts it as ClientStats.DropReason.FAILED.

  • Enum Constant Details

    • STOP

      public static final FailurePolicy STOP
      Stops the client when the failed delivery still holds back its acknowledgement: a QoS 1 or 2 delivery with AckMode.AFTER_HANDLER, or with AckMode.MANUAL before MqttDelivery.ack(). The failure ends the connection and withdraws the connection request, as MqttSubscriber.subscribe(Subscribe, java.util.function.Consumer) describes, so the unacknowledged message can come back in a continued session instead of being lost silently. A failed delivery that holds back no acknowledgement (QoS 0, AckMode.ON_RECEIVE, or MANUAL after ack()) has nothing to protect, so it is skipped as SKIP skips it. The default.
    • SKIP

      public static final FailurePolicy SKIP
      Skips every failed delivery: a QoS 1 or 2 delivery is acknowledged without processing, and a QoS 0 delivery is dropped. The subscription and the connection continue, and a message that matched other subscriptions still reaches them. Use it when the handler's failures are deterministic, so a redelivery would fail again.
  • Method Details

    • values

      public static FailurePolicy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static FailurePolicy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null