KApolinario1120 commented on code in PR #17973: URL: https://github.com/apache/kafka/pull/17973#discussion_r1874204920
########## streams/src/main/java/org/apache/kafka/streams/AutoOffsetReset.java: ########## @@ -0,0 +1,76 @@ +package org.apache.kafka.streams; + +import java.time.Duration; +import java.util.Optional; + +/** + * Sets the {@code auto.offset.reset} configuration when + * {@link #addSource(AutoOffsetReset, String, String...) adding a source processor} or when creating {@link KStream} + * or {@link KTable} via {@link StreamsBuilder}. + */ +public class AutoOffsetReset { + protected final Optional<Long> duration; + + protected AutoOffsetReset(Optional<Long> duration) { + this.duration = duration; + } + + /** + * Creates an AutoOffsetReset instance representing "latest". + * + * @return an AutoOffsetReset instance for the "latest" offset. + */ + public static AutoOffsetReset latest() { + return new AutoOffsetReset(Optional.empty()); + } + + /** + * Creates an AutoOffsetReset instance representing "earliest". + * + * @return an AutoOffsetReset instance for the "earliest" offset. + */ + public static AutoOffsetReset earliest() { + return new AutoOffsetReset(Optional.of(0L)); + } + + /** + * Creates an AutoOffsetReset instance with a custom duration. + * + * @param duration the duration to use for the offset reset; must be non-negative. + * @return an AutoOffsetReset instance with the specified duration. + * @throws IllegalArgumentException if the duration is negative. + */ + public static AutoOffsetReset duration(Duration duration) { + if (duration.isNegative()) { + throw new IllegalArgumentException("Duration cannot be negative"); + } + return new AutoOffsetReset(Optional.of(duration.toMillis())); + } + + /** + * Retrieves the offset reset duration if specified. + * + * @return an Optional containing the duration in milliseconds, or empty if "latest". + */ + public Optional<Long> getDuration() { Review Comment: I see, we may have a need to do this internally but a user never would, and giving them the ability to call it would not make their lives any easier but just adds bloat. I appreciate the explanation, I am beginning to see the relationship between the 'internals' and the user-facing components and will keep this in mind in the future. I have some things to learn yet about the API we are exposing to the end-user -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org