scala - 使用包含 self 类型的 Prop 创建 Actor

标签 scala akka traits

我正在努力寻找创建具有 self 类型的转换的新方法。

假设我有一个 Actor

trait BarPolicy {
  val maxDrinksNumber:Int
}

trait ProductionPolicy extends BarPolicy {
  val maxDrinksNumber = 5
}

object FooActor { 
   def apply()  = new FooActor with ProductionPolicy 
}

class FooActor extends Actor {
   this: BarPolicy =>
}

有了该代码,我可以编写如下内容:

context.actorOf(Props(FooActor()))

现在这已被弃用,我只是找不到另一种方法来正确执行此操作。

根据 akka 的建议,“apply()”方法现在应该看起来像这样:

def apply() : Props = Props(classOf[FooActor])

但是我可以把 mixin 放在哪里呢?

最佳答案

object FooActor { 
  private class ProductionFooActor extends FooActor with ProductionPolicy
  def apply() : Props = Props(classOf[ProductionFooActor])
}

也许是这样的?

关于scala - 使用包含 self 类型的 Prop 创建 Actor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20957743/

相关文章:

scala - 列表中的 groupBy 作为 LinkedHashMap 而不是 Map

scala - AKKA HTTP 源流与 Futures

templates - 检查类成员是否是静态的

Scala:让特质依赖于其他特质

scala:定义特征并引用相应的伴生对象

scala - spark 中的自定义输入阅读器

java - Play Framework 在使用空值的 Web 服务调用期间从 URL 中剥离 "="(导致结束点出现 500 错误)

scala - 如何在 ScalaTest 中使测试失败并打印堆栈跟踪?

scala - akka中的Actor创建错误

f# - 如何使用 F# 在 Akka.Remote 中发送带有元组的消息?