X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fimplementation%2Finmemory%2FShardedChatHomeService.java;h=c281d9e1d463d74130b000cb3cdbee47e3a3c0f9;hb=8d997cc65763b3f12fb680da67f471590e6eeeb2;hp=06c197bf65f2a2cb423f96ca82e7756a43169c3f;hpb=efb070ce6e1e7ea1bb3297147b4e5a4bee3967cd;p=demos%2Fkafka%2Fchat diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeService.java index 06c197bf..c281d9e1 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeService.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeService.java @@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import java.net.URI; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -19,14 +21,20 @@ public class ShardedChatHomeService implements ChatHomeService { private final SimpleChatHomeService[] chatHomes; private final Set ownedShards; + private final String[] shardOwners; private final ShardingStrategy shardingStrategy; public ShardedChatHomeService( SimpleChatHomeService[] chatHomes, + URI[] shardOwners, ShardingStrategy shardingStrategy) { this.chatHomes = chatHomes; + this.shardOwners = Arrays + .stream(shardOwners) + .map(uri -> uri.toASCIIString()) + .toArray(size -> new String[size]); this.shardingStrategy = shardingStrategy; this.ownedShards = new HashSet<>(); for (int shard = 0; shard < chatHomes.length; shard++) @@ -90,6 +98,12 @@ public class ShardedChatHomeService implements ChatHomeService : throwable); } + @Override + public Mono getShardOwners() + { + return Mono.just(shardOwners); + } + private int selectShard(UUID chatroomId) { return shardingStrategy.selectShard(chatroomId);