import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
private final UUID id;
@Getter
private final String name;
- private final LinkedHashMap<MessageKey, Message> messages = new LinkedHashMap<>();
+ private final LinkedHashMap<Message.MessageKey, Message> messages = new LinkedHashMap<>();
private final Sinks.Many<Message> sink = Sinks.many().multicast().onBackpressureBuffer();
synchronized public Mono<Message> addMessage(
String user,
String text)
{
- Message message = new Message(id, (long)messages.size(), timestamp, user, text);
+ Message.MessageKey key = Message.MessageKey.of(user, id);
+ Message message = new Message(key, (long)messages.size(), timestamp, text);
- MessageKey key = new MessageKey(user, id);
Message existing = messages.get(key);
if (existing != null)
{
{
return Mono.fromSupplier(() ->
{
- MessageKey key = MessageKey.of(username, messageId);
+ Message.MessageKey key = Message.MessageKey.of(username, messageId);
return messages.get(key);
});
}
return serial >= first && serial <= last;
}));
}
-
-
- @Value(staticConstructor = "of")
- static class MessageKey
- {
- String username;
- Long messageId;
- }
}
package de.juplo.kafka.chat.backend.domain;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
+import lombok.*;
import java.time.LocalDateTime;
@ToString
public class Message
{
- private final Long id;
+ private final MessageKey key;
private final Long serialNumber;
private final LocalDateTime timestamp;
- private final String username;
private final String messageText;
+
+ public Long getId()
+ {
+ return key.messageId;
+ }
+
+ public String getUsername()
+ {
+ return key.username;
+ }
+
+
+ @Value(staticConstructor = "of")
+ public static class MessageKey
+ {
+ String username;
+ Long messageId;
+ }
}