2016-04-19 10 views
0

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

答えて

0

答えは上記のように私はshutdownメソッドが呼び出される前に、メインメソッドのスリープ期間を追加することにより、スレッドをブロックしなければならなかった私のために働いてしまうしませんでした。

def main(args: Array[String]) { 
    val test = ActionsService.getActions 
    Thread.sleep(700) 
test.onComplete { 
    case Success(x) => println(x) 
    case Failure(y) => println(y) 
} 
CorporateActionsService.system.shutdown() 

} 
0

です例)

Await.ready(system.whenTerminated, Duration.Inf) 
+0

アッカのバージョンは2.2.3であり、私は終了していない一見決してActionsService.system.awaitTerminationは()も、これらの方法は、2.2.3に存在してはいけない – Zee

+0

..試してみました – Zee

関連する問題