2017-03-31 32 views
0

我想发送一个请求,使用问模式的远程演员。当地的演员会收到一些价值,并在它上面执行一些任务并更新它。 然后,当本地演员尝试发送更新值给远程演员时,发送时发生错误。我应该如何处理这个错误?斯卡拉阿卡演员,问模式,发送答复时遇到的死信

错误: [INFO] [2017年3月31日17:28:18.383] [ClientSystem-akka.actor.default-调度-3] [阿卡:// ClientSystem/deadLetters] 消息[check.package $ Rcvdcxt]从Actor [akka:// ClientSystem/user/localA1#1050660737]发送给Actor [akka:// ClientSystem/deadLetters]未送达。 [1]遇到了死信。

Remote Actor: 

class RemoteActor() extends Actor { 

    def receive = { 


    case TaskFromLocal() =>{ 
     implicit val timeout: Timeout = 15000 
     val currentSender = sender 
     val f1 = currentSender ? RemoteActor.rtree.cxtA 
      f1.onComplete{ 
      case Success(Rcvdcxt(cxtA))=> 
       println("Success"+cxtA) 
      case Success(s) => 
        println("Success :"+s) 
      case Failure(ex) => 
        println("failure:"+ex) 
      } 
     } 


    case _ => println("unknown msg") 
    } 
} 
object RemoteActor{ 

    def createRndCxtC(count: Int):List[CxtC] = (for (i <- 1 to count) yield CxtC(Random.nextString(5), Random.nextInt())).toList 
    def createRndCxtB(count: Int): List[CxtB] = (for (i <- 1 to count) yield CxtB(createRndCxtC(count), Random.nextInt())).toList 
    def createRndCxtA(count: Int): List[CxtA] = (for (i <- 1 to count) yield CxtA(createRndCxtC(count), 5)).toList 
    var rtree = RCxt(createRndCxtA(1),createRndCxtB(2),1,"") 

    def main(args: Array[String]) {  
     val configFile = getClass.getClassLoader.getResource("remote_application.conf").getFile 
     val config = ConfigFactory.parseFile(new File(configFile)) 
     val system = ActorSystem("RemoteSystem" , config) 
     val remoteActor = system.actorOf(Props[RemoteActor], name="remote") 
     println("remote is ready") 
    } 
} 



Local Actor : 


class LocalActorA extends Actor{  

    @throws[Exception](classOf[Exception]) 
    val remoteActor = context.actorSelection("akka.tcp://[email protected]:5150/user/remote") 

    def receive = { 



    case TaskLA1(taskA) => { 

    implicit val timeout: Timeout = 15000 
     val rCxt = remoteActor ? TaskFromLocal() 
     val currentSender = sender 
     rCxt.onComplete{ 
      case Success(Rcvdcxt(cxtA))=> 
       println("Success"+cxtA) 
       println("Sender: "+ sender) 
       currentSender ! Rcvdcxt(cxtA) 

      case Success(s)=> 
       println("Got nothing from Remote"+s) 
       currentSender ! "Failuree" 

      case Failure(ex) => 
       println("Failure in getting remote") 
       currentSender ! "Failure" 
      } 
    } 
    } 
} 

object LocalActorA {  


    def createRndCxtC(count: Int):List[CxtC] = (for (i <- 1 to count) yield CxtC(Random.nextString(5), Random.nextInt())).toList 
    def createRndCxtB(count: Int): List[CxtB] = (for (i <- 1 to count) yield CxtB(createRndCxtC(count), Random.nextInt())).toList 
    def createRndCxtA(count: Int): List[CxtA] = (for (i <- 1 to count) yield CxtA(createRndCxtC(count), 3)).toList 
    var tree = RCxt(createRndCxtA(2),createRndCxtB(2),1,"") 

    def main(args: Array[String]) { 
    val configFile = getClass.getClassLoader.getResource("local_application.conf").getFile 
    val config = ConfigFactory.parseFile(new File(configFile)) 
    val system = ActorSystem("ClientSystem",config) 
    val localActorA1 = system.actorOf(Props[LocalActorA], name="localA1") 
    println("LocalActor A tree : "+tree) 
    localActorA1 ! TaskLA1(new DummySum()) 
    } 
} 

回答

0

既然你没有张贴所有的代码,我真的不能告诉完全错误,但我最好的猜测是有关的事实,你在呼唤在LocalActor的onCompletesender。这是不安全的,应该不惜一切代价避免。相反,做远程男主角类似的东西:

class LocalActor { 
    def receive = { 
    case TaskLA1(taskA) => 
     val currentSender = sender 
     rCxt.onComplete { 
     case Success(Rcvdcxt(cxtA))=> 
      currentSender ! Rcvdcxt(cxtA) 
      ... 
     } 
    } 
} 
+0

是的,我已经更新了发信人瓦尔currentSender,但仍存在着同样的错误,因为第一次调用是从LocalActor到RemoteActor,然后本地回复远程等待:案例TaskLA1 (taskA)=> val rCxt = remoteActor? TaskFromLocal()val currentSender = sender rCxt.onComplete {0}成功(Rcvdcxt(cxtA))=> currentSender! Rcvdcxt(cxtA) ... } –