title: Akka matching Failures, and recovery
body: <p>Stuff I need help with is in bold.</p>
  
  <p>I have an actor that is flying multiple spray HttpRequests, the requests are paginated and the actor makes sure it writes the results in sequence into a database (sequence is important to resume crawlers). I explain this because I don't want to explore other patterns of concurrency at the moment. The actor needs to recover from timeouts without restarting.</p>
  
  <p>in my actor I have the following : </p>
  
  <pre><code>            case f : Failure =&gt; {
                  system.log.error("faiure")
                  system.log.error(s"$f")
                  system.shutdown()
              }
              case f : AskTimeoutException =&gt; {
                  system.log.error("faiure")
                  system.log.error(s"$f")
                  system.shutdown()
              }
              case msg @ _ =&gt; {
  
                  system.log.error("Unexpected message in harvest")
                  system.log.error(s"${msg}")
                  system.shutdown()
              }
  </code></pre>
  
  <p><strong>but I can't match correctly :</strong></p>
  
  <pre><code>[ERROR] [11/23/2013 14:58:10.694] [Crawler-akka.actor.default-dispatcher-3] [ActorSystem(Crawler)] Unexpected message in harvest
  [ERROR] [11/23/2013 14:58:10.694] [Crawler-akka.actor.default-dispatcher-3] [ActorSystem(Crawler)] Failure(akka.pattern.AskTimeoutException: Timed out)
  </code></pre>
  
  <p>My dispatches look as follows : </p>
  
  <pre><code>abstract class CrawlerActor extends Actor {
    private implicit val timeout: Timeout = 20.seconds
    import context._
    def dispatchRequest(node: CNode) {
      val reqFut = (System.requester ? CrawlerRequest(node,Get(node.url))).map(r=&gt; CrawlerResponse(node,r.asInstanceOf[HttpResponse]))
      reqFut pipeTo self
    }
  
  
  class CrawlerRequester extends Actor  {
    import context._
    val throttler = context.actorOf(Props(classOf[TimerBasedThrottler],System.Config.request_rate),"throttler")
    throttler ! SetTarget(Some(IO(Http).actorRef))
  
    def receive : Receive = {
      case CrawlerRequest(type_,request) =&gt; {
        throttler forward request
      }
    }
  }
  </code></pre>
  
  <p><strong>Once I find the correct way of matching, is there anyway I can get my hands on the CrawlerRequest that the timeout occurred with ? it contains some state I need to figure out how to recover.</strong></p>