title: Akka Actor hotswapping using rest api
body: <p>Upon calling a rest api, I would want to switch the actor's routing to another routes.
  Please see the below code. </p>
  
  <p>Couple of questions:</p>
  
  <ol>
  <li>The code compiles fine but when the app is started and a http call is made, I get Configured registration timeout of 1 second expired, stopping message and i dont get any response from server.</li>
  <li>I want to be able to switch routing to another set of routes through api.</li>
  </ol>
  
  <p>made</p>
  
  <pre><code>package com.example
  import akka.actor.Actor
  import akka.io.IO
  import spray.httpx.RequestBuilding._
  import spray.http.MediaTypes._
  import spray.routing.{RoutingSettings, RejectionHandler, ExceptionHandler, HttpService}
  import spray.util.LoggingContext
  import scala.concurrent.Future
  import spray.can.Http
  import spray.http._
  import akka.util.Timeout
  import HttpMethods._
  import akka.pattern.ask
  import akka.event.Logging
  import scala.concurrent.duration._
  
  case object Swap
  class MyServiceActor extends Actor with MyService with akka.actor.ActorLogging {
  
    implicit def actorRefFactory = context
    import context._
  
    def receive = {
        case Swap =&gt;
             become {
               case Swap =&gt; unbecome()
               case _    =&gt; runRoute(otherRoutes)
             }
        case _ =&gt;   runRoute(myRoute)
    } 
  }
  
  
  trait MyService extends HttpService { this: MyServiceActor =&gt;
  
    implicit val timeout: Timeout = Timeout(15.seconds)
  
    implicit val system = context.system
  
    val myRoute =
    {
      path("") {
        get {
            complete("MyRoute")
        }
      } ~ path("swap") {
  
          get{
              self ! Swap
              complete("Swapped")
          }
      }
    }
  
    val otherRoutes =path("") {
    get {
        complete("OtherRoutes")
       }
     } ~ path("swap") {
          get{
          self ! Swap
          complete("Reverted")
       }
  }
  
  }
  </code></pre>