From: Kai Moritz Date: Sun, 8 Jan 2023 09:10:46 +0000 (+0100) Subject: refactore: Renamed `PersistenceStrategy` to `ChatroomService` -- Rename X-Git-Tag: TEST~44 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2298c1b58366271467ceba8b0667c3c9ee521ba3;p=demos%2Fkafka%2Fchat refactore: Renamed `PersistenceStrategy` to `ChatroomService` -- Rename --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java index 60f7274e..2261e022 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/Chatroom.java @@ -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 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 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 listen() @@ -73,7 +74,7 @@ public class Chatroom public Flux getMessages(long first, long last) { - return persistence.getMessages(first, last); + return chatroomService.getMessages(first, last); } private Sinks.Many createSink() diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomFactory.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomFactory.java index 6e770958..e1236b9a 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomFactory.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomFactory.java @@ -3,7 +3,7 @@ package de.juplo.kafka.chat.backend.domain; import java.util.UUID; -public interface ChatroomFactory +public interface ChatroomFactory { Chatroom createChatroom(UUID id, String name); } diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomService.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomService.java index d3a8364d..1e7e8c72 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatroomService.java @@ -6,7 +6,7 @@ import reactor.core.publisher.Mono; import java.time.LocalDateTime; -public interface PersistenceStrategy +public interface ChatroomService { Mono persistMessage( Message.MessageKey key, diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java index 6e4985ed..41ecd4cf 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java @@ -9,7 +9,7 @@ import java.util.UUID; @RequiredArgsConstructor -public class InMemoryChatroomFactory implements ChatroomFactory +public class InMemoryChatroomFactory implements ChatroomFactory { private final int bufferSize; @@ -17,16 +17,16 @@ public class InMemoryChatroomFactory implements ChatroomFactory()); - 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); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomService.java index 4b522a82..e06709ff 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomService.java @@ -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 messages; - public InMemoryPersistenceStrategy(LinkedHashMap messages) + public InMemoryChatroomService(LinkedHashMap messages) { this.messages = messages; } - public InMemoryPersistenceStrategy(Flux messageFlux) + public InMemoryChatroomService(Flux messageFlux) { - log.debug("Creating InMemoryPersistenceStrategy"); + log.debug("Creating InMemoryChatroomService"); messages = new LinkedHashMap<>(); messageFlux.subscribe(message -> persistMessage(message)); } 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 28008f46..6c619087 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 @@ -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); }); }