Skip to content

Commit

Permalink
Allow to disable automatic passivation for specific shard regions
Browse files Browse the repository at this point in the history
Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
  • Loading branch information
Yannic92 committed Jan 17, 2022
1 parent 4da346a commit eb5722d
Showing 1 changed file with 21 additions and 1 deletion.
Expand Up @@ -115,11 +115,31 @@ public ActorRef getSearchUpdaterShardRegion(final int numberOfShards,
* @return the shard region.
*/
public ActorRef createShardRegion(final int shards, final Props props, final String name, final String role) {
return createShardRegion(shards, true, props, name, role);
}

/**
* Create a new shard region.
*
* @param shards number of shards.
* @param automaticPassivationEnabled indicates whether the entities should be passivated automatically.
* @param props props of actors in the shard region.
* @param name name of the shard region.
* @param role cluster role where the shard region starts.
* @return the shard region.
*/
public ActorRef createShardRegion(final int shards, final boolean automaticPassivationEnabled, final Props props,
final String name, final String role) {
final ClusterSharding clusterSharding = ClusterSharding.get(actorSystem);
final ClusterShardingSettings shardingSettings =
ClusterShardingSettings.create(actorSystem).withRole(role);
final ShardRegionExtractor shardRegionExtractor = ShardRegionExtractor.of(shards, actorSystem);
return clusterSharding.start(name, props, shardingSettings, shardRegionExtractor);
if (automaticPassivationEnabled) {
return clusterSharding.start(name, props, shardingSettings, shardRegionExtractor);
} else {
return clusterSharding.start(name, props, shardingSettings.withNoPassivationStrategy(),
shardRegionExtractor);
}
}

}

0 comments on commit eb5722d

Please sign in to comment.