Community
Participate
Working Groups
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 );
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.
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'.
Check out bug 399290 if you're interested in filtering loggers. JD
M6 has sailed. Please set a new target if still on the plan.