fix: `Chatroom`s must not share an instance of `PersistanceStrategy`
authorKai Moritz <kai@juplo.de>
Sat, 7 Jan 2023 20:00:50 +0000 (21:00 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 15 Jan 2023 18:35:59 +0000 (19:35 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java

index 6387c6e..aea5f8e 100644 (file)
@@ -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
index 231eb37..415a71f 100644 (file)
@@ -11,12 +11,11 @@ import java.util.UUID;
 @RequiredArgsConstructor
 public class InMemoryChatroomFactory implements ChatroomFactory<InMemoryPersistenceStrategy>
 {
-  private final PersistenceStrategy persistenceStrategy;
-
-
   @Override
   public Chatroom createChatroom(UUID id, String name)
   {
+    InMemoryPersistenceStrategy persistenceStrategy =
+        new InMemoryPersistenceStrategy(new LinkedHashMap<>());
     return new Chatroom(id, name, persistenceStrategy);
   }