我正在尝试使用Scala和Akka(2.3.8)
代码
object Main extends App {
args match {
case Array("worker") => {
startWorker
}
case Array("service") => {
startService
}
case _ => {
println("Invalid")
}
}
def startWorker: Unit = {
println("Remote is Ready !!!")
ActorSystem("server", ConfigFactory.load("worker.conf"))
}
def startService: Unit ={
implicit val system = ActorSystem("study", ConfigFactory.load("application.conf"))
val master = system.actorOf(Props[Master], "study")
for (i <- 1 to 100) {
master ! i
Thread.sleep(5)
}
master ! "Stop"
system.shutdown()
}
}
class Master extends Actor {
val router = context.actorOf(FromConfig.props(Props[ServerActor]), "worker")
def receive ={
case "Stop" =>
router ! Broadcast(PoisonPill)
case x => router.forward(x)
}
}
class ServerActor extends Actor {
def receive = {
case x => {
println("got message from remote " + x)
}
}
}
有效,但我有这个日志
[WARN] [07/01/2015 00:16:11.532] [server-akka.remote.default-remote-dispatcher-13] [LocalActorRefProvider(akka:// server)]未知消息[DeathWatchNotification(Actor [ akka.tcp://study@127.0.0.1:2551 / user / study / worker#1059230782],true,false)] [Actor [akka:// server / remote]]收到 [ERROR] [07/01/2015 00:16:11.604] [server-akka.remote.default-remote-dispatcher-5] [akka.tcp://server@127.0.0.1:2552 / system / endpointManager / reliableEndpointWriter -akka.tcp%3A%2F%2Fstudy%40127.0.0.1%3A2551-0 / endpointWriter] AssociationError [akka.tcp://server@127.0.0.1:2552]&lt; - [akka.tcp://study@127.0 .0.1:2551]:错误[关闭地址:akka.tcp://study@127.0.0.1:2551] [ akka.remote.ShutDownAssociation:关闭地址:akka.tcp://study@127.0.0.1:2551 引起:akka.remote.transport.Transport $ InvalidAssociationException:远程系统终止了关联,因为它正在关闭。 ]
为什么呢? 我不明白这种治疗方法。请告诉我如何处理这个问题。