Optional filtering on incoming events to target specific event handlers
Filtering
The goal is to support rules at the EventHandler to filter the event instances dispatched by the SEP to an event handler method.
Fluxtion allows filtering of event dispatch so that only event handlers that match certain criteria will receive the dispatched event. The filtering rules that Fluxtion supports are:
By event type
By event type and event value
By event type and unmatched against event value
Event filtering is statically generated at compile time and cannot be altered at runtime
The EventHandler annotation allows optional arguments for setting match filters. An incoming event can specify a filter value as either a String or an integer at runtime, whereas the event handler filter value is fixed at compile time. If the filter value of the incoming event matches that of the event handler then a dispatch will occur. The base class Event provides member variables for filter string and filter int.
The following example demonstrates String filtering for a configuration event:
Fluxtion also supports the unmatched filter case or the default branch in a case statement. Unlike a no filter that is always invoked, the unmatched filter is only invoked if there are no matches on any specified filter. The example below demonstrates a method, unHandledConfig that is invoked if there is an unknown config received.
publicclassMyEventProcessor {//previous handlers omitted for clarity @EventHandler(FilterType.unmatched)publicvoidunHandledConfig(ConfigEvent event) {}}
Generated SEP
The following SEP is produced demonstrating the unmatched filter or default case:
Strings as filter values can lead to fragile api's especially when refactoring. To combat this a class literal can be supplied as a filter value in the EventHandler, Fluxtion converts the class literal to a String and filters by String in the generated SEP, as shown in the example below:
publicclassMyEventProcessor {//previous handlers omitted for clarity @EventHandler(filterStringFromClass =Date.class)publicvoiddateConfig(ConfigEvent event) {}}
Generated SEP
Notice the class literal used in line 23, producing the following generated SEP:
The value of the filter in the eventhandler method can be provided from an instance variable in the eventhandler node. This instance variable is read once at compile time for the generation phase. A string match between the