X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fapi%2FChatBackendController.java;h=9be7fa165dcf918d14e94f137fd9085e2f4dcfdc;hb=ff98b068a91fc9e60e51bd4a95065633bb8ed2db;hp=1c0224bc6e7c0f5be7df2942af533ccafe3f14d6;hpb=9d61871563f4be4850cebca4fad0545d504522c3;p=demos%2Fkafka%2Fchat diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java index 1c0224bc..9be7fa16 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java @@ -45,8 +45,7 @@ public class ChatBackendController @GetMapping("{chatroomId}/list") public Flux list(@PathVariable UUID chatroomId) { - int shard = selectionStrategy.selectShard(chatroomId); - return chatHomes[shard] + return chatHomes[selectShard(chatroomId)] .getChatRoom(chatroomId) .flatMapMany(chatroom -> chatroom .getMessages() @@ -56,8 +55,7 @@ public class ChatBackendController @GetMapping("{chatroomId}") public Mono get(@PathVariable UUID chatroomId) { - int shard = selectionStrategy.selectShard(chatroomId); - return chatHomes[shard] + return chatHomes[selectShard(chatroomId)] .getChatRoom(chatroomId) .map(chatroom -> ChatRoomTo.from(chatroom)); } @@ -69,9 +67,8 @@ public class ChatBackendController @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)); } @@ -97,9 +94,8 @@ public class ChatBackendController @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)); } @@ -118,8 +114,7 @@ public class ChatBackendController @GetMapping(path = "{chatroomId}/listen") public Flux> listen(@PathVariable UUID chatroomId) { - int shard = selectionStrategy.selectShard(chatroomId); - return chatHomes[shard] + return chatHomes[selectShard(chatroomId)] .getChatRoom(chatroomId) .flatMapMany(chatroom -> listen(chatroom)); } @@ -144,4 +139,9 @@ public class ChatBackendController for (int shard = 0; shard < chatHomes.length; shard++) storageStrategy.write(chatHomes[shard].getChatRooms()); } + + private int selectShard(UUID chatroomId) + { + return selectionStrategy.selectShard(chatroomId); + } }