WIP
authorKai Moritz <kai@juplo.de>
Fri, 24 Feb 2023 10:43:39 +0000 (11:43 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 24 Feb 2023 10:43:39 +0000 (11:43 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java
src/main/java/de/juplo/kafka/chat/backend/domain/ChatHome.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java

index 4bcc542..c61f848 100644 (file)
@@ -16,7 +16,7 @@ public class ChatBackendApplication implements WebFluxConfigurer
        @Autowired
        ChatBackendProperties properties;
        @Autowired
-       ChatHome[] chatHomes;
+       ChatHome chatHome;
        @Autowired
        StorageStrategy storageStrategy;
 
@@ -32,8 +32,7 @@ public class ChatBackendApplication implements WebFluxConfigurer
        @PreDestroy
        public void onExit()
        {
-               for (int shard = 0; shard < chatHomes.length; shard++)
-                       storageStrategy.write(chatHomes[shard].getChatRooms(shard));
+               storageStrategy.write(chatHome.getChatRooms());
        }
 
        public static void main(String[] args)
index c6445a0..557cf75 100644 (file)
@@ -1,5 +1,6 @@
 package de.juplo.kafka.chat.backend.domain;
 
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -7,18 +8,13 @@ import reactor.core.publisher.Mono;
 import java.util.*;
 
 
+@RequiredArgsConstructor
 @Slf4j
 public class ChatHome
 {
   private final ChatHomeService service;
 
 
-  public ChatHome(ChatHomeService service)
-  {
-    log.info("Created ChatHome with ChatHomeService {}", service);
-  }
-
-
   public Mono<ChatRoom> getChatRoom(UUID id)
   {
     return service
@@ -26,8 +22,8 @@ public class ChatHome
         .switchIfEmpty(Mono.error(() -> new UnknownChatroomException(id)));
   }
 
-  public Flux<ChatRoom> getChatRooms(int shard)
+  public Flux<ChatRoom> getChatRooms()
   {
-    return service.getChatRooms(shard);
+    return service.getChatRooms();
   }
 }
index a72b0c9..25a9bcf 100644 (file)
@@ -95,6 +95,6 @@ public class InMemoryChatHomeService implements ChatHomeService
   {
     return Flux
         .fromIterable(ownedShards)
-        .flatMap(shard -> chatrooms[shard].values().stream());
+        .flatMap(shard -> Flux.fromIterable(chatrooms[shard].values()));
   }
 }