1 package de.juplo.kafka;
3 import lombok.EqualsAndHashCode;
5 import org.apache.kafka.common.TopicPartition;
7 import java.util.Collection;
8 import java.util.HashMap;
13 @EqualsAndHashCode(of = { "partition" })
14 public class PartitionStatistics
17 private final TopicPartition partition;
18 private final Map<String, KeyCounter> statistics = new HashMap<>();
21 public PartitionStatistics(TopicPartition partition)
23 this.partition = partition;
26 public PartitionStatistics(StatisticsDocument document)
28 this.partition = new TopicPartition(document.topic, document.partition);
36 new KeyCounter(entry.getKey(), entry.getValue()));
41 public KeyCounter addKey(String key)
43 KeyCounter counter = new KeyCounter(key);
46 statistics.put(key, counter);
52 public long increment(String key)
54 KeyCounter counter = statistics.get(key);
58 counter = new KeyCounter(key);
59 statistics.put(key, counter);
62 return counter.increment();
65 public Collection<KeyCounter> getStatistics()
67 return statistics.values();
71 public String toString()
73 return partition.toString();