feat: configuration for service & storage lives in the according packages
authorKai Moritz <kai@juplo.de>
Wed, 11 Jan 2023 17:38:39 +0000 (18:38 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 25 Jan 2023 20:59:37 +0000 (21:59 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java [new file with mode: 0644]
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java [new file with mode: 0644]

index 0cca42d..ac77748 100644 (file)
@@ -1,18 +1,12 @@
 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.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.storage.files.FilesStorageStrategy;
-import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
-import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
 
-import java.nio.file.Paths;
 import java.time.Clock;
 
 
@@ -27,32 +21,6 @@ public class ChatBackendConfiguration
     return new ChatHome(chatHomeService);
   }
 
-  @Bean
-  InMemoryChatHomeService chatHomeService(
-      StorageStrategy storageStrategy,
-      Clock clock,
-      ChatBackendProperties properties)
-  {
-    return new InMemoryChatHomeService(
-        storageStrategy.read(),
-        clock,
-        properties.getChatroomBufferSize());
-  }
-
-  @Bean
-  public StorageStrategy storageStrategy(
-      ChatBackendProperties properties,
-      Clock clock,
-      ObjectMapper mapper)
-  {
-    return new FilesStorageStrategy(
-        Paths.get(properties.getStorageDirectory()),
-        clock,
-        properties.getChatroomBufferSize(),
-        messageFlux -> new InMemoryChatRoomService(messageFlux),
-        mapper);
-  }
-
   @Bean
   public Clock clock()
   {
diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java
new file mode 100644 (file)
index 0000000..20a1b5f
--- /dev/null
@@ -0,0 +1,25 @@
+package de.juplo.kafka.chat.backend.persistence.inmemory;
+
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Clock;
+
+
+@Configuration
+public class InMemoryServicesConfiguration
+{
+  @Bean
+  InMemoryChatHomeService chatHomeService(
+      StorageStrategy storageStrategy,
+      Clock clock,
+      ChatBackendProperties properties)
+  {
+    return new InMemoryChatHomeService(
+        storageStrategy.read(),
+        clock,
+        properties.getChatroomBufferSize());
+  }
+}
diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java
new file mode 100644 (file)
index 0000000..32bedb8
--- /dev/null
@@ -0,0 +1,30 @@
+package de.juplo.kafka.chat.backend.persistence.storage.files;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.nio.file.Paths;
+import java.time.Clock;
+
+
+@Configuration
+public class FilesStorageConfiguration
+{
+  @Bean
+  public StorageStrategy storageStrategy(
+      ChatBackendProperties properties,
+      Clock clock,
+      ObjectMapper mapper)
+  {
+    return new FilesStorageStrategy(
+        Paths.get(properties.getStorageDirectory()),
+        clock,
+        properties.getChatroomBufferSize(),
+        messageFlux -> new InMemoryChatRoomService(messageFlux),
+        mapper);
+  }
+}