2017-03-31 13 views
0

私はaskパターンを使用してリモートアクタにリクエストを送信しようとしています。地元の俳優は何らかの価値を受け取り、そこで何らかの仕事をして更新します。 ローカルアクターが更新された値をリモートアクターに送り返そうとすると、送信中にエラーが発生します。このエラーをどうやって処理すべきですか?Scala Akkaの俳優、パターンを聞いて、返信を送信中にデッドレターが遭遇しました

エラー: [INFO] [2017年3月31日17:28:18.383] [ClientSystem-akka.actor.default-ディスパッチャ-3] [アッカ:// ClientSystem/deadLetters] メッセージ[check.package Actk [akka:// ClientSystem/deadLetters]へのアクタ[akka:// ClientSystem/user/localA1#1050660737]からの$ Rcvdcxt]は配信されませんでした。 [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 { case成功(Rcvdcxt(cxtA))=> currentSender! Rcvdcxt(cxtA) ... } –

関連する問題