Hi Lucas
In your example I assume you're not using any state from the future to
modify your actor (that would be against the actor contract)?
My assumption is that you either want to have the mail processing happen
with a different execution context (thread pool) since it is IO-bound an
probably blocking OR you don't want to block your actor during the mail
sending process and instead free up the actor to continue processing the
next message.
If it is the first case you are out of luck in using a supervisor as the
exception is not thrown to the surrounding actor in the first place, but
you can still use the onComplete method.
val snd = sender
case SendMail( ... ) => Future( sendMail( ... ) ).onComplete {
case Success( _ ) => snd ! Success
case Failure( ex:MailException ) => log.error( ... ); snd ! Failure
case Failure( ex ) => log.error( ...., ex ); snd ! Failure
}
This works but you can still get into trouble if you try to change the
state of the actor since the actor have moved on at that point.
In the second case the Akka-way of doing it would be to spawn a child actor
where you do your computation without a future. You can then supervise that
actor but still free up your parent actor to process new messages that in
turn spawns new child actors. Remember let the children do the dangerous
stuff!
/Magnus
Den måndagen den 30:e december 2013 kl. 23:49:05 UTC+1 skrev Lucas
Batistussi:
>
> What I have to do to still support fault tolerance when using Future as
> shown in code below?
>
> ...
> override def receive = {
>
> case email: Email => Future {
>
> // Suppose here I got an exception. Without "Future", supervisor
> strategy
> // works well restarting the actor
> throw new MailException("ops!")
>
> }
> }
>
> Supervisor Strategy:
>
> ...
> withSupervisorStrategy(
> OneForOneStrategy(
>
> // Max number of retries
> maxNrOfRetries = retries,
> // Time Window
> withinTimeRange = timeRange) {
>
> case ex: MailException => {
> Restart
> }
> }))
>
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> 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/groups/opt_out.