From: Kai Moritz Date: Mon, 9 Jan 2023 21:46:42 +0000 (+0100) Subject: refactor: Refined (simplified) `StorageStrategy` X-Git-Tag: wip-sharding~44 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=fad1a04e738182403490b11575653e3a1130fd48;p=demos%2Fkafka%2Fchat refactor: Refined (simplified) `StorageStrategy` --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java index 80a46c00..c61f8488 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java @@ -32,7 +32,7 @@ public class ChatBackendApplication implements WebFluxConfigurer @PreDestroy public void onExit() { - storageStrategy.writeChatrooms(chatHome.getChatRooms()); + storageStrategy.write(chatHome.getChatRooms()); } public static void main(String[] args) diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java index dcf2d9f3..87965ab9 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -32,7 +32,7 @@ public class ChatBackendConfiguration ChatBackendProperties properties) { return new InMemoryChatHomeService( - storageStrategy.readChatrooms(), + storageStrategy.read(), clock, properties.getChatroomBufferSize()); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java index e7a6f1a5..3b8fc842 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java @@ -124,6 +124,6 @@ public class ChatBackendController @PostMapping("/store") public void store() { - storageStrategy.writeChatrooms(chatHome.getChatRooms()); + storageStrategy.write(chatHome.getChatRooms()); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java index 4355f9fc..bedd0aac 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/StorageStrategy.java @@ -1,15 +1,11 @@ package de.juplo.kafka.chat.backend.persistence; -import de.juplo.kafka.chat.backend.api.ChatRoomTo; import de.juplo.kafka.chat.backend.domain.ChatRoom; -import de.juplo.kafka.chat.backend.domain.Message; import reactor.core.publisher.Flux; public interface StorageStrategy { - void writeChatrooms(Flux chatroomFlux); - Flux readChatrooms(); - void writeMessages(ChatRoomTo chatroomTo, Flux messageFlux); - Flux readMessages(ChatRoomTo chatroomTo); + void write(Flux chatroomFlux); + Flux read(); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java index e6709709..1fd307f5 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageStrategy.java @@ -36,7 +36,7 @@ public class FilesStorageStrategy implements StorageStrategy @Override - public void writeChatrooms(Flux chatroomFlux) + public void write(Flux chatroomFlux) { Path path = chatroomsPath(); log.info("Writing chatrooms to {}", path); @@ -96,7 +96,7 @@ public class FilesStorageStrategy implements StorageStrategy } @Override - public Flux readChatrooms() + public Flux read() { JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class); return Flux @@ -110,7 +110,6 @@ public class FilesStorageStrategy implements StorageStrategy bufferSize)); } - @Override public void writeMessages(ChatRoomTo chatroomTo, Flux messageFlux) { Path path = chatroomPath(chatroomTo); @@ -169,7 +168,6 @@ public class FilesStorageStrategy implements StorageStrategy } } - @Override public Flux readMessages(ChatRoomTo chatroomTo) { JavaType type = mapper.getTypeFactory().constructType(MessageTo.class); diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java index b2cbde2b..549faada 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java @@ -29,7 +29,7 @@ public abstract class AbstractStorageStrategyIT protected void stop() { - getStorageStrategy().writeChatrooms(chathome.getChatRooms()); + getStorageStrategy().write(chathome.getChatRooms()); } @Test diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageStrategyIT.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageStrategyIT.java index f182c82c..93bfc8ff 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageStrategyIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/InMemoryWithFilesStorageStrategyIT.java @@ -52,7 +52,7 @@ public class InMemoryWithFilesStorageStrategyIT extends AbstractStorageStrategyI @Override protected Supplier chatHomeServiceSupplier() { - return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8); + return () -> new InMemoryChatHomeService(getStorageStrategy().read(), clock, 8); } @BeforeEach