projects
/
demos
/
kafka
/
chat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: A `ChatRoom` does not have to remember its shard any more
[demos/kafka/chat]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
chat
/
backend
/
persistence
/
inmemory
/
InMemoryServicesConfiguration.java
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
96ef05c
..
1dca040
100644
(file)
--- 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,22
+45,23
@@
public class InMemoryServicesConfiguration
StorageStrategy storageStrategy)
{
int numShards = properties.getInmemory().getNumShards();
StorageStrategy storageStrategy)
{
int numShards = properties.getInmemory().getNumShards();
+ ShardingStrategy shardingStrategy = new KafkaLikeShardingStrategy(numShards);
SimpleChatHome[] chatHomes = new SimpleChatHome[numShards];
storageStrategy
.read()
.subscribe(chatRoom ->
{
SimpleChatHome[] chatHomes = new SimpleChatHome[numShards];
storageStrategy
.read()
.subscribe(chatRoom ->
{
- int shard =
chatRoom.getShard(
);
+ int shard =
shardingStrategy.selectShard(chatRoom.getId()
);
if (chatHomes[shard] == null)
chatHomes[shard] = new SimpleChatHome(chatHomeService, shard);
});
if (chatHomes[shard] == null)
chatHomes[shard] = new SimpleChatHome(chatHomeService, shard);
});
- ShardingStrategy strategy = new KafkaLikeShardingStrategy(numShards);
- return new ShardedChatHome(chatHomes, strategy);
+ return new ShardedChatHome(chatHomes, shardingStrategy);
}
@Bean
InMemoryChatHomeService chatHomeService(
ChatBackendProperties properties,
}
@Bean
InMemoryChatHomeService chatHomeService(
ChatBackendProperties properties,
+ ShardingStrategy shardingStrategy,
StorageStrategy storageStrategy)
{
ShardingStrategyType sharding =
StorageStrategy storageStrategy)
{
ShardingStrategyType sharding =
@@
-72,6
+73,7
@@
public class InMemoryServicesConfiguration
? new int[] { 0 }
: properties.getInmemory().getOwnedShards();
return new InMemoryChatHomeService(
? new int[] { 0 }
: properties.getInmemory().getOwnedShards();
return new InMemoryChatHomeService(
+ shardingStrategy,
numShards,
ownedShards,
storageStrategy.read());
numShards,
ownedShards,
storageStrategy.read());