feat: Plaintext와 Ssl에서의 전송 시간 메트릭 측정에 사용되는 ConsumerStats 클래스

This commit is contained in:
이상진 2025-06-27 14:29:46 +09:00
parent 3e9e8ebe2a
commit ce20f85c04

View File

@ -0,0 +1,30 @@
package com.sangdol.consumer.infrastructure.kafka.consumer;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class ConsumerStats {
private final int workerThreads;
private final Map<String, Long> threadElapsedTime;
public ConsumerStats(int workerThreads) {
this.workerThreads = workerThreads;
this.threadElapsedTime = new ConcurrentHashMap<>();
}
public void update(long elapsedTime) {
threadElapsedTime.put(Thread.currentThread().getName(), elapsedTime);
}
public long averageTime() {
if (threadElapsedTime.size() != workerThreads) {
return 0L;
}
return threadElapsedTime.values().stream()
.collect(Collectors.averagingLong(Long::longValue))
.longValue();
}
}