It's hard to give the right suggestion from what you say here, but the
basic approach doesn't feel very "Akka-ish".  It sounds like you are trying
to hand-manage a few Actors from some linear, synchronous code, and that's
usually a recipe for trouble.  For example, the Supervisor should always be
responsible for creating its Workers, and it's pretty common for the worker
operations to route through the Supervisor.  The "external" code (outside
the Actors) should usually be pretty minimal, if any is needed at all.

But it's very hard to know from this snippet -- there isn't enough here to
even understand what the code is doing, much less what you're trying to
accomplish.  Can you describe your problem a bit better?


On Fri, Apr 25, 2014 at 8:17 AM, Nan Zhu <[email protected]> wrote:

> Hi, all
>
> I'm a newbie to akka, I have a question on the initialization process of
> akka
>
> My question comes from the following scenario
>
> class A {
>   val workerActor: ActorRef = _
>   val supervisorActor: ActorRef = actorOf(Props[B])
>
>   def work() {workerActor ! message} //NPE line
> }
>
> class B {
>   val supervisorStrategy = ...
>   def receive = {...}
>   workerActor = context.actorOf(...) //buggy line
> }
>
> it seems that the "buggy line" is executed in another thread (I think it's
> true, as I found actorOf is non-blocking since akka 2.1), so sometimes I
> will meet a NPE when the work() is called before B is fully started
>
> What I want is to block A's constructor thread until workerActor is not
> null
>
> I can send a message to supervisorActor in a blocking way and returns  a
> ActorRef from the supervisor in A's constructor, but it seems that I have
> to define a timeout Value on that blocking operation....which may involve
> some hard-coding
>
> The other option includes busy loop in A's constructor...but it's
> obviously not a first option
>
> I also saw this https://gist.github.com/viktorklang/856818, but I'm not
> sure if it is what I want
>
> Any suggestion is highly appreciated!
>
> Best,
>
> Nan
>
> --
> >>>>>>>>>> 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.
>

-- 
>>>>>>>>>>      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.

Reply via email to