refactore: Renamed `PersistenceStrategy` to `ChatroomService` -- Rename
authorKai Moritz <kai@juplo.de>
Sun, 8 Jan 2023 09:10:46 +0000 (10:10 +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/domain/Chatroom.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomFactory.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomService.java
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomService.java
src/main/java/de/juplo/kafka/chat/backend/persistence/LocalJsonFilesStorageStrategy.java

index 60f7274..2261e02 100644 (file)
@@ -17,19 +17,19 @@ public class Chatroom
   private final UUID id;
   @Getter
   private final String name;
-  private final PersistenceStrategy persistence;
+  private final ChatroomService chatroomService;
   private final int bufferSize;
   private Sinks.Many<Message> sink;
 
   public Chatroom(
       UUID id,
       String name,
-      PersistenceStrategy persistence,
+      ChatroomService chatroomService,
       int bufferSize)
   {
     this.id = id;
     this.name = name;
-    this.persistence = persistence;
+    this.chatroomService = chatroomService;
     this.bufferSize = bufferSize;
     this.sink = createSink();
   }
@@ -41,7 +41,7 @@ public class Chatroom
       String user,
       String text)
   {
-    return persistence
+    return chatroomService
         .persistMessage(Message.MessageKey.of(user, id), timestamp, text)
         .doOnNext(message ->
         {
@@ -56,7 +56,8 @@ public class Chatroom
 
   public Mono<Message> getMessage(String username, Long messageId)
   {
-    return persistence.getMessage(Message.MessageKey.of(username, messageId));
+    Message.MessageKey key = Message.MessageKey.of(username, messageId);
+    return chatroomService.getMessage(key);
   }
 
   synchronized public Flux<Message> listen()
@@ -73,7 +74,7 @@ public class Chatroom
 
   public Flux<Message> getMessages(long first, long last)
   {
-    return persistence.getMessages(first, last);
+    return chatroomService.getMessages(first, last);
   }
 
   private Sinks.Many<Message> createSink()
index 6e77095..e1236b9 100644 (file)
@@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend.domain;
 import java.util.UUID;
 
 
-public interface ChatroomFactory<Strategy extends PersistenceStrategy>
+public interface ChatroomFactory<T extends ChatroomService>
 {
   Chatroom createChatroom(UUID id, String name);
 }
index d3a8364..1e7e8c7 100644 (file)
@@ -6,7 +6,7 @@ import reactor.core.publisher.Mono;
 import java.time.LocalDateTime;
 
 
-public interface PersistenceStrategy
+public interface ChatroomService
 {
   Mono<Message> persistMessage(
       Message.MessageKey key,
index 6e4985e..41ecd4c 100644 (file)
@@ -9,7 +9,7 @@ import java.util.UUID;
 
 
 @RequiredArgsConstructor
-public class InMemoryChatroomFactory implements ChatroomFactory<InMemoryPersistenceStrategy>
+public class InMemoryChatroomFactory implements ChatroomFactory<InMemoryChatroomService>
 {
   private final int bufferSize;
 
@@ -17,16 +17,16 @@ public class InMemoryChatroomFactory implements ChatroomFactory<InMemoryPersiste
   @Override
   public Chatroom createChatroom(UUID id, String name)
   {
-    InMemoryPersistenceStrategy persistenceStrategy =
-        new InMemoryPersistenceStrategy(new LinkedHashMap<>());
-    return new Chatroom(id, name, persistenceStrategy, bufferSize);
+    InMemoryChatroomService chatroomService =
+        new InMemoryChatroomService(new LinkedHashMap<>());
+    return new Chatroom(id, name, chatroomService, bufferSize);
   }
 
   public Chatroom restoreChatroom(
       UUID id,
       String name,
-      InMemoryPersistenceStrategy persistenceStrategy)
+      InMemoryChatroomService chatroomService)
   {
-    return new Chatroom(id, name, persistenceStrategy, bufferSize);
+    return new Chatroom(id, name, chatroomService, bufferSize);
   }
 }
index 4b522a8..e06709f 100644 (file)
@@ -2,7 +2,7 @@ package de.juplo.kafka.chat.backend.persistence;
 
 import de.juplo.kafka.chat.backend.domain.Message;
 import de.juplo.kafka.chat.backend.domain.MessageMutationException;
-import de.juplo.kafka.chat.backend.domain.PersistenceStrategy;
+import de.juplo.kafka.chat.backend.domain.ChatroomService;
 import lombok.extern.slf4j.Slf4j;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -12,19 +12,19 @@ import java.util.LinkedHashMap;
 
 
 @Slf4j
-public class InMemoryPersistenceStrategy implements PersistenceStrategy
+public class InMemoryChatroomService implements ChatroomService
 {
   private final LinkedHashMap<Message.MessageKey, Message> messages;
 
 
-  public InMemoryPersistenceStrategy(LinkedHashMap<Message.MessageKey, Message> messages)
+  public InMemoryChatroomService(LinkedHashMap<Message.MessageKey, Message> messages)
   {
     this.messages = messages;
   }
 
-  public InMemoryPersistenceStrategy(Flux<Message> messageFlux)
+  public InMemoryChatroomService(Flux<Message> messageFlux)
   {
-    log.debug("Creating InMemoryPersistenceStrategy");
+    log.debug("Creating InMemoryChatroomService");
     messages = new LinkedHashMap<>();
     messageFlux.subscribe(message -> persistMessage(message));
   }
index 28008f4..6c61908 100644 (file)
@@ -100,9 +100,12 @@ public class LocalJsonFilesStorageStrategy implements StorageStrategy
         .log()
         .map(chatroomTo ->
         {
-          InMemoryPersistenceStrategy strategy =
-              new InMemoryPersistenceStrategy(readMessages(chatroomTo));
-          return chatroomFactory.restoreChatroom(chatroomTo.getId(), chatroomTo.getName(), strategy);
+          InMemoryChatroomService chatroomService =
+              new InMemoryChatroomService(readMessages(chatroomTo));
+          return chatroomFactory.restoreChatroom(
+              chatroomTo.getId(),
+              chatroomTo.getName(),
+              chatroomService);
         });
   }