refactor: Renamed `ChatRoom` into `ChatRoomData` - Aligned Code
authorKai Moritz <kai@juplo.de>
Sun, 3 Sep 2023 23:44:51 +0000 (01:44 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 3 Sep 2023 23:44:51 +0000 (01:44 +0200)
src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoomData.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java

index 0031bb0..5c49731 100644 (file)
@@ -1,6 +1,5 @@
 package de.juplo.kafka.chat.backend.domain;
 
-import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -19,8 +18,6 @@ public class ChatRoomData
 {
   public final static Pattern VALID_USER = Pattern.compile("^[a-z0-9-]{2,}$");
 
-  @Getter
-  private final UUID id;
   private final ChatRoomService service;
   private final Clock clock;
   private final int bufferSize;
@@ -28,13 +25,11 @@ public class ChatRoomData
 
 
   public ChatRoomData(
-      UUID id,
       ChatRoomService service,
       Clock clock,
       int bufferSize)
   {
-    log.info("Created ChatRoom {id} with buffer-size {}", id, bufferSize);
-    this.id = id;
+    log.info("Created ChatRoom with buffer-size {}", bufferSize);
     this.service = service;
     this.clock = clock;
     this.bufferSize = bufferSize;
index 76080c9..47c223e 100644 (file)
@@ -47,6 +47,7 @@ public class InMemoryServicesConfiguration
   ChatHome kafkalikeShardingChatHome(
       ChatBackendProperties properties,
       StorageStrategy storageStrategy,
+      ChatRoomServiceFactory chatRoomServiceFactory,
       Clock clock)
   {
     int numShards = properties.getInmemory().getNumShards();
@@ -55,7 +56,8 @@ public class InMemoryServicesConfiguration
         .of(properties.getInmemory().getOwnedShards())
         .forEach(shard -> chatHomes[shard] = new SimpleChatHome(
             shard,
-            storageStrategy.readChatRoomData(),
+            storageStrategy,
+            chatRoomServiceFactory,
             clock,
             properties.getChatroomBufferSize()));
     ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
index 961cea2..862c704 100644 (file)
@@ -75,7 +75,6 @@ public class SimpleChatHome implements ChatHome
           chatRoomData.put(
               info.getId(),
               new ChatRoomData(
-                  chatRoomId,
                   chatRoomServiceFactory.create(messageFlux),
                   clock,
                   bufferSize));
@@ -91,7 +90,7 @@ public class SimpleChatHome implements ChatHome
     log.info("Creating ChatRoom with buffer-size {}", bufferSize);
     ChatRoomService service = new InMemoryChatRoomService(Flux.empty());
     ChatRoomInfo chatRoomInfo = new ChatRoomInfo(id, name, shard);
-    ChatRoomData chatRoomData = new ChatRoomData(id, service, clock, bufferSize);
+    ChatRoomData chatRoomData = new ChatRoomData(service, clock, bufferSize);
     this.chatRoomData.put(id, chatRoomData);
     return Mono.just(chatRoomInfo);
   }