Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional subscriptions with Guava EventBus

Tags:

java

guava

I am looking at using the Guava EventBus in my application to distribute data (Doubles for example) from one or more data creators through to data consumer.

I know in my consumer class, I need to annotate my data handler with @Subscribe. Is there a way in which to make this subscription conditional? So for example

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

I could add the check within my valueUpdated method, but is there a way to stop the EventBus from dispatching values that my Subscriber is not interested in?

Is there a product similar to EventBus that may provide this sort of function?

like image 535
Luhar Avatar asked Mar 25 '26 13:03

Luhar


1 Answers

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.

like image 151
卢声远 Shengyuan Lu Avatar answered Mar 28 '26 01:03

卢声远 Shengyuan Lu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!