From: Kai Moritz Date: Sat, 7 Jan 2023 20:00:50 +0000 (+0100) Subject: fix: `Chatroom`s must not share an instance of `PersistanceStrategy` X-Git-Tag: TEST~55 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=f0bd82164eba22ba0c30d6206e23aed012faa5b7;p=demos%2Fkafka%2Fchat fix: `Chatroom`s must not share an instance of `PersistanceStrategy` --- 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 6387c6ef..aea5f8ec 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -3,9 +3,7 @@ package de.juplo.kafka.chat.backend; import de.juplo.kafka.chat.backend.domain.ChatHome; import com.fasterxml.jackson.databind.ObjectMapper; import de.juplo.kafka.chat.backend.domain.ChatroomFactory; -import de.juplo.kafka.chat.backend.domain.Message; import de.juplo.kafka.chat.backend.persistence.InMemoryChatroomFactory; -import de.juplo.kafka.chat.backend.persistence.InMemoryPersistenceStrategy; import de.juplo.kafka.chat.backend.persistence.LocalJsonFilesStorageStrategy; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -14,7 +12,6 @@ import org.springframework.context.annotation.Configuration; import java.nio.file.Paths; import java.time.Clock; -import java.util.LinkedHashMap; @Configuration @@ -44,15 +41,9 @@ public class ChatBackendConfiguration } @Bean - ChatroomFactory chatroomFactory(InMemoryPersistenceStrategy persistenceStrategy) + ChatroomFactory chatroomFactory() { - return new InMemoryChatroomFactory(persistenceStrategy); - } - - @Bean - InMemoryPersistenceStrategy persistenceStrategy() - { - return new InMemoryPersistenceStrategy(new LinkedHashMap<>()); + return new InMemoryChatroomFactory(); } @Bean diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java index 231eb37c..415a71f5 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java @@ -11,12 +11,11 @@ import java.util.UUID; @RequiredArgsConstructor public class InMemoryChatroomFactory implements ChatroomFactory { - private final PersistenceStrategy persistenceStrategy; - - @Override public Chatroom createChatroom(UUID id, String name) { + InMemoryPersistenceStrategy persistenceStrategy = + new InMemoryPersistenceStrategy(new LinkedHashMap<>()); return new Chatroom(id, name, persistenceStrategy); }