【发布时间】:2016-04-19 14:49:32
【问题描述】:
我对 scala 中的 akka 和期货非常陌生。我使用 spray 来获取 URL 的输出并将 Future[String] 返回给另一个对象。这是发出 HTTP 请求的对象。
object ActionsService {
private implicit val formats = DefaultFormats
implicit val system = ActorSystem()
import system.dispatcher
val pipeline = sendReceive ~> unmarshal[String]
def getActions: Future[String] ={
val out = getOutput("http://www.google.com")
out
}
def getOutput(url: String): Future[String] ={
val response = pipeline (Get (url) )
response
}
def shutdown(code: Int): Unit = {
IO(Http).ask(Http.CloseAll)(1.second).await
system.shutdown()
}
}
这是我试图关闭actor系统的另一个对象中的主要方法。
import ExecutionContext.Implicits.global
def main(args: Array[String]) {
val test = ActionsService.getActions
test.onComplete {
case Success(x) => println(x)
case Failure(y) => println(y)
}
ActionsService.system.shutdown()
由于某种原因,akka 系统不会关闭。我还尝试使用我的 shutdown 方法关闭 akka 系统,但我得到一个 Exception in thread "main" akka.pattern.AskTimeoutException: Timed out 错误(当调用 shutdown 方法时,这也发生在 main 方法中)。
akka 版本是 2.2.3
【问题讨论】: