akka.net只重启池中的单个routee

时间:2016-08-21 08:36:01

标签: c# akka akka.net

我有一个RoundRobinPool,我想要使用OneForOneStategy,这样当一个孩子只抛出那个孩子重新启动时。我正在创建这样的路由器:

var strat = new OneForOneStrategy(1, TimeSpan.FromSeconds(5), e => Directive.Restart);

var props = Props.Create<ThrowAlwaysActor>()
                        .WithRouter(new RoundRobinPool(2))
                        .WithSupervisorStrategy(strat);

var router = system.ActorOf(props, "myrouter");
router.Tell("1");

输出:

akka://loadSystem/user/myrouter/$b PRERESTART <-- pool init
akka://loadSystem/user/myrouter/$a PRERESTART <-- pool init
akka://loadSystem/user/myrouter/$a OnReceive()
[ERROR][8/21/2016 8:21:02 AM][Thread 0004][akka://loadSystem/user/myrouter] The method or operation is not implemented.
akka://loadSystem/user/myrouter/$a PRERESTART <-- the actor that threw is being restarted
akka://loadSystem/user/myrouter/$b PRERESTART <-- this actor should not be restarted

如何将RoundRobin池配置为仅重新启动抛出异常的routee并避免整个池重新启动。

1 个答案:

答案 0 :(得分:1)

必须将策略传递给池的构造函数,而不是流利的Props构建器:

   @IBAction func saveBook(sender: UIBarButtonItem) {


    var arrayOfNames : [String] = [String]()
    for i in 0 ..< 6 {
        let indexPath = NSIndexPath(forRow:i, inSection:0)
        let cell : LongNameTableViewCell? = self.tableView.cellForRowAtIndexPath(indexPath) as! LongNameTableViewCell?
        if let item = cell?.textField.text {
            arrayOfNames.append(item)
        }
    }

   self.ref.child("books").childByAutoId().setValue(["title": arrayOfNames[0], "author": arrayOfNames[1], "pages_count":arrayOfNames[2]])
   self.dismissViewControllerAnimated(true, completion: nil)

}