@GetMapping("{chatroomId}/list")
public Flux<MessageTo> list(@PathVariable UUID chatroomId)
{
- int shard = selectionStrategy.selectShard(chatroomId);
- return chatHomes[shard]
+ return chatHomes[selectShard(chatroomId)]
.getChatRoom(chatroomId)
.flatMapMany(chatroom -> chatroom
.getMessages()
@GetMapping("{chatroomId}")
public Mono<ChatRoomTo> get(@PathVariable UUID chatroomId)
{
- int shard = selectionStrategy.selectShard(chatroomId);
- return chatHomes[shard]
+ return chatHomes[selectShard(chatroomId)]
.getChatRoom(chatroomId)
.map(chatroom -> ChatRoomTo.from(chatroom));
}
@PathVariable Long messageId,
@RequestBody String text)
{
- int shard = selectionStrategy.selectShard(chatroomId);
return
- chatHomes[shard]
+ chatHomes[selectShard(chatroomId)]
.getChatRoom(chatroomId)
.flatMap(chatroom -> put(chatroom, username, messageId, text));
}
@PathVariable String username,
@PathVariable Long messageId)
{
- int shard = selectionStrategy.selectShard(chatroomId);
return
- chatHomes[shard]
+ chatHomes[selectShard(chatroomId)]
.getChatRoom(chatroomId)
.flatMap(chatroom -> get(chatroom, username, messageId));
}
@GetMapping(path = "{chatroomId}/listen")
public Flux<ServerSentEvent<MessageTo>> listen(@PathVariable UUID chatroomId)
{
- int shard = selectionStrategy.selectShard(chatroomId);
- return chatHomes[shard]
+ return chatHomes[selectShard(chatroomId)]
.getChatRoom(chatroomId)
.flatMapMany(chatroom -> listen(chatroom));
}
for (int shard = 0; shard < chatHomes.length; shard++)
storageStrategy.write(chatHomes[shard].getChatRooms());
}
+
+ private int selectShard(UUID chatroomId)
+ {
+ return selectionStrategy.selectShard(chatroomId);
+ }
}