WIP:callbacks
authorKai Moritz <kai@juplo.de>
Sun, 18 Feb 2024 16:33:30 +0000 (17:33 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 18 Feb 2024 16:33:30 +0000 (17:33 +0100)
src/main/java/de/juplo/kafka/chat/backend/implementation/StorageStrategy.java

index 9fb115e..9dd7625 100644 (file)
@@ -26,25 +26,26 @@ public interface StorageStrategy
                     chatRoomInfo.getId(),
                     chatHomeService
                         .getChatRoomData(chatRoomInfo.getId())
-                        .flatMapMany(chatRoomData -> chatRoomData.getMessages()))));
-  }
-
-  default void writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux)
-  {
-    writeChatRoomData(
-        chatRoomId,
-        messageFlux,
-        (id) -> logSuccess(id),
-        (id, throwable) -> logFailure(id, throwable));
+                        .flatMapMany(chatRoomData -> chatRoomData.getMessages()),
+                    this::logSuccess,
+                    this::logFailure)));
   }
 
   void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux);
   Flux<ChatRoomInfo> readChatRoomInfo();
-  void writeChatRoomData(
+  default void writeChatRoomData(
       UUID chatRoomId,
       Flux<Message> messageFlux,
-      SuccessCallback callback,
-      FailureCallback failureCallback);
+      SuccessCallback successCallback,
+      FailureCallback failureCallback)
+  {
+    writeChatRoomData(
+        chatRoomId,
+        messageFlux
+            .doOnComplete(() -> successCallback.accept(chatRoomId))
+            .doOnError(throwable -> failureCallback.accept(chatRoomId, throwable)));
+  }
+  void writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux);
   Flux<Message> readChatRoomData(UUID chatRoomId);
 
   interface SuccessCallback extends Consumer<UUID> {}