feat: `UnknownChatroomException` records shard and owned shards
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / persistence / inmemory / InMemoryChatHomeService.java
index 1334124..29f1312 100644 (file)
@@ -6,6 +6,7 @@ import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 import java.util.*;
+import java.util.stream.IntStream;
 
 
 @Slf4j
@@ -60,6 +61,14 @@ public class InMemoryChatHomeService
     return Mono.justOrEmpty(chatrooms[shard].get(id));
   }
 
+  public int[] getOwnedShards()
+  {
+    return IntStream
+        .range(0, chatrooms.length)
+        .filter(i -> chatrooms[i] != null)
+        .toArray();
+  }
+
   public Flux<ChatRoom> getChatRooms(int shard)
   {
     return Flux.fromStream(chatrooms[shard].values().stream());