So, is your recommendation as I have it, to be in "loading" and handle 
"akka.status.Failure" there.  I could decide at that point how to handle 
the failure, with the typical case being to throw the exception and let my 
parent figure out what to do with me.

On Friday, February 5, 2016 at 9:43:47 AM UTC-5, Guido Medina wrote:
>
> preStart method always executes before the 1st message is consumed so you 
> don't need both at the same time unless you have to wait for another thing 
> to happen hence handling states as you are in your example.
>
> On Friday, February 5, 2016 at 2:42:36 PM UTC, Guido Medina wrote:
>>
>> preStart is your friend, but also make sure you create these children in 
>> another dispatcher, preStart is my preferred way, another way is an actor 
>> with stash, with stash will give you less performance as the mailbox has 
>> different requirements and the code will be less readable.
>>
>> HTH,
>>
>> Guido.
>>
>> On Friday, February 5, 2016 at 2:07:24 PM UTC, Paul Cleary wrote:
>>>
>>> I am trying to figure out the best way to load actor state from a 
>>> database.  The actor could be a child actor of another.
>>>
>>> From what I have found, something like this would work:
>>>
>>> class MyActor extends Actor with Stash {
>>>   
>>>   var data: Data = _
>>>
>>>   // start the actor in a loading state
>>>   def receive = loading
>>>
>>>   def loading: Receive = {
>>>     case Loaded(data) =>
>>>       unstashAll()
>>>       become(ready, false)
>>>
>>>     case _ => stash()
>>>   }
>>>
>>>   def ready: Receive = {
>>>     case _ => "hi :)"
>>>   }
>>>
>>>   override def preStart() = {
>>>     db.load().map(Loaded) pipeTo self
>>>   }
>>> }
>>>
>>>
>>> so my problem is in dealing with failure, what to do if db.load fails? 
>>>  If db.load is a Future?
>>>
>>> What I want to happen is something like the `BackoffSupervisor` where we 
>>> restart with a backoff.  You can imagine that if there were a network / db 
>>> issue that it could take time to recover.  We should see the actor "trying" 
>>> to restart.
>>>
>>> Does it make sense to simply throw the error to force the restart?  As 
>>> in the following example...
>>>
>>>   def loading: Receive = {
>>>     case Loaded(data) =>
>>>       unstashAll()
>>>       become(ready, false)
>>>
>>>     case akka.status.Failure(e) => throw e
>>>
>>>     case _ => stash()
>>>   }
>>>
>>>
>>> Thanks!
>>> Paul
>>>
>>

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to