From 49dc4e819b8cedb78e2f99afff73b3d774c700a9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 8 Jan 2023 10:17:49 +0100 Subject: [PATCH] refactore: Renamed `ChatroomFactory` to `ChatHomeService` -- Rename --- .../chat/backend/ChatBackendConfiguration.java | 16 ++++++++-------- .../kafka/chat/backend/domain/ChatHome.java | 10 +++++----- .../chat/backend/domain/ChatHomeService.java | 2 +- .../persistence/InMemoryChatHomeService.java | 4 ++-- .../LocalJsonFilesStorageStrategy.java | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) 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 b9d1d29c..1b568294 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java @@ -2,8 +2,8 @@ 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.persistence.InMemoryChatroomFactory; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; +import de.juplo.kafka.chat.backend.persistence.InMemoryChatHomeService; import de.juplo.kafka.chat.backend.persistence.LocalJsonFilesStorageStrategy; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -20,28 +20,28 @@ public class ChatBackendConfiguration { @Bean public ChatHome chatHome( - ChatroomFactory chatroomFactory, + ChatHomeService chatHomeService, StorageStrategy storageStrategy) { - return new ChatHome(chatroomFactory, storageStrategy.readChatrooms()); + return new ChatHome(chatHomeService, storageStrategy.readChatrooms()); } @Bean public StorageStrategy storageStrategy( ChatBackendProperties properties, ObjectMapper mapper, - InMemoryChatroomFactory chatroomFactory) + InMemoryChatHomeService chatHomeService) { return new LocalJsonFilesStorageStrategy( Paths.get(properties.getDatadir()), mapper, - chatroomFactory); + chatHomeService); } @Bean - InMemoryChatroomFactory chatroomFactory(ChatBackendProperties properties) + InMemoryChatHomeService chatHomeService(ChatBackendProperties properties) { - return new InMemoryChatroomFactory(properties.getChatroomBufferSize()); + return new InMemoryChatHomeService(properties.getChatroomBufferSize()); } @Bean diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java index ed4d8c7f..773cd4cf 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java @@ -11,19 +11,19 @@ import java.util.stream.Stream; public class ChatHome { private final Map chatrooms; - private final ChatroomFactory factory; + private final ChatHomeService service; - public ChatHome(ChatroomFactory factory, Flux chatroomFlux) + public ChatHome(ChatHomeService service, Flux chatroomFlux) { - log.debug("Creating ChatHome with factory: {}", factory); - this.factory = factory; + log.debug("Creating ChatHome with factory: {}", service); + this.service = service; this.chatrooms = new HashMap<>(); chatroomFlux.subscribe(chatroom -> chatrooms.put(chatroom.getId(), chatroom)); } public Chatroom createChatroom(String name) { - Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name); + Chatroom chatroom = service.createChatroom(UUID.randomUUID(), name); chatrooms.put(chatroom.getId(), chatroom); return chatroom; } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java index e1236b9a..987839cc 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java @@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend.domain; import java.util.UUID; -public interface ChatroomFactory +public interface ChatHomeService { Chatroom createChatroom(UUID id, String name); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java index 41ecd4cf..5c7c4b94 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java @@ -1,7 +1,7 @@ package de.juplo.kafka.chat.backend.persistence; import de.juplo.kafka.chat.backend.domain.Chatroom; -import de.juplo.kafka.chat.backend.domain.ChatroomFactory; +import de.juplo.kafka.chat.backend.domain.ChatHomeService; import lombok.RequiredArgsConstructor; import java.util.LinkedHashMap; @@ -9,7 +9,7 @@ import java.util.UUID; @RequiredArgsConstructor -public class InMemoryChatroomFactory implements ChatroomFactory +public class InMemoryChatHomeService implements ChatHomeService { private final int bufferSize; diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java index 6c619087..d2092b2b 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java @@ -28,7 +28,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy private final Path storagePath; private final ObjectMapper mapper; - private final InMemoryChatroomFactory chatroomFactory; + private final InMemoryChatHomeService service; @Override @@ -102,7 +102,7 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy { InMemoryChatroomService chatroomService = new InMemoryChatroomService(readMessages(chatroomTo)); - return chatroomFactory.restoreChatroom( + return service.restoreChatroom( chatroomTo.getId(), chatroomTo.getName(), chatroomService); -- 2.20.1