Created
July 17, 2014 12:31
-
-
Save ktoso/c7382f3c88159f352b75 to your computer and use it in GitHub Desktop.
Trying to debug remote terminated messages from a Pool that's all children have died.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.cluster.simple | |
import akka.actor.Actor.Receive | |
import akka.routing.{Broadcast, RoundRobinPool} | |
import com.typesafe.config.ConfigFactory | |
import akka.remote.RemoteScope | |
import akka.actor._ | |
import scala.util.Random | |
object SimpleClusterApp { | |
var names = "A" :: "B" :: "C" :: Nil | |
def main(args: Array[String]): Unit = { | |
val Seq(s1, s2, sys) = startup(Seq("2551", "2552", "0")) | |
val a1 = Address("akka.tcp", "ClusterSystem-A", "127.0.0.1", 2551) | |
val a2 = Address("akka.tcp", "ClusterSystem-B", "127.0.0.1", 2552) | |
val router = sys.actorOf( | |
Props[Echo]() | |
.withRouter(RoundRobinPool(5)) | |
.withDeploy(Deploy(scope = RemoteScope(a2))), | |
"router") | |
val watcher = sys.actorOf(Props(classOf[Watcher], router), "watcher") | |
router ! "Hi" | |
router ! Broadcast("All") | |
Thread.sleep(2000) | |
router ! Broadcast(PoisonPill) | |
println("Waiting...") | |
Thread.sleep(5000) | |
println("Shutting down...") | |
s1.shutdown() | |
s2.shutdown() | |
sys.shutdown() | |
} | |
def startup(ports: Seq[String]): Seq[ActorSystem] = { | |
ports map { port => | |
// Override the configuration of the port | |
val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port). | |
withFallback(ConfigFactory.load()) | |
// Create an Akka system | |
val name = s"ClusterSystem-${names.head}" | |
names = names.drop(1) | |
println("name = " + name) | |
val system = ActorSystem(name, config) | |
// Create an actor that handles cluster domain events | |
system.actorOf(Props[SimpleClusterListener], name = "clusterListener") | |
system | |
} | |
} | |
} | |
class Echo extends Actor { | |
val n = Random.nextInt(200) | |
override def postStop() { | |
super.postStop() | |
println(s"dying-$n") | |
} | |
override def receive = { | |
case m ⇒ | |
println(s"actor-$n (${self.path.address.hostPort}}), got: " + m) | |
sender() ! (m + "-" + n) | |
} | |
} | |
class Watcher(who: ActorRef) extends Actor { | |
override def preStart() { | |
println("watching: " + who) | |
context.watch(who) | |
} | |
override def receive: Receive = { | |
case Terminated(dead) => | |
println(s"I got info that terminated: " + dead) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment