All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.management.domain.detection.InactiveTopic Maven / Gradle / Ivy

There is a newer version: 2.10.4
Show newest version
package pl.allegro.tech.hermes.management.domain.detection;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

public record InactiveTopic(
    @JsonProperty("topic") String qualifiedTopicName,
    @JsonProperty("lastPublishedTsMs") long lastPublishedMessageTimestampMs,
    @JsonProperty("notificationTsMs") List notificationTimestampsMs,
    @JsonProperty("whitelisted") boolean whitelisted) {

  InactiveTopic notificationSent(Instant timestamp) {
    List newNotificationTimestampsMs = new ArrayList<>(notificationTimestampsMs);
    newNotificationTimestampsMs.add(timestamp.toEpochMilli());
    return new InactiveTopic(
        this.qualifiedTopicName,
        this.lastPublishedMessageTimestampMs,
        newNotificationTimestampsMs,
        this.whitelisted);
  }

  InactiveTopic limitNotificationsHistory(int limit) {
    List newNotificationTimestampsMs =
        notificationTimestampsMs.stream()
            .sorted((a, b) -> Long.compare(b, a))
            .limit(limit)
            .toList();
    return new InactiveTopic(
        this.qualifiedTopicName,
        this.lastPublishedMessageTimestampMs,
        newNotificationTimestampsMs,
        this.whitelisted);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy