Skip to content

Commit

Permalink
Add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dimabarbul committed Sep 24, 2023
1 parent 2eca05b commit b9212f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* The maximum seconds is {@value MAX_INTERVAL_SECONDS}.
*/
@Immutable
public class MessageExpiryInterval {
public final class MessageExpiryInterval {

public static final long MIN_INTERVAL_SECONDS = 1L;

Expand All @@ -36,6 +36,14 @@ private MessageExpiryInterval(@Nullable final Long seconds) {
this.seconds = seconds;
}

/**
* Returns an instance of {@code MessageExpiryInterval} for the specified interval.
*
* @param seconds the message expiry interval duration in seconds. The value must be between
* {@value #MIN_INTERVAL_SECONDS} and {@value #MAX_INTERVAL_SECONDS} (both inclusive).
* @return the MessageExpiryInterval for interval of {@code seconds}.
* @throws IllegalMessageExpiryIntervalSecondsException if the seconds is less than {@value MIN_INTERVAL_SECONDS} or greater than {@value #MAX_INTERVAL_SECONDS}.
*/
public static MessageExpiryInterval of(final long seconds)
throws IllegalMessageExpiryIntervalSecondsException {
if (seconds < MIN_INTERVAL_SECONDS || seconds > MAX_INTERVAL_SECONDS) {
Expand All @@ -50,10 +58,20 @@ public static MessageExpiryInterval of(final long seconds)
return new MessageExpiryInterval(seconds);
}

/**
* Returns an instance of the empty {@code MessageExpiryInterval}.
*
* @return the empty message expiry interval.
*/
public static MessageExpiryInterval empty() {
return new MessageExpiryInterval(null);
}

/**
* Returns message expiry interval seconds.
*
* @return optional count of seconds in the interval.
*/
public OptionalLong getAsOptionalLong() {
return seconds != null ?
OptionalLong.of(seconds) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public static Builder builder(final MqttTopic mqttTopic, final MqttQos mqttQos)
*/
public abstract boolean isRetain();

/**
* Returns expiry interval for this Publish message.
*
* @return message expiry interval.
*/
public abstract MessageExpiryInterval getMessageExpiryInterval();

public abstract Optional<ByteBuffer> getCorrelationData();
Expand Down Expand Up @@ -238,6 +243,12 @@ public Builder retain(final boolean retain) {
return this;
}

/**
* Sets message expiry interval.
*
* @param messageExpiryInterval expiry interval of the Publish
* @return this Builder instance for method chaining.
*/
public Builder messageExpiryInterval(final MessageExpiryInterval messageExpiryInterval) {
this.messageExpiryInterval = messageExpiryInterval;
return this;
Expand Down

0 comments on commit b9212f8

Please sign in to comment.