Where

public @interface Where

Filters events delivered to a handler method.

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.

Filtering Events by a Field Value

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
    voidonExpired(@Where(field = "subscription.status", equals = "EXPIRED")
                     UserLoggedIn event) {
        // Handle expired subscription.
    }

   @Subscribe
    voidonInactive(@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
    voidonExpired(@Where(field = "subscription.status", equals = "EXPIRED")
                     UserLoggedIn event) {
    }

   @Subscribe
    voidonUnknownBilling(@Where(field = "payment_method.status", equals = "UNSET")
                            UserLoggedIn event) {
        // Error, different field paths used in the same class for the same event type.
    }

Functions

Link copied to clipboard
public abstract String equals()
The expected value of the field.
Link copied to clipboard
public abstract String field()
The path to the field of the event message to filter by.

Inherited functions

Link copied to clipboard
public abstract Class<? extends Annotation> annotationType()
Link copied to clipboard
public abstract boolean equals(Object p)
Link copied to clipboard
public abstract int hashCode()
Link copied to clipboard
public abstract String toString()