Scala 儿童演员的回复是否应该向其家长反映?
我对演员还不熟悉,我正在努力理解如何正确地将演员联系起来。我已经阅读了文档的一节 我现在是怎么做的Scala 儿童演员的回复是否应该向其家长反映?,scala,akka,actor,chaining,Scala,Akka,Actor,Chaining,我对演员还不熟悉,我正在努力理解如何正确地将演员联系起来。我已经阅读了文档的一节 我现在是怎么做的 case class Message1(text : String) class RootActor extends Actor { def receive: Actor.Receive = { case Message1(message) => { (context.actorOf(Props( new TestActor1)) ? message)(5.seco
case class Message1(text : String)
class RootActor extends Actor {
def receive: Actor.Receive = {
case Message1(message) => {
(context.actorOf(Props( new TestActor1)) ? message)(5.seconds) pipeTo sender
}
}
}
class TestActor1 extends Actor {
def receive: Actor.Receive = {
case message : String => {
sender ! (message + " TestActor1")
}
}
}
object Test {
def main(args: Array[String]) {
println("Start!")
implicit val system = ActorSystem()
val rootActor = system.actorOf(Props( new RootActor))
for (reply1 <- (rootActor ? Message1("Begin"))(5.seconds).mapTo[String])
println(reply1)
}
}
案例类消息1(文本:字符串)
类RootActor扩展了Actor{
def receive:Actor.receive={
案例消息1(消息)=>{
(context.actorOf(Props(newtestactor1))?消息(5秒)通过管道发送给发送方
}
}
}
类TestActor 1扩展了Actor{
def receive:Actor.receive={
案例消息:String=>{
发送者!(消息+测试者1)
}
}
}
对象测试{
def main(参数:数组[字符串]){
println(“开始!”)
隐式val system=ActorSystem()
val rootActor=system.actorOf(Props(新rootActor))
对于(回复1只需使用forward
即可。这就是它的用途。请像这样使用:
context.actorOf(Props( new TestActor1)).forward(message)
只需使用forward
即可。这就是它的用途。请像这样使用它:
context.actorOf(Props( new TestActor1)).forward(message)