scala - preStart hook: a message to the actor itself -


let's override prestart hook , send message self:

class someactor extends actor {    override def prestart(): unit = {     self ! somemessage   }    ...  } 

can expect somemessage first message in queue?

no, since actor creation happens asynchronously might have enqueued message before constructor or prestart run. if need ensure processing of message before other you’ll need use become , stash:

self ! somemessage  def receive = initial  def initial: receive = {   case somemessage =>     // stuff     unstashall()     context become initialized   case _ => stash() }  def initialized: receive = {   // normal behavior } 

you’ll need mix in akka.actor.stash trait , configure actor use dequebasedmailbox.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -