Hi Guido, you’re thinking too complicated :-) What we do in Akka internally needs to be regarded with a spoonful of salt (a.k.a. low-level knowledge of concurrency and Akka’s internal design). The rule is quite simple: never call an Actor’s methods—any of them—from outside of that Actor’s execution. In more detail the problem you’re overlooking is not the call to context() but the invocation of child(). Sending the result of calling self() to another Actor, though, is entirely fine because the returned ActorRef is a data type that supports that, just like purely immutable data types (i.e. messages).
Regards, Roland > 11 jun 2015 kl. 18:38 skrev Guido Medina <[email protected]>: > > Hi Dr. Roland, > > Sorry for being annoying over here :D > > In Akka 2.3.11 self() for example is context.self() and context below, > doesn't that make self() also dangerous to be send to another thread outside > Akka? > It looks to me that these chances are also valid for self(), isn't all about > calling context() early, by early I mean before you do anything at all? > That being the case, doesn't extracting a variable for context before using > it makes it safe? Maybe it is not appropriate to do it, > then I guess the only safe bet is to extract self() to a variable but that > looks to me is exactly as extracting context() to a variable, right? > > implicit val context: ActorContext = { > val contextStack = ActorCell.contextStack.get > if ((contextStack.isEmpty) || (contextStack.head eq null)) > throw ActorInitializationException( > s"You cannot create an instance of [${getClass.getName}] explicitly > using the constructor (new). " + > "You have to use one of the 'actorOf' factory methods to create a > new actor. See the documentation.") > val c = contextStack.head > ActorCell.contextStack.set(null :: contextStack) > c > } > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/> > >>>>>>>>>> Check the FAQ: > >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html> > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > >>>>>>>>>> <https://groups.google.com/group/akka-user> > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at http://groups.google.com/group/akka-user > <http://groups.google.com/group/akka-user>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. Dr. Roland Kuhn Akka Tech Lead Typesafe <http://typesafe.com/> – Reactive apps on the JVM. twitter: @rolandkuhn <http://twitter.com/#!/rolandkuhn> -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
