From a59751d3069ad00427f92b6e29879c8f30530280 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 20 Feb 2024 11:14:43 +0100 Subject: [PATCH] refactor: Refined return-type of `StorageStrategy#write` --- .../chat/backend/implementation/StorageStrategy.java | 5 +++-- .../storage/nostorage/NoStorageStorageStrategy.java | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java index 487a37fe..94b2bb45 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java @@ -15,7 +15,7 @@ public interface StorageStrategy { Logger log = LoggerFactory.getLogger(StorageStrategy.class.getCanonicalName()); - default Flux write(ChatHomeService chatHomeService) + default Mono write(ChatHomeService chatHomeService) { return writeChatRoomInfo( chatHomeService @@ -30,7 +30,8 @@ public interface StorageStrategy .doOnSuccess(emittedChatRoomInfo -> log.info("Stored {}", chatRoomInfo)) .doOnError(throwable -> log.error("Could not store {}: {}", chatRoomInfo, throwable))) ) - .doOnComplete(() -> log.info("Stored {}", chatHomeService)) + .then() + .doOnSuccess(empty -> log.info("Stored {}", chatHomeService)) .doOnError(throwable -> log.error("Could not store {}: {}", chatHomeService, throwable)); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java index 59027424..46189b6c 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java @@ -6,6 +6,7 @@ import de.juplo.kafka.chat.backend.domain.Message; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; import java.util.UUID; @@ -13,11 +14,11 @@ import java.util.UUID; @Slf4j public class NoStorageStorageStrategy implements StorageStrategy { - public Flux write(ChatHomeService chatHomeService) + public Mono write(ChatHomeService chatHomeService) { - return Flux - .empty() - .doOnComplete(() -> log.info("Storage is disabled: Not storing {}", chatHomeService)); + return Mono + .empty() + .doOnSuccess(empty -> log.info("Storage is disabled: Not storing {}", chatHomeService)); } -- 2.20.1