私はakkaが初めてなので、イベントバスにイベントを追加して呼び出されたものをキャッチする方法を知りたいです。コードサンプルあり。
localEventBus = new com.google.common.eventbus.EventBus(new ExceptionHandler());
Object listener = new Object()
{
@Subscribe
public void witingCommand(SomeCommand cmd)
{
//Here I want to catch call
}
};
...
localEventBus.register(listener);
...
client = system.actorOf(Props.create(ClientActor.class, localEventBus, receptionists));
...
client.tell(new Publish(Constants.COMMAND, someCommand), noSender());
種類:
private final ActorSystem system;
private ActorRef client;
ClientActor.java
final class ClientActor extends UntypedActor
{
ClientActor(final EventBus eventBus, final List<ActorSelection> receptionists)
{
localEventBus = eventBus;
clusterReceptionists.addAll(receptionists);
}
@Override
public void preStart()
{...}
@Override
public void postStop()
{...}
@Override
public void onReceive(final Object msg)
{...}
}
問題は、「witingCommand」が呼び出されていないことです。誰かが私が間違っていることを教えてくれるでしょうか?