Cannot create actor with '$' in its name.
1. Create an actor as an embedded class of another class.
2. Using reflection get a reference to the class ('typeclass' in the following line of code) and try to call actorOf with it.
val actor = system.actorOf(Props.create(typeClass), className)
This hangs indefinitely with no feedback as to what went wrong.
2. Using reflection get a reference to the class ('typeclass' in the following line of code) and try to call actorOf with it.
val actor = system.actorOf(Props.create(typeClass), className)
This hangs indefinitely with no feedback as to what went wrong.
Leave a comment
on 2013-10-18 19:55 *
By Jamie Allen
Hi, Jonathan. Are you sure you need to do a Props.create for this? That looks like the Java API to me - you're just using Scala, right? I think you can just say this:
or
If that's not it, can you post the code of both the outer class, as well as the embedded Actor class? Or just sample code that reproduces your issue?
Thanks!
val actor = system.actorOf(Props[MyClass], myClassName)
or
val actor = system.actorOf(Props(new MyClass(<any params>)), myClassName)
If that's not it, can you post the code of both the outer class, as well as the embedded Actor class? Or just sample code that reproduces your issue?
Thanks!
Hi,
We're actually using a 3rd party reflections library (org.reflections) to get all subclasses of Actor within our current module. Then, we try to instantiate them all. The line I pasted works for all except for the nested class.
This is what we currently have (with a special case to skip the would-be nested class, ExtServerRouter):
Here's the getSubclassesOf method:
I think this code will be pretty easy to adapt to a self-contained repro and if you'd like me to do that, I'd be glad to.
Thanks!
We're actually using a 3rd party reflections library (org.reflections) to get all subclasses of Actor within our current module. Then, we try to instantiate them all. The line I pasted works for all except for the nested class.
This is what we currently have (with a special case to skip the would-be nested class, ExtServerRouter):
val actors = {
LOGGER.debug("Creating external server's set of actors.")
val subclasses = ExtServer.getSubclassesOf(classOf[ExtServerApplication].getPackage.getName, classOf[Actor])
LOGGER.debug(s"Subclasses: $subclasses")
subclasses.flatMap { typeClass =>
typeClass.getName.split("\\.").last match {
case x if x == "ExtServerRouter" => None
case className => {
LOGGER.debug(s"Calling actorOf for: $className")
val actor = system.actorOf(Props.create(typeClass), className)
LOGGER.debug(s"Created actor: $actor")
Some((typeClass.getName, actor))
}
}
}.toMap
}
Here's the getSubclassesOf method:
// HACK: (temporary): This is due to the inability, as of current, to use 'org.Reflections' directly from Scala.
public static <T> Set<Class<? extends T>> getSubclassesOf(String packageName, Class<T> clazz) {
final Reflections reflections = new Reflections(packageName);
return reflections.getSubTypesOf(clazz);
}
I think this code will be pretty easy to adapt to a self-contained repro and if you'd like me to do that, I'd be glad to.
Thanks!
Hi Jonathan,
it would help tremendously if you could attach a log for the failing run. Prime suspects are either that className is not a valid actor name (resulting in InvalidActorNameException in actorOf) or that you try to instantiate a non-static inner class without giving it a reference to its outer class as first constructor argument. Both of these would not be Akka problems.
Regards,
Roland
it would help tremendously if you could attach a log for the failing run. Prime suspects are either that className is not a valid actor name (resulting in InvalidActorNameException in actorOf) or that you try to instantiate a non-static inner class without giving it a reference to its outer class as first constructor argument. Both of these would not be Akka problems.
Regards,
Roland