X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fpersistence%2Finmemory%2FInMemoryServicesConfiguration.java;h=de50448524841a6579ce7ea98a378917d5a7506f;hb=13c51b4630177e7f6649500a3d4b876a12509af6;hp=1dca04023df825ae14802943e13dc1ea548330e6;hpb=7dc64266c5675ead8214edb36173b80363e08b1f;p=demos%2Fkafka%2Fchat diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java index 1dca0402..de504485 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryServicesConfiguration.java @@ -45,23 +45,22 @@ public class InMemoryServicesConfiguration StorageStrategy storageStrategy) { int numShards = properties.getInmemory().getNumShards(); - ShardingStrategy shardingStrategy = new KafkaLikeShardingStrategy(numShards); SimpleChatHome[] chatHomes = new SimpleChatHome[numShards]; storageStrategy .read() .subscribe(chatRoom -> { - int shard = shardingStrategy.selectShard(chatRoom.getId()); + int shard = chatRoom.getShard(); if (chatHomes[shard] == null) chatHomes[shard] = new SimpleChatHome(chatHomeService, shard); }); - return new ShardedChatHome(chatHomes, shardingStrategy); + ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards); + return new ShardedChatHome(chatHomes, strategy); } @Bean InMemoryChatHomeService chatHomeService( ChatBackendProperties properties, - ShardingStrategy shardingStrategy, StorageStrategy storageStrategy) { ShardingStrategyType sharding = @@ -73,7 +72,6 @@ public class InMemoryServicesConfiguration ? new int[] { 0 } : properties.getInmemory().getOwnedShards(); return new InMemoryChatHomeService( - shardingStrategy, numShards, ownedShards, storageStrategy.read()); @@ -81,11 +79,13 @@ public class InMemoryServicesConfiguration @Bean InMemoryChatRoomFactory chatRoomFactory( + InMemoryChatHomeService service, ShardingStrategy strategy, Clock clock, ChatBackendProperties properties) { return new InMemoryChatRoomFactory( + service, strategy, clock, properties.getChatroomBufferSize());