Skip to content

Commit

Permalink
Allow to pass -1 to Mqtt5PublishBuilderBase.messageExpiryInterval to …
Browse files Browse the repository at this point in the history
…disable message expiry
  • Loading branch information
SgtSilvio committed Nov 14, 2023
1 parent e71d360 commit a9c3eb7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ public abstract class MqttPublishBuilder<B extends MqttPublishBuilder<B>> {
}

public @NotNull B messageExpiryInterval(final long messageExpiryInterval) {
this.messageExpiryInterval = Checks.unsignedInt(messageExpiryInterval, "Message expiry interval");
if (messageExpiryInterval == -1) {
this.messageExpiryInterval = MqttPublish.NO_MESSAGE_EXPIRY;
} else {
this.messageExpiryInterval = Checks.unsignedInt(messageExpiryInterval, "Message expiry interval");
}
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface Mqtt5ConnectBuilderBase<B extends Mqtt5ConnectBuilderBase<B>> {
/**
* Sets the {@link Mqtt5Connect#getSessionExpiryInterval() session expiry interval} in seconds.
* <p>
* The value must be in the range of an unsigned int: [0, 4_294_967_295].
* The value must be in the range of an unsigned int: [0, 4_294_967_295]. 4_294_967_295 disables session expiry.
*
* @param sessionExpiryInterval the session expiry interval in seconds.
* @return the builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ interface Complete<C extends Mqtt5PublishBuilderBase.Complete<C>> extends Mqtt5P
/**
* Sets the {@link Mqtt5Publish#getMessageExpiryInterval() message expiry interval} in seconds.
* <p>
* The value must be in the range of an unsigned int: [0, 4_294_967_295].
* The value must be in the range of an unsigned int: [0, 4_294_967_295] or -1 to disable message expiry.
*
* @param messageExpiryInterval the message expiry interval in seconds.
* @return the builder.
*/
@CheckReturnValue
@NotNull C messageExpiryInterval(
@Range(from = 0, to = UnsignedDataTypes.UNSIGNED_INT_MAX_VALUE) long messageExpiryInterval);
@Range(from = -1, to = UnsignedDataTypes.UNSIGNED_INT_MAX_VALUE) long messageExpiryInterval);

/**
* Disables the {@link Mqtt5Publish#getMessageExpiryInterval() message expiry}.
Expand Down

0 comments on commit a9c3eb7

Please sign in to comment.