}
@Bean
- InMemoryChatHomeService chatHomeService(ChatBackendProperties properties)
+ InMemoryChatHomeService chatHomeService(
+ Clock clock,
+ ChatBackendProperties properties)
{
- return new InMemoryChatHomeService(properties.getChatroomBufferSize());
+ return new InMemoryChatHomeService(clock, properties.getChatroomBufferSize());
}
@Bean
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import java.time.Clock;
-import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
public class ChatBackendController
{
private final ChatHome chatHome;
- private final Clock clock;
private final StorageStrategy storageStrategy;
chatroom
.addMessage(
messageId,
- LocalDateTime.now(clock),
username,
text)
.switchIfEmpty(chatroom.getMessage(username, messageId))
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
+import java.time.Clock;
import java.time.LocalDateTime;
import java.util.*;
private final UUID id;
@Getter
private final String name;
+ private final Clock clock;
private final ChatRoomService service;
private final int bufferSize;
private Sinks.Many<Message> sink;
public ChatRoom(
UUID id,
String name,
+ Clock clock,
ChatRoomService service,
int bufferSize)
{
this.id = id;
this.name = name;
+ this.clock = clock;
this.service = service;
this.bufferSize = bufferSize;
this.sink = createSink();
synchronized public Mono<Message> addMessage(
Long id,
- LocalDateTime timestamp,
String user,
String text)
{
return service
- .persistMessage(Message.MessageKey.of(user, id), timestamp, text)
+ .persistMessage(Message.MessageKey.of(user, id), LocalDateTime.now(clock), text)
.doOnNext(message ->
{
Sinks.EmitResult result = sink.tryEmitNext(message);
import de.juplo.kafka.chat.backend.domain.ChatHomeService;
import lombok.RequiredArgsConstructor;
+import java.time.Clock;
import java.util.LinkedHashMap;
import java.util.UUID;
@RequiredArgsConstructor
public class InMemoryChatHomeService implements ChatHomeService<InMemoryChatRoomService>
{
+ private final Clock clock;
private final int bufferSize;
{
InMemoryChatRoomService service =
new InMemoryChatRoomService(new LinkedHashMap<>());
- return new ChatRoom(id, name, service, bufferSize);
+ return new ChatRoom(id, name, clock, service, bufferSize);
}
public ChatRoom restoreChatroom(
String name,
InMemoryChatRoomService service)
{
- return new ChatRoom(id, name, service, bufferSize);
+ return new ChatRoom(id, name, clock, service, bufferSize);
}
}