2013-07-03 15 views
1

在java中如何找到特定的演員在阿卡

我有簡單的Web應用程序。在ServletContextListener我創建演員

ActorSystem system = ActorSystem.create("MySystem"); 
actor = system.actorOf(new Props(MyServerActor.class), "MyServer"); 
actor.tell(new StartMessage()); 

這個演員有路徑akka://MySystem/user/MyServer。然後,我嘗試從業務方法發送消息給這個演員

ActorSystem system = ActorSystem.create("MySystem"); 
client = system.actorSelection("/user/MyServer"); // same effect when use actorFor 
client.tell("OK"); 

onReceive方法:

@Override 
public void onReceive(Object message) throws Exception { 
    System.out.println(message + " : " + message); 
} 

,但我的演員沒有收到消息。它看起來像我發送到/ dev/null。

哪裏錯了?

//編輯:

我也嘗試使用完整路徑。

回答

3

好,我很愚蠢......

我創建兩個System所以無法訪問另一個人,也找不到這樣的演員了消息發送到/dev/null

2

你可以與遠程參與者嘗試:

String path = "akka://[email protected]:some-port/some/sub/path" 
ActorRef xxx = actorSystem.actorFor(path); 

另外,如果您訂閱deadLetters()actor以記錄未處理的消息,那將會更好。

final ActorRef actor = actorSystem.actorOf(new Props(DefaultDeadLetterHandlerActor.class)); 
actorSystem.eventStream().subscribe(actor, DeadLetter.class); 

也許只是簡單地記錄它們。