call methods on akka actors in scala

前端 未结 3 2236
甜味超标
甜味超标 2021-02-20 15:10

I have a an actor defined as so:

class nodeActor(ID: String) extends Actor

which contains a method, which is used to set up the actor before it

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 15:25

    You can cast anything to anything and the compiler will happily do so, but the check at runtime will fail if it's not possible. The ActorRef is not an instance of your Actor class or a subtype of it.

    When you do this:

    system.actorOf(Props(new nodeActor("node1")), name="node1")
    

    You get back an ActorRef to which you should only send messages. Apart from that, the actor is started immediately when you call system.actorOf, so trying to call a method on the Actor instance before it is started is not possible.

    Here is a description of actors from the Akka Docs explaining actor references.

提交回复
热议问题