diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala index d4b5d66a6b..ca47f4f36e 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala @@ -59,6 +59,34 @@ class RoutingSpec extends AkkaSpec with DefaultTimeout with ImplicitSender { expectMsg(Terminated(router)) } + "be able to send their routees" in { + val doneLatch = new CountDownLatch(1) + + class TheActor extends Actor { + val routee1 = context.actorOf(Props[TestActor], "routee1") + val routee2 = context.actorOf(Props[TestActor], "routee2") + val routee3 = context.actorOf(Props[TestActor], "routee3") + val router = context.actorOf(Props[TestActor].withRouter(ScatterGatherFirstCompletedRouter(routees = List(routee1, routee2, routee3)))) + + // Stop one of the routees - which should exclude it from the router's list of active routees + routee3 ! PoisonPill + + def receive = { + case RouterRoutees(iterable) ⇒ + iterable.exists(_ == "routee1") must be(true) + iterable.exists(_ == "routee2") must be(true) + iterable.exists(_ == "routee3") must be(false) + doneLatch.countDown() + case "doIt" ⇒ + router ! CurrentRoutees + } + } + + val theActor = system.actorOf(Props(new TheActor), "theActor") + theActor ! "doIt" + doneLatch.await(1, TimeUnit.SECONDS) must be(true) + } + } "no router" must { diff --git a/akka-actor/src/main/scala/akka/routing/Routing.scala b/akka-actor/src/main/scala/akka/routing/Routing.scala index b047af5888..fd33eb1525 100644 --- a/akka-actor/src/main/scala/akka/routing/Routing.scala +++ b/akka-actor/src/main/scala/akka/routing/Routing.scala @@ -4,12 +4,8 @@ package akka.routing import akka.actor._ -import akka.japi.Creator -import java.lang.reflect.InvocationTargetException -import akka.config.ConfigurationException import java.util.concurrent.atomic.AtomicInteger -import akka.util.{ ReflectiveAccess, Timeout } -import akka.AkkaException +import akka.util.Timeout import scala.collection.JavaConversions._ import java.util.concurrent.TimeUnit @@ -33,6 +29,9 @@ private[akka] class RoutedActorRef(_system: ActorSystemImpl, _props: Props, _sup def applyRoute(sender: ActorRef, message: Any): Iterable[Destination] = message match { case _: AutoReceivedMessage ⇒ Nil case Terminated(_) ⇒ Nil + case CurrentRoutees ⇒ + sender ! RouterRoutees(_routees map (_.path.name)) + Nil case _ ⇒ if (route.isDefinedAt(sender, message)) route(sender, message) else Nil @@ -148,6 +147,17 @@ trait Router extends Actor { */ case class Broadcast(message: Any) +/** + * Sending this message to a router will make it send back its currently used routees. + * The routees will be sent as a RouterRoutees message to the "requester". + */ +case object CurrentRoutees + +/** + * Message used to carry information about what routees the router is currently using. + */ +case class RouterRoutees(routees: Iterable[String]) + /** * For every message sent to a router, its route determines a set of destinations, * where for each recipient a different sender may be specified; typically the