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: rebase--2024-01-27--15-46~39 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=6cc5f2c7faa5ea79ea20ab95486c0c843fe3ec24;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));