@Retention(value=RUNTIME)
@Target(value=PARAMETER)
@Documented
public @interface Where
To apply filtering to an event handler method, annotate the first parameter of the method.
For example, the following method would be invoked only if the owner of the created
project is [email protected]
:
@Subscribe void on(@Where(field = "owner.email", equals = "[email protected]") ProjectCreated e) { ... }
Annotations for handler methods which support @Where
should be marked with
AcceptsFilters
.
If a field filter is defined, only the events matching this filter are passed to the handler method.
A single class may define a number of handler methods with different field filters. Though, all the field filters must target the same field. For example, this event handling is valid:
@Subscribe void onExpired(@Where(field = "subscription.status", equals = "EXPIRED") UserLoggedIn event) { // Handle expired subscription. } @Subscribe void onInactive(@Where(field = "subscription.status", equals = "INACTIVE") UserLoggedIn event) { // Handle inactive subscription. } @Subscribe void on(UserLoggedIn event) { // Handle other cases. }
And this one is not:
@Subscribe void onExpired(@Where(field = "subscription.status", equals = "EXPIRED") UserLoggedIn event) { } @Subscribe void onUnknownBilling(@Where(field = "payment_method.status", equals = "UNSET") UserLoggedIn event) { // Error, different field paths used in the same class for the same event type. }