Bug 399161 - Add Event Filter annotation for UIEventTopic and EventTopic
Summary: Add Event Filter annotation for UIEventTopic and EventTopic
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-26 08:37 EST by Alex Blewitt CLA
Modified: 2013-04-23 09:41 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Blewitt CLA 2013-01-26 08:37:02 EST
It is possible to add a filter to events using the EVENT_FILTER property of the event subscription.

@Qualifier
@Documented
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface EventFilter {
  String value() default ""; // ldap filter as for EVENT_FILTER
}

If specified the values would be applied to the event properties, e.g.

@Inject
@Optional
handle(
@EventTopic("my/topic") @EventFilter("(&(user=*)(priority=high))") Event event
);
Comment 1 Alex Blewitt CLA 2013-01-26 08:45:19 EST
I think the code that would need to be updated is here:

public class EventObjectSupplier extends ExtendedObjectSupplier {

	private void subscribe(String topic, EventAdmin eventAdmin, IRequestor requestor) {

		Dictionary<String, Object> d = new Hashtable<String, Object>();
		d.put(EventConstants.EVENT_TOPIC, topics);
		EventHandler wrappedHandler = makeHandler(topic, requestor);
		ServiceRegistration registration = bundleContext.registerService(EventHandler.class.getName(), wrappedHandler, d);


When registering the service, if you have an EVENT_FILTER you can set it here:

if(eventFilter != null && !eventFilter.equals("")) {
  d.put(EventConstants.EVENT_FILTER,eventFilter);
}

How you get the eventFilter from the annotation to this method, I'm not quite sure. Perhaps something like:

	protected String getFilter(IObjectDescriptor descriptor) {
		if (descriptor == null)
			return null;
		EventFilter qualifier = descriptor.getQualifier(EventFilter.class);
		return qualifier.value();
	}

and then in the get() method, something like:

                String eventFilter = getFilter(descriptor);

		if (track) 
			subscribe(topic, eventFilter, eventAdmin, requestor);

However, my understanding of the way it all works remains to be seen.
Comment 2 Alex Blewitt CLA 2013-01-28 15:02:04 EST
It occurred to me after filing that the concept of Filter could be applied to other places, not just events. For example, one might have:

@Inject
@Filter("(logserver=remote)")
Logger logger;

which would then ask to inject a Logger.class service which met the given LDAP style filter. Of course, that implementation is much further off than the event specific case, but it might suggest a more generic annotation name than 'EventFilter'.
Comment 3 Joseph Carroll CLA 2013-01-29 08:47:36 EST
Check out bug 399290 if you're interested in filtering loggers.

JD
Comment 4 Dani Megert CLA 2013-04-23 09:41:31 EDT
M6 has sailed. Please set a new target if still on the plan.