From e7bbbdf8eda101220413e7bdd35f83500e6c17cb Mon Sep 17 00:00:00 2001 From: danischroeter Date: Sat, 11 Nov 2017 00:25:33 +0100 Subject: [PATCH] Provide access to known shard types #23912 (#23913) * Provide access to known shard types #23912 * applied format --- .../akka/cluster/sharding/ClusterSharding.scala | 16 ++++++++++++++++ akka-docs/src/main/paradox/cluster-sharding.md | 2 ++ 2 files changed, 18 insertions(+) diff --git a/akka-cluster-sharding/src/main/scala/akka/cluster/sharding/ClusterSharding.scala b/akka-cluster-sharding/src/main/scala/akka/cluster/sharding/ClusterSharding.scala index 10f6b69fb4..3d5fc32dba 100644 --- a/akka-cluster-sharding/src/main/scala/akka/cluster/sharding/ClusterSharding.scala +++ b/akka-cluster-sharding/src/main/scala/akka/cluster/sharding/ClusterSharding.scala @@ -6,6 +6,7 @@ package akka.cluster.sharding import java.net.URLEncoder import java.util.Optional import java.util.concurrent.ConcurrentHashMap + import scala.concurrent.Await import akka.actor.Actor import akka.actor.ActorRef @@ -27,10 +28,15 @@ import akka.pattern.ask import akka.dispatch.Dispatchers import akka.cluster.ddata.ReplicatorSettings import akka.cluster.ddata.Replicator + import scala.util.control.NonFatal import akka.actor.Status import akka.cluster.ClusterSettings import akka.cluster.ClusterSettings.DataCenter +import akka.stream.{ Inlet, Outlet } + +import scala.collection.immutable +import scala.collection.JavaConverters._ /** * This extension provides sharding functionality of actors in a cluster. @@ -445,6 +451,16 @@ class ClusterSharding(system: ExtendedActorSystem) extends Extension { } + /** + * Scala API: get all currently defined sharding type names. + */ + def shardTypeNames: immutable.Set[String] = regions.keySet().asScala.toSet + + /** + * Java API: get all currently defined sharding type names. + */ + def getShardTypeNames: java.util.Set[String] = regions.keySet() + /** * Retrieve the actor reference of the [[ShardRegion]] actor responsible for the named entity type. * The entity type must be registered with the [[#start]] or [[#startProxy]] method before it diff --git a/akka-docs/src/main/paradox/cluster-sharding.md b/akka-docs/src/main/paradox/cluster-sharding.md index 09ccb5af4c..82c0dc73a5 100644 --- a/akka-docs/src/main/paradox/cluster-sharding.md +++ b/akka-docs/src/main/paradox/cluster-sharding.md @@ -464,6 +464,8 @@ the identifiers of the shards running in a Region and what entities are alive fo a `ShardRegion.ClusterShardingStats` containing the identifiers of the shards running in each region and a count of entities that are alive in each shard. +The type names of all started shards can be aquired via @scala[`ClusterSharding.shardTypeNames`] @java[`ClusterSharding.getShardTypeNames`]. + The purpose of these messages is testing and monitoring, they are not provided to give access to directly sending messages to the individual entities.