diff --git a/src/main/java/com/aws/greengrass/mqttclient/spool/CloudMessageSpool.java b/src/main/java/com/aws/greengrass/mqttclient/spool/CloudMessageSpool.java index 411515c103..925a6a32a6 100644 --- a/src/main/java/com/aws/greengrass/mqttclient/spool/CloudMessageSpool.java +++ b/src/main/java/com/aws/greengrass/mqttclient/spool/CloudMessageSpool.java @@ -6,6 +6,7 @@ package com.aws.greengrass.mqttclient.spool; import java.io.IOException; +import java.util.List; public interface CloudMessageSpool { @@ -17,5 +18,34 @@ public interface CloudMessageSpool { Iterable getAllMessageIds() throws IOException; + /** + * Get the maximum message ID currently stored in the spool. + * This is used to set the next ID for new messages without iterating all messages. + * + *

Default returns -1 (not supported) for backward compatibility with older plugin versions. + * When -1 is returned, the nucleus falls back to iterating all message IDs.

+ * + * @return the maximum message ID, or -1 if the spool is empty or not supported + * @throws IOException if an I/O error occurs + */ + default long getMaxMessageId() throws IOException { + return -1; + } + + /** + * Get all message IDs with their payload sizes, ordered by ID ascending. + * Returns a list of [messageId, payloadSizeInBytes] pairs without reading full payloads. + * This enables fast capacity tracking during startup without per-message I/O. + * + *

Default returns null (not supported) for backward compatibility with older plugin versions. + * When null is returned, the nucleus falls back to reading each message individually.

+ * + * @return ordered list of (id, size) pairs, or null if not supported + * @throws IOException if an I/O error occurs + */ + default List getAllMessageIdsWithSizes() throws IOException { + return null; + } + void initializeSpooler() throws IOException; }