refactor: Refined return-type of `StorageStrategy#write`
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 10:14:43 +0000 (11:14 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 10:14:43 +0000 (11:14 +0100)
src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java
src/main/java/de/juplo/kafka/chat/backend/storage/nostorage/NoStorageStorageStrategy.java

index 487a37f..94b2bb4 100644 (file)
@@ -15,7 +15,7 @@ public interface StorageStrategy
 {
   Logger log = LoggerFactory.getLogger(StorageStrategy.class.getCanonicalName());
 
-  default Flux<ChatRoomInfo> write(ChatHomeService chatHomeService)
+  default Mono<Void> 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));
   }
 
index 5902742..46189b6 100644 (file)
@@ -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<ChatRoomInfo> write(ChatHomeService chatHomeService)
+  public Mono<Void> write(ChatHomeService chatHomeService)
   {
-    return Flux
-        .<ChatRoomInfo>empty()
-        .doOnComplete(() -> log.info("Storage is disabled: Not storing {}", chatHomeService));
+    return Mono
+        .<Void>empty()
+        .doOnSuccess(empty -> log.info("Storage is disabled: Not storing {}", chatHomeService));
 
   }