From bf4bc3328ce12653fa90f1f5c26c8ff84946200e Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 29 Nov 2024 16:12:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20getOrCreateDuplicatedContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quarkus/core/TelegramPollingBot.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java index c1f4a5f..77a800d 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/TelegramPollingBot.java @@ -3,8 +3,11 @@ package dev.struchkov.godfather.telegram.quarkus.core; import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig; import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor; import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot; +import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.infrastructure.Infrastructure; import io.vertx.core.Vertx; +import io.vertx.core.impl.ContextInternal; +import io.vertx.mutiny.core.Context; import lombok.SneakyThrows; import org.jetbrains.annotations.NotNull; import org.telegram.telegrambots.bots.DefaultBotOptions; @@ -13,7 +16,6 @@ import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.bots.AbsSender; import java.lang.reflect.Field; -import java.util.concurrent.Executors; /** * TODO: Добавить описание класса. @@ -53,11 +55,22 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr private void handleUpdate(Update update) { if (update != null && eventDistributor != null) { - eventDistributor.processing(update) + Uni.createFrom().voidItem() + .emitOn(command -> Context.newInstance(getOrCreateDuplicatedContext(vertx)).runOnContext(command)) + .replaceWith(() -> eventDistributor.processing(update)) .subscribe().asCompletionStage(); } } + public static io.vertx.core.Context getOrCreateDuplicatedContext(Vertx vertx) { + io.vertx.core.Context context = vertx.getOrCreateContext(); + if (((ContextInternal) context).isDuplicate()) { + return context; + } else { + return ((ContextInternal) context).duplicate(); + } + } + @Override public String getBotUsername() { return telegramBotConfig.getUsername();