akaと先物はスカラで非常に新しいです。私はスプレーを使ってURLの出力を取得し、別のオブジェクトにFuture[String]
を返します。 HTTPリクエストを作成しているオブジェクトは次のとおりです。akkaシステムからスプレーでシステムをシャットダウン
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()
}
}
ここでは、アクターシステムをシャットダウンしようとしている他のオブジェクトの主な方法があります。
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システムをシャットダウンしようとしましたが、シャットダウンメソッドが呼び出されたときにメインメソッドでも発生するException in thread "main" akka.pattern.AskTimeoutException: Timed out
エラーが発生します。
アッカバージョンは、あなたが使用しているアッカのバージョンを指定しませんでしたが、最後のバージョンでは、あなたがお尻(代わりに
system.terminate()
を呼び出すと、このような終了を待つ必要がある2.2.3
アッカのバージョンは2.2.3であり、私は終了していない一見決してActionsService.system.awaitTerminationは()も、これらの方法は、2.2.3に存在してはいけない – Zee
..試してみました – Zee