'Akka actor get class
Is there way to get class from which actor was created. For example, I have an actorRef or actor selection instance and I would like to get class from which existed actor is created. Thanks in advance for respond!
Solution 1:[1]
In general there's no way to do that, partly because it's not something that's likely to be useful (between patterns in classic like context.become and in typed, every actor will be of the same class as far as the runtime is concerned) and partly because it potentially (especially in non-clustered applications) allows for ways to violate the guarantees of the actor model.
In situations where you control the code of the actors in question (especially in classic or the OO-style in typed) there's nothing stopping you from adding GetClass/ClassIs messages to your actors' protocol(s), e.g. in classic (Scala):
// inside the Receive
case GetClass =>
sender ! ClassIs(getClass)
My experience is that a service with more than, say, a dozen or so actor classes in the application is a pretty strong candidate for breaking up into different services or at least a major refactor. A lot of possible actor classes responding to the same messages (thus inhibiting a simple search or IDE "find usages") also strikes me as a bit of a design smell.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
