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<ChatRoomInfo> chatRoomInfoFlux);
Flux<ChatRoomInfo> readChatRoomInfo();
default void writeChatRoomData(
UUID chatRoomId,
Flux<Message> messageFlux,
- SuccessCallback successCallback,
- FailureCallback failureCallback)
+ ChatRoomWrittenSuccessCallback successCallback,
+ ChatRoomWrittenFailureCallback failureCallback)
{
writeChatRoomData(
chatRoomId,
void writeChatRoomData(UUID chatRoomId, Flux<Message> messageFlux);
Flux<Message> readChatRoomData(UUID chatRoomId);
- interface SuccessCallback extends Consumer<UUID> {}
- interface FailureCallback extends BiConsumer<UUID, Throwable> {}
+ interface ChatHomeServiceWrittenSuccessCallback extends Consumer<ChatHomeService> {}
+ interface ChatHomeServiceWrittenFailureCallback extends BiConsumer<ChatHomeService, Throwable> {}
+
+ 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<UUID> {}
+ interface ChatRoomWrittenFailureCallback extends BiConsumer<UUID, Throwable> {}
- 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);
}