2012-09-07 6 views
5

액터를 시작하고 액터를 시작하고 실행을 종료하는 샘플 코드를 작성했습니다.올바르게 스칼라에서 akka 액터를 종료하십시오.

object PureAkka { 
    def main(argv : Array[String]) = { 
    val actorSystem : ActorSystem = ActorSystem("main") 
    val actor : ActorRef = actorSystem.actorOf(Props(new Actor { 
     override def receive = { 
     case x => println(x) 
     } 
     override def preStart() = println("prestart") 
     override def postStop() = println("poststop") 
    })) 
    Thread.sleep(15000) 
    actor ! PoisonPill 
    } 
} 

이 코드를 인쇄 :

[info] prestart 
[info] poststop 

그러나 내가 Ctrl-C를

어떤 애플리케이션 대기 않습니다와 프로세스를 종료 할 때까지 중단하기를 거부? 적절한 방법으로 어떻게 멈출 수 있습니까?

+2

Akka 설명서는 http://doc.akka.io/api/akka/2.0.3/#akka.actor.Actor에서 'context.stop'이라고 말하면 도움이 될 수 있습니다. –

답변

8

아마도 ActorSystem.shutdown()을 호출하면이 트릭을 수행하게됩니다. akka docs에 따르면

:

추상적 인 데프 shutdown(): Unit

정지이 액터 시스템. 그러면 보호자가 중지되고 모든 하위 액터가 재귀 적으로 중지되고 시스템 보호자 (그 아래에서 로깅 액터가 상주합니다)와 등록 된 모든 종료 처리기가 실행됩니다 (ActorSystem.registerOnTermination 참조).

+1

참고 사항 : [Akka 2.4 현재] (http://doc.akka.io/docs/akka/snapshot/project/migration-guide-2.3.x-2.4.x.html#Actor_system_shutdown) 'ActorSystem .terminate()'. 이것은 당신이 기다릴 수있는'Future [Terminated]'를 반환합니다. – 203

관련 문제