Hi all,
Last week I succesfully ported my project from akka 1.0 to 1.1. I was hit by one issue however: it appeared that in our application some actors were instantiated in the following way:
val nestedActor = actorOf(new OuterActor(actorOf(new InnerActor).start)).start
This works in 1.0, but fails in 1.1 with the error
Exception in thread "main" akka.actor.ActorInitializationException: ActorRef for instance of actor [org.ulysses.investing.routing.OuterActor] is not in scope.
You can not create an instance of an actor explicitly using 'new MyActor'.
You have to use one of the factory methods in the 'Actor' object to create a new actor.
Either use:
'val actor = Actor.actorOf[MyActor]', or
'val actor = Actor.actorOf(new MyActor(..))'
This is likely to be the result of this ticket:
http://www.assembla.com/spaces/akka/tickets/757. As far as I could see, the reason for this is that the current implementation the initialization order is such that the
actorRefInCreation threadlocal that is used to track the current ActorRef is first set twice, first by the ActorRef of OuterActor, and after that by the ActorRef of InnerActor. After creaton of the InnerActor the threadlocal is cleared, causing the subsequent initialization of OuterActor to fail.
This is fair enough, but to me it was not immediately apparent that the above code is invalid, since the actors seamed to be created the 'legal' way, and the error message was slightly confusing me.
To make a long story short: assuming that this is indeed the intended behaviour, can the error message and/or documentation be updated to include this case? This will save people running into the same issue some debugging time, I reckon.
Cheers, Arjan