3

我正在考虑在我的应用程序中使用Guava EventBus将数据(Double例如)从一个或多个数据创建者分发到数据消费者。

我知道在我的消费者类中,我需要用@Subscribe. 有没有办法让这个订阅有条件?所以例如

@Subscribe {newValue > 0.0} public void valueUpdated(Double newValue)

我可以在我的valueUpdated方法中添加检查,但是有没有办法阻止EventBus发送我的订阅者不感兴趣的值?

有没有类似EventBus的产品可以提供这种功能?

4

1 回答 1

1

Spring Expression Language (SpEL) may help.

Plus: after checking the EventBus, I think it's type-based dispatch, no way to apply condition-based dispatch. If you insist on using Expression Language, you could put it in subscriber as Louis comment. But Expression Language is designed for flexibility rather than speed.

于 2012-10-05T13:17:12.607 回答