import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import java.util.Arrays;
import java.util.UUID;
private final ChatHome chatHome;
private final ChatRoomFactory factory;
private final StorageStrategy storageStrategy;
+ private final int[] ownedShards;
@PostMapping("create")
.map(ChatRoomInfoTo::from);
}
- @GetMapping("list")
- public Flux<ChatRoomInfoTo> list()
+
+ @GetMapping("list/{shard}")
+ public Flux<ChatRoomInfoTo> list(@PathVariable int shard)
{
return chatHome
- .getChatRooms()
+ .getChatRooms(shard)
+ .map(chatroom -> ChatRoomInfoTo.from(chatroom));
+ }
+
+ @GetMapping("list")
+ public Mono<ChatRoomsTo> list()
+ {
+ return Arrays
+ .stream(ownedShards)
+ .mapToObj(shard -> chatHome.getChatRooms(shard))
.map(chatroom -> ChatRoomInfoTo.from(chatroom));
}
@PostMapping("/store")
public void store()
{
- storageStrategy.write(chatHome.getChatRooms());
+ Arrays
+ .stream(ownedShards)
+ .forEach(i -> storageStrategy.write(chatHome.getChatRooms(i))); // TODO: Sharded Storage
}
}
--- /dev/null
+package de.juplo.kafka.chat.backend.api;
+
+import lombok.Value;
+
+import java.util.List;
+import java.util.Map;
+
+
+@Value
+public class ChatRoomsTo
+{
+ Map<Integer, List<ChatRoomInfoTo>> chatRooms;
+}