From 6665467f76198e20f4852f3eb61d53ea9d07bfca Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 11 Jan 2023 18:38:39 +0100 Subject: [PATCH] feat: configuration for service & storage lives in the according packages --- .../backend/ChatBackendConfiguration.java | 32 ------------------- .../InMemoryServicesConfiguration.java | 25 +++++++++++++++ .../files/FilesStorageConfiguration.java | 30 +++++++++++++++++ 3 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java create mode 100644 src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java 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 0cca42d3..ac77748e 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -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 index 00000000..20a1b5f6 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java @@ -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 index 00000000..32bedb8f --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/storage/files/FilesStorageConfiguration.java @@ -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); + } +} -- 2.20.1