refactore: Renamed `ChatroomFactory` to `ChatHomeService` -- Rename
authorKai Moritz <kai@juplo.de>
Sun, 8 Jan 2023 09:17:49 +0000 (10:17 +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/domain/ChatHome.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatHomeService.java
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatHomeService.java
src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java

index b9d1d29..1b56829 100644 (file)
@@ -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
index ed4d8c7..773cd4c 100644 (file)
@@ -11,19 +11,19 @@ import java.util.stream.Stream;
 public class ChatHome
 {
   private final Map<UUID, Chatroom> chatrooms;
-  private final ChatroomFactory factory;
+  private final ChatHomeService service;
 
-  public ChatHome(ChatroomFactory factory, Flux<Chatroom> chatroomFlux)
+  public ChatHome(ChatHomeService service, Flux<Chatroom> 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;
   }
index e1236b9..987839c 100644 (file)
@@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend.domain;
 import java.util.UUID;
 
 
-public interface ChatroomFactory<T extends ChatroomService>
+public interface ChatHomeService<T extends ChatroomService>
 {
   Chatroom createChatroom(UUID id, String name);
 }
index 41ecd4c..5c7c4b9 100644 (file)
@@ -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<InMemoryChatroomService>
+public class InMemoryChatHomeService implements ChatHomeService<InMemoryChatroomService>
 {
   private final int bufferSize;
 
index 6c61908..d2092b2 100644 (file)
@@ -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);