0

我有几个这样定义的akka​​-actors:

object SomethingActor {
  val name: String = "somethingActor"
  def props: Props = Props(new SomethingActor())
}

class somethingActor extends Actor {
  verride def receive: Receive = ???
}

// somewhere else
final val myActor = actorSystem.actorOf(SomethingActor.props, SomethingActor.name)

在这些演员中,在我的应用程序的任何给定时刻,最多只有一个瞬间是“活着的”,因此,例如,只有在旧的演员死SomethingActor了时才能创建新的演员。SomethingActor

现在,我不认为像这样定义演员名称:val name: String = "somethingActor"很好,所以我一直想知道我是否可以使用这样的东西:

object SomethingActor {
  val name: String = this.getClass.getName
  def props: Props = Props(new SomethingActor())
}

这会被认为是不好的做法吗?有没有更好的方法来处理这个?我(想我)需要将名称保存在伴生对象中,以便能够使用ActorSystem.actorSelection(path: String)docu)从我的程序中的另一个点搜索演员。

4

0 回答 0