So, if I have an actor, I can give it a name. But, can I access that name internally? Example:
class Actorz extends Actor with ActorLogging { val actorName = //??What function def receive = { case x => log.debug(actorName+": Received Message: "+x) } } val actor = system.actorOf(Props[Actorz], "named") actor ! "dogs"
Now, I can pass its name as a constructor parameter. But, that seems like unnecessary duplication if there is a way to get the name internally... as it was set when I instantiated the actor using system.actorOf
. API docs didn't seem to have anything.
Akka ensures that each instance of an actor runs in its own lightweight thread and that messages are processed one at a time. In this way, each actor's state can be reliably maintained without the developer needing to explicitly worry about synchronization or race conditions.
Spring, Scala, Erlang, Kafka, and Spring Boot are the most popular alternatives and competitors to Akka.
The ActorSystem is a root actor in actors structure. An ActorSystem is a hierarchical group of actors which share common configuration, e.g. dispatchers, deployments, remote capabilities and addresses. It is also the entry point for creating or looking up actors.
From an Actor
you can use self
to get the ActorRef
.
val actorName = self.path.name
http://doc.akka.io/api/akka/2.2.3/#akka.actor.Actor
http://doc.akka.io/api/akka/2.2.3/#akka.actor.ActorRef
http://doc.akka.io/api/akka/2.2.3/#akka.actor.ActorPath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With