From c5976140f6ad8c5a09753c528f0f01a69716dd6b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 2 Sep 2023 19:46:50 +0200 Subject: [PATCH] WIP --- .../inmemory/InMemoryChatRoomFactory.java | 1 - .../InMemoryServicesConfiguration.java | 30 +++---------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomFactory.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomFactory.java index 2bde2361..855c401e 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomFactory.java +++ b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatRoomFactory.java @@ -14,7 +14,6 @@ import java.util.UUID; @Slf4j public class InMemoryChatRoomFactory implements ChatRoomFactory { - private final InMemoryChatHomeService chatHomeService; private final ShardingStrategy shardingStrategy; private final Clock clock; private final int bufferSize; 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 00e0c6fd..ee41c4f3 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 @@ -1,7 +1,6 @@ package de.juplo.kafka.chat.backend.persistence.inmemory; import de.juplo.kafka.chat.backend.ChatBackendProperties; -import de.juplo.kafka.chat.backend.ChatBackendProperties.ShardingStrategyType; import de.juplo.kafka.chat.backend.domain.ChatHome; import de.juplo.kafka.chat.backend.persistence.StorageStrategy; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -26,9 +25,9 @@ public class InMemoryServicesConfiguration name = "sharding-strategy", havingValue = "none", matchIfMissing = true) - ChatHome noneShardingChatHome() + ChatHome noneShardingChatHome(StorageStrategy storageStrategy) { - return new SimpleChatHome(); + return new SimpleChatHome(storageStrategy.read()); } @Bean @@ -38,45 +37,24 @@ public class InMemoryServicesConfiguration havingValue = "kafkalike") ChatHome kafkalikeShardingChatHome( ChatBackendProperties properties, - InMemoryChatHomeService chatHomeService) + StorageStrategy storageStrategy) { int numShards = properties.getInmemory().getNumShards(); SimpleChatHome[] chatHomes = new SimpleChatHome[numShards]; IntStream .of(properties.getInmemory().getOwnedShards()) - .forEach(shard -> chatHomes[shard] = new SimpleChatHome(chatHomeService, shard)); + .forEach(shard -> chatHomes[shard] = new SimpleChatHome(shard, storageStrategy.read())); ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards); return new ShardedChatHome(chatHomes, strategy); } - @Bean - InMemoryChatHomeService chatHomeService( - ChatBackendProperties properties, - StorageStrategy storageStrategy) - { - ShardingStrategyType sharding = - properties.getInmemory().getShardingStrategy(); - int numShards = sharding == ShardingStrategyType.none - ? 1 - : properties.getInmemory().getNumShards(); - int[] ownedShards = sharding == ShardingStrategyType.none - ? new int[] { 0 } - : properties.getInmemory().getOwnedShards(); - return new InMemoryChatHomeService( - numShards, - ownedShards, - storageStrategy.read()); - } - @Bean InMemoryChatRoomFactory chatRoomFactory( - InMemoryChatHomeService service, ShardingStrategy strategy, Clock clock, ChatBackendProperties properties) { return new InMemoryChatRoomFactory( - service, strategy, clock, properties.getChatroomBufferSize()); -- 2.20.1