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.

Reply via email to