import de.juplo.kafka.chat.backend.domain.ChatHome;
import com.fasterxml.jackson.databind.ObjectMapper;
-import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
-import de.juplo.kafka.chat.backend.persistence.InMemoryChatroomFactory;
+import de.juplo.kafka.chat.backend.domain.ChatHomeService;
+import de.juplo.kafka.chat.backend.persistence.InMemoryChatHomeService;
import de.juplo.kafka.chat.backend.persistence.LocalJsonFilesStorageStrategy;
import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
{
@Bean
public ChatHome chatHome(
- ChatroomFactory chatroomFactory,
+ ChatHomeService chatHomeService,
StorageStrategy storageStrategy)
{
- return new ChatHome(chatroomFactory, storageStrategy.readChatrooms());
+ return new ChatHome(chatHomeService, storageStrategy.readChatrooms());
}
@Bean
public StorageStrategy storageStrategy(
ChatBackendProperties properties,
ObjectMapper mapper,
- InMemoryChatroomFactory chatroomFactory)
+ InMemoryChatHomeService chatHomeService)
{
return new LocalJsonFilesStorageStrategy(
Paths.get(properties.getDatadir()),
mapper,
- chatroomFactory);
+ chatHomeService);
}
@Bean
- InMemoryChatroomFactory chatroomFactory(ChatBackendProperties properties)
+ InMemoryChatHomeService chatHomeService(ChatBackendProperties properties)
{
- return new InMemoryChatroomFactory(properties.getChatroomBufferSize());
+ return new InMemoryChatHomeService(properties.getChatroomBufferSize());
}
@Bean
public class ChatHome
{
private final Map<UUID, Chatroom> chatrooms;
- private final ChatroomFactory factory;
+ private final ChatHomeService service;
- public ChatHome(ChatroomFactory factory, Flux<Chatroom> chatroomFlux)
+ public ChatHome(ChatHomeService service, Flux<Chatroom> chatroomFlux)
{
- log.debug("Creating ChatHome with factory: {}", factory);
- this.factory = factory;
+ log.debug("Creating ChatHome with factory: {}", service);
+ this.service = service;
this.chatrooms = new HashMap<>();
chatroomFlux.subscribe(chatroom -> chatrooms.put(chatroom.getId(), chatroom));
}
public Chatroom createChatroom(String name)
{
- Chatroom chatroom = factory.createChatroom(UUID.randomUUID(), name);
+ Chatroom chatroom = service.createChatroom(UUID.randomUUID(), name);
chatrooms.put(chatroom.getId(), chatroom);
return chatroom;
}
import java.util.UUID;
-public interface ChatroomFactory<T extends ChatroomService>
+public interface ChatHomeService<T extends ChatroomService>
{
Chatroom createChatroom(UUID id, String name);
}
package de.juplo.kafka.chat.backend.persistence;
import de.juplo.kafka.chat.backend.domain.Chatroom;
-import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
+import de.juplo.kafka.chat.backend.domain.ChatHomeService;
import lombok.RequiredArgsConstructor;
import java.util.LinkedHashMap;
@RequiredArgsConstructor
-public class InMemoryChatroomFactory implements ChatroomFactory<InMemoryChatroomService>
+public class InMemoryChatHomeService implements ChatHomeService<InMemoryChatroomService>
{
private final int bufferSize;
private final Path storagePath;
private final ObjectMapper mapper;
- private final InMemoryChatroomFactory chatroomFactory;
+ private final InMemoryChatHomeService service;
@Override
{
InMemoryChatroomService chatroomService =
new InMemoryChatroomService(readMessages(chatroomTo));
- return chatroomFactory.restoreChatroom(
+ return service.restoreChatroom(
chatroomTo.getId(),
chatroomTo.getName(),
chatroomService);