From: Kai Moritz Date: Sun, 18 Feb 2024 20:46:56 +0000 (+0100) Subject: WIP:callbacks - chat-home X-Git-Tag: rebase--2024-02-19--08-16 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=d5cd41aac014f3b0ea3e5f6a4c20f0ec204bde03;p=demos%2Fkafka%2Fchat WIP:callbacks - chat-home --- 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 9dd76250..11f91f4e 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 @@ -17,27 +17,39 @@ public interface StorageStrategy Logger log = LoggerFactory.getLogger(StorageStrategy.class.getCanonicalName()); default void write(ChatHomeService chatHomeService) + { + write( + chatHomeService, + this::logSuccessChatHomeService, + this::logFailureChatHomeService); + } + + default void write( + ChatHomeService chatHomeService, + ChatHomeServiceWrittenSuccessCallback successCallback, + ChatHomeServiceWrittenFailureCallback failureCallback) { writeChatRoomInfo( chatHomeService .getChatRoomInfo() + .doOnComplete(() -> successCallback.accept(chatHomeService)) + .doOnError(throwable -> failureCallback.accept(chatHomeService, throwable)) .doOnNext(chatRoomInfo -> writeChatRoomData( chatRoomInfo.getId(), chatHomeService .getChatRoomData(chatRoomInfo.getId()) .flatMapMany(chatRoomData -> chatRoomData.getMessages()), - this::logSuccess, - this::logFailure))); + this::logSuccessChatRoom, + this::logFailureChatRoom))); } - void writeChatRoomInfo(Flux chatRoomInfoFlux); Flux readChatRoomInfo(); default void writeChatRoomData( UUID chatRoomId, Flux messageFlux, - SuccessCallback successCallback, - FailureCallback failureCallback) + ChatRoomWrittenSuccessCallback successCallback, + ChatRoomWrittenFailureCallback failureCallback) { writeChatRoomData( chatRoomId, @@ -48,15 +60,28 @@ public interface StorageStrategy void writeChatRoomData(UUID chatRoomId, Flux messageFlux); Flux readChatRoomData(UUID chatRoomId); - interface SuccessCallback extends Consumer {} - interface FailureCallback extends BiConsumer {} + interface ChatHomeServiceWrittenSuccessCallback extends Consumer {} + interface ChatHomeServiceWrittenFailureCallback extends BiConsumer {} + + default void logSuccessChatHomeService(ChatHomeService chatHomeService) + { + log.info("Successfully stored chat-home {}", chatHomeService); + } + + default void logFailureChatHomeService(ChatHomeService chatHomeService, Throwable throwable) + { + log.error("Could not store chat-home {}: {}", chatHomeService, throwable); + } + + interface ChatRoomWrittenSuccessCallback extends Consumer {} + interface ChatRoomWrittenFailureCallback extends BiConsumer {} - default void logSuccess(UUID chatRoomId) + default void logSuccessChatRoom(UUID chatRoomId) { log.info("Successfully stored chat-room {}", chatRoomId); } - default void logFailure(UUID chatRoomId, Throwable throwable) + default void logFailureChatRoom(UUID chatRoomId, Throwable throwable) { log.error("Could not store chat-room {}: {}", chatRoomId, throwable); }