From: Kai Moritz Date: Tue, 29 Aug 2023 17:36:15 +0000 (+0200) Subject: refactor: `ShardNotOwnedException` should be send over `Mono.send()` X-Git-Tag: wip-inmemory-chat-home-service~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=a3558bc7e8476e38a62f714247a9c9eb39346d6e;p=demos%2Fkafka%2Fchat refactor: `ShardNotOwnedException` should be send over `Mono.send()` --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java index 4fa4d9bd..ac7a9808 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ShardedChatHome.java @@ -44,9 +44,9 @@ public class ShardedChatHome implements ChatHome public Mono getChatRoom(UUID id) { int shard = selectShard(id); - if (chatHomes[shard] == null) - throw new ShardNotOwnedException(shard); - return chatHomes[shard].getChatRoom(id); + return chatHomes[shard] == null + ? Mono.error(new ShardNotOwnedException(shard)) + : chatHomes[shard].getChatRoom(id); } @Override diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java index f6f50ccd..234554eb 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/kafka/ChatRoomChannel.java @@ -369,12 +369,12 @@ public class ChatRoomChannel implements Runnable, ConsumerRebalanceListener { if (loadInProgress) { - throw new LoadInProgressException(); + return Mono.error(new LoadInProgressException()); } if (!isShardOwned[shard]) { - throw new ShardNotOwnedException(shard); + return Mono.error(new ShardNotOwnedException(shard)); } return Mono.justOrEmpty(chatrooms[shard].get(id));