import java.util.UUID;
-public interface ChatHomeService<T extends ChatroomService>
+public interface ChatHomeService<T extends ChatRoomService>
{
ChatRoom createChatroom(UUID id, String name);
}
private final UUID id;
@Getter
private final String name;
- private final ChatroomService chatroomService;
+ private final ChatRoomService service;
private final int bufferSize;
private Sinks.Many<Message> sink;
public ChatRoom(
UUID id,
String name,
- ChatroomService chatroomService,
+ ChatRoomService service,
int bufferSize)
{
this.id = id;
this.name = name;
- this.chatroomService = chatroomService;
+ this.service = service;
this.bufferSize = bufferSize;
this.sink = createSink();
}
String user,
String text)
{
- return chatroomService
+ return service
.persistMessage(Message.MessageKey.of(user, id), timestamp, text)
.doOnNext(message ->
{
public Mono<Message> getMessage(String username, Long messageId)
{
Message.MessageKey key = Message.MessageKey.of(username, messageId);
- return chatroomService.getMessage(key);
+ return service.getMessage(key);
}
synchronized public Flux<Message> listen()
public Flux<Message> getMessages(long first, long last)
{
- return chatroomService.getMessages(first, last);
+ return service.getMessages(first, last);
}
private Sinks.Many<Message> createSink()
import java.time.LocalDateTime;
-public interface ChatroomService
+public interface ChatRoomService
{
Mono<Message> persistMessage(
Message.MessageKey key,
@RequiredArgsConstructor
-public class InMemoryChatHomeService implements ChatHomeService<InMemoryChatroomService>
+public class InMemoryChatHomeService implements ChatHomeService<InMemoryChatRoomService>
{
private final int bufferSize;
@Override
public ChatRoom createChatroom(UUID id, String name)
{
- InMemoryChatroomService chatroomService =
- new InMemoryChatroomService(new LinkedHashMap<>());
- return new ChatRoom(id, name, chatroomService, bufferSize);
+ InMemoryChatRoomService service =
+ new InMemoryChatRoomService(new LinkedHashMap<>());
+ return new ChatRoom(id, name, service, bufferSize);
}
public ChatRoom restoreChatroom(
UUID id,
String name,
- InMemoryChatroomService chatroomService)
+ InMemoryChatRoomService service)
{
- return new ChatRoom(id, name, chatroomService, bufferSize);
+ return new ChatRoom(id, name, service, bufferSize);
}
}
import de.juplo.kafka.chat.backend.domain.Message;
import de.juplo.kafka.chat.backend.domain.MessageMutationException;
-import de.juplo.kafka.chat.backend.domain.ChatroomService;
+import de.juplo.kafka.chat.backend.domain.ChatRoomService;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@Slf4j
-public class InMemoryChatroomService implements ChatroomService
+public class InMemoryChatRoomService implements ChatRoomService
{
private final LinkedHashMap<Message.MessageKey, Message> messages;
- public InMemoryChatroomService(LinkedHashMap<Message.MessageKey, Message> messages)
+ public InMemoryChatRoomService(LinkedHashMap<Message.MessageKey, Message> messages)
{
this.messages = messages;
}
- public InMemoryChatroomService(Flux<Message> messageFlux)
+ public InMemoryChatRoomService(Flux<Message> messageFlux)
{
log.debug("Creating InMemoryChatroomService");
messages = new LinkedHashMap<>();
.log()
.map(chatRoomTo ->
{
- InMemoryChatroomService chatroomService =
- new InMemoryChatroomService(readMessages(chatRoomTo));
+ InMemoryChatRoomService chatroomService =
+ new InMemoryChatRoomService(readMessages(chatRoomTo));
return service.restoreChatroom(
chatRoomTo.getId(),
chatRoomTo.getName(),