From 682d9313dc86e089979c11392f6c4bcf44608208 Mon Sep 17 00:00:00 2001 From: "adel.kalimullin" Date: Tue, 13 May 2025 14:59:59 +0300 Subject: [PATCH] SUPPORT-9165: add wait for accumulator --- .../service/SessionResponseHolder.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/src/main/java/ervu_business_metrics/service/SessionResponseHolder.java b/backend/src/main/java/ervu_business_metrics/service/SessionResponseHolder.java index a323a6d..c43f2e2 100644 --- a/backend/src/main/java/ervu_business_metrics/service/SessionResponseHolder.java +++ b/backend/src/main/java/ervu_business_metrics/service/SessionResponseHolder.java @@ -12,6 +12,8 @@ import java.util.concurrent.atomic.AtomicInteger; import ervu_business_metrics.config.KafkaEnabledCondition; import ervu_business_metrics.model.sso.UserSessionInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; @@ -21,6 +23,7 @@ import org.springframework.stereotype.Component; @Component @Conditional(KafkaEnabledCondition.class) public class SessionResponseHolder { + private final Logger LOGGER = LoggerFactory.getLogger(SessionResponseHolder.class); private final Map sessionsMap = new ConcurrentHashMap<>(); public void initIfAbsent(String requestKey, int totalExpected) { @@ -37,9 +40,21 @@ public class SessionResponseHolder { public List awaitSessions(String requestKey, long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException { SessionAccumulator acc = sessionsMap.get(requestKey); + + long startTime = System.nanoTime(); + LOGGER.info("Начало ожидания сессий для requestKey = {}", requestKey); + + while (acc == null && (System.nanoTime() - startTime) < unit.toNanos(timeout)) { + LOGGER.debug("Аккумулятор для requestKey = {} еще не найден, повторная проверка", requestKey); + TimeUnit.MILLISECONDS.sleep(50); + acc = sessionsMap.get(requestKey); + } + if (acc == null) { + LOGGER.error("Аккумулятор для requestKey: {} не был инициализирован за время ожидания.", requestKey); return List.of(); } + return acc.getFuture().get(timeout, unit); }