@PreDestroy
public void onExit()
{
- storageStrategy.writeChatrooms(chatHome.getChatRooms());
+ storageStrategy.write(chatHome.getChatRooms());
}
public static void main(String[] args)
ChatBackendProperties properties)
{
return new InMemoryChatHomeService(
- storageStrategy.readChatrooms(),
+ storageStrategy.read(),
clock,
properties.getChatroomBufferSize());
}
@PostMapping("/store")
public void store()
{
- storageStrategy.writeChatrooms(chatHome.getChatRooms());
+ storageStrategy.write(chatHome.getChatRooms());
}
}
package de.juplo.kafka.chat.backend.persistence;
-import de.juplo.kafka.chat.backend.api.ChatRoomTo;
import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import de.juplo.kafka.chat.backend.domain.Message;
import reactor.core.publisher.Flux;
public interface StorageStrategy
{
- void writeChatrooms(Flux<ChatRoom> chatroomFlux);
- Flux<ChatRoom> readChatrooms();
- void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux);
- Flux<Message> readMessages(ChatRoomTo chatroomTo);
+ void write(Flux<ChatRoom> chatroomFlux);
+ Flux<ChatRoom> read();
}
@Override
- public void writeChatrooms(Flux<ChatRoom> chatroomFlux)
+ public void write(Flux<ChatRoom> chatroomFlux)
{
Path path = chatroomsPath();
log.info("Writing chatrooms to {}", path);
}
@Override
- public Flux<ChatRoom> readChatrooms()
+ public Flux<ChatRoom> read()
{
JavaType type = mapper.getTypeFactory().constructType(ChatRoomTo.class);
return Flux
bufferSize));
}
- @Override
public void writeMessages(ChatRoomTo chatroomTo, Flux<Message> messageFlux)
{
Path path = chatroomPath(chatroomTo);
}
}
- @Override
public Flux<Message> readMessages(ChatRoomTo chatroomTo)
{
JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
protected void stop()
{
- getStorageStrategy().writeChatrooms(chathome.getChatRooms());
+ getStorageStrategy().write(chathome.getChatRooms());
}
@Test
@Override
protected Supplier<ChatHomeService> chatHomeServiceSupplier()
{
- return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
+ return () -> new InMemoryChatHomeService(getStorageStrategy().read(), clock, 8);
}
@BeforeEach