简体   繁体   English

Guava eventbus有订阅者吗?

[英]Guava eventbus are there any subscribers?

Is it possible to detect if an Guava Eventbus has one or more subscribers for a specific event? 是否可以检测Guava Eventbus是否具有一个或多个特定事件的订阅者?

I'm using Guava EventBus to broadcast received messages through the application. 我正在使用Guava EventBus通过应用程序广播接收到的消息。 Sometimes i forget to register a class or forget the @Subscribe annotation. 有时我忘记注册一个类或忘记@Subscribe批注。

It would be nice if i could detect this and write a warning to the log, but while going through the javadocs i couldn't find an lead. 如果我能检测到并向日志写警告,那将是很好的选择,但是在通过javadocs时我找不到线索。

Going through the javadocs did the trick: DeadEvent https://google.github.io/guava/releases/23.0/api/docs/com/google/common/eventbus/DeadEvent.html 通过javadocs可以达到目的:DeadEvent https://google.github.io/guava/releases/23.0/api/docs/com/google/common/eventbus/DeadEvent.html

@Subscribe
  public void handleDeadEvent(DeadEvent deadEvent) {
    log.debug("no subscribers!: "+deadEvent);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM