1 package de.juplo.kafka.chat.backend.persistence.inmemory;
3 import de.juplo.kafka.chat.backend.ChatBackendProperties;
4 import de.juplo.kafka.chat.backend.api.KafkaLikeShardingStrategy;
5 import de.juplo.kafka.chat.backend.api.ShardingStrategy;
6 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
7 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.context.annotation.Configuration;
11 import java.time.Clock;
14 @ConditionalOnProperty(
15 prefix = "chat.backend",
17 havingValue = "inmemory",
18 matchIfMissing = true)
20 public class InMemoryServicesConfiguration
23 InMemoryChatHomeService chatHomeService(
24 ChatBackendProperties properties,
25 StorageStrategy storageStrategy)
27 return new InMemoryChatHomeService(
28 properties.getInmemory().getNumShards(),
29 properties.getInmemory().getOwnedShards(),
30 storageStrategy.read());
34 InMemoryChatHomeFactory chatHomeFactory(InMemoryChatHomeService service)
36 return new InMemoryChatHomeFactory(service);
40 InMemoryChatRoomFactory chatRoomFactory(
41 ShardingStrategy strategy,
43 ChatBackendProperties properties)
45 return new InMemoryChatRoomFactory(
48 properties.getChatroomBufferSize());
51 @ConditionalOnProperty(
52 prefix = "chat.backend.inmemory",
53 name = "sharding-strategy",
55 matchIfMissing = true)
57 ShardingStrategy defaultShardingStrategy()
59 return chatRoomId -> 0;
62 @ConditionalOnProperty(
63 prefix = "chat.backend.inmemory",
64 name = "sharding-strategy",
65 havingValue = "kafkalike")
67 ShardingStrategy kafkalikeShardingStrategy(ChatBackendProperties properties)
69 return new KafkaLikeShardingStrategy(
70 properties.getInmemory().getNumShards());