Using event.filter to register to event topics [message #1711207] |
Wed, 14 October 2015 07:08 |
|
Dear list,
I am trying to use the event.filter property of a component to register a handler to 1+ events.
I am aware that wildcards can be used in the event.topics property in order to register to more events, but I would rather use a filter for my case.
I started with an OR LDAP-encoded selection ("(|(k1=v1)(k2=v2))"), and that did not work.
I stepped back to the basic single-event registration via filter, using event.topics as filter key, and the name of the topic as value, like in the following example:
<property name="event.filter" type="String" value="(event.topics=FILTERED_TOPIC)"/>
Still the listener is ignored.. v_v
Any hint on what the mistake is?
Thanks a lot.
[Updated on: Wed, 14 October 2015 07:22] Report message to a moderator
|
|
|
|
|
|
Re: Using event.filter to register to event topics [message #1711238 is a reply to message #1711220] |
Wed, 14 October 2015 09:10 |
|
Dear Dirk,
(where did you read about the FILTERED_TOPIC keyword?)
Regarding your question: I get no OSGi warning nor an org.osgi.framework.InvalidSyntaxException which would be thrown with illegal filters.
I added now the event.topics property, with value FILTERED_TOPIC but the listener is still silently ignored.
|
|
|
|
Re: Using event.filter to register to event topics [message #1711333 is a reply to message #1711243] |
Thu, 15 October 2015 06:21 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
From EventBroker:
> @Override
> public boolean subscribe(String topic, String filter, EventHandler eventHandler, boolean headless) {
> BundleContext bundleContext = Activator.getDefault().getBundleContext();
> if (bundleContext == null) {
> if (logger != null) {
> logger.error(NLS.bind(ServiceMessages.NO_BUNDLE_CONTEXT, topic));
> }
> return false;
> }
> String[] topics = new String[] {topic};
> Dictionary<String, Object> d = new Hashtable<String, Object>();
> d.put(EventConstants.EVENT_TOPIC, topics);
> if (filter != null)
> d.put(EventConstants.EVENT_FILTER, filter);
> EventHandler wrappedHandler = new UIEventHandler(eventHandler, headless ? null : uiSync);
> ServiceRegistration<?> registration = bundleContext.registerService(
> EventHandler.class.getName(), wrappedHandler, d);
> Collection<ServiceRegistration<?>> handled = registrations
> .get(eventHandler);
> if (handled == null) {
> registrations.put(eventHandler,
> handled = new ArrayList<ServiceRegistration<?>>());
> }
> handled.add(registration);
> return true;
> }
So Dirk is right event.topics does NOT use ldap topic filters but eg you
use "event.topics=my/simple/*/valueChange"
Tom
On 14.10.15 11:22, Dirk Fauth wrote:
> Quote:
>> (where did you read about the FILTERED_TOPIC keyword?)
>
>
> You posted it in your initial post. I assume you need to replace
> FILTERED_TOPIC with a real topic. Or do I missunderstand what you are
> trying to achieve?
>
> Looking at your initial post, you are trying to create one EventHandler
> for several topics. AFAIK this is achieved by a hierarchy using
> wildcards on the topic. I never heard of creating a filter that applies
> to topics, nor could I find something similar on the web.
>
> That said, either you need to rethink your topic hierarchy or the way
> you want to handle events.
|
|
|
Re: Using event.filter to register to event topics [message #1711334 is a reply to message #1711333] |
Thu, 15 October 2015 06:22 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Sorry hit the reply to early you code needs to look like this
<property name="event.topic" type="String" value="my/simple/*/valueChange"/>
Tom
On 15.10.15 08:21, Tom Schindl wrote:
> From EventBroker:
>
>> @Override
>> public boolean subscribe(String topic, String filter, EventHandler eventHandler, boolean headless) {
>> BundleContext bundleContext = Activator.getDefault().getBundleContext();
>> if (bundleContext == null) {
>> if (logger != null) {
>> logger.error(NLS.bind(ServiceMessages.NO_BUNDLE_CONTEXT, topic));
>> }
>> return false;
>> }
>> String[] topics = new String[] {topic};
>> Dictionary<String, Object> d = new Hashtable<String, Object>();
>> d.put(EventConstants.EVENT_TOPIC, topics);
>> if (filter != null)
>> d.put(EventConstants.EVENT_FILTER, filter);
>> EventHandler wrappedHandler = new UIEventHandler(eventHandler, headless ? null : uiSync);
>> ServiceRegistration<?> registration = bundleContext.registerService(
>> EventHandler.class.getName(), wrappedHandler, d);
>> Collection<ServiceRegistration<?>> handled = registrations
>> .get(eventHandler);
>> if (handled == null) {
>> registrations.put(eventHandler,
>> handled = new ArrayList<ServiceRegistration<?>>());
>> }
>> handled.add(registration);
>> return true;
>> }
>
> So Dirk is right event.topics does NOT use ldap topic filters but eg you
> use "event.topics=my/simple/*/valueChange"
>
> Tom
>
> On 14.10.15 11:22, Dirk Fauth wrote:
>> Quote:
>>> (where did you read about the FILTERED_TOPIC keyword?)
>>
>>
>> You posted it in your initial post. I assume you need to replace
>> FILTERED_TOPIC with a real topic. Or do I missunderstand what you are
>> trying to achieve?
>>
>> Looking at your initial post, you are trying to create one EventHandler
>> for several topics. AFAIK this is achieved by a hierarchy using
>> wildcards on the topic. I never heard of creating a filter that applies
>> to topics, nor could I find something similar on the web.
>>
>> That said, either you need to rethink your topic hierarchy or the way
>> you want to handle events.
>
|
|
|
Re: Using event.filter to register to event topics [message #1711335 is a reply to message #1711334] |
Thu, 15 October 2015 06:25 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
hm but further down the event.filter should work as well if i read the
description correct because the filter is applied to the
event-properties and event.topics is clearly a property.
Tom
On 15.10.15 08:22, Tom Schindl wrote:
> Sorry hit the reply to early you code needs to look like this
>
> <property name="event.topic" type="String" value="my/simple/*/valueChange"/>
>
> Tom
>
> On 15.10.15 08:21, Tom Schindl wrote:
>> From EventBroker:
>>
>>> @Override
>>> public boolean subscribe(String topic, String filter, EventHandler eventHandler, boolean headless) {
>>> BundleContext bundleContext = Activator.getDefault().getBundleContext();
>>> if (bundleContext == null) {
>>> if (logger != null) {
>>> logger.error(NLS.bind(ServiceMessages.NO_BUNDLE_CONTEXT, topic));
>>> }
>>> return false;
>>> }
>>> String[] topics = new String[] {topic};
>>> Dictionary<String, Object> d = new Hashtable<String, Object>();
>>> d.put(EventConstants.EVENT_TOPIC, topics);
>>> if (filter != null)
>>> d.put(EventConstants.EVENT_FILTER, filter);
>>> EventHandler wrappedHandler = new UIEventHandler(eventHandler, headless ? null : uiSync);
>>> ServiceRegistration<?> registration = bundleContext.registerService(
>>> EventHandler.class.getName(), wrappedHandler, d);
>>> Collection<ServiceRegistration<?>> handled = registrations
>>> .get(eventHandler);
>>> if (handled == null) {
>>> registrations.put(eventHandler,
>>> handled = new ArrayList<ServiceRegistration<?>>());
>>> }
>>> handled.add(registration);
>>> return true;
>>> }
>>
>> So Dirk is right event.topics does NOT use ldap topic filters but eg you
>> use "event.topics=my/simple/*/valueChange"
>>
>> Tom
>>
>> On 14.10.15 11:22, Dirk Fauth wrote:
>>> Quote:
>>>> (where did you read about the FILTERED_TOPIC keyword?)
>>>
>>>
>>> You posted it in your initial post. I assume you need to replace
>>> FILTERED_TOPIC with a real topic. Or do I missunderstand what you are
>>> trying to achieve?
>>>
>>> Looking at your initial post, you are trying to create one EventHandler
>>> for several topics. AFAIK this is achieved by a hierarchy using
>>> wildcards on the topic. I never heard of creating a filter that applies
>>> to topics, nor could I find something similar on the web.
>>>
>>> That said, either you need to rethink your topic hierarchy or the way
>>> you want to handle events.
>>
>
|
|
|
Re: Using event.filter to register to event topics [message #1711338 is a reply to message #1711335] |
Thu, 15 October 2015 06:36 |
|
I was trying to register a handler to 2 topics coming from different branches of my event taxonomy and I thought it could be possible with some LDAP filtering; the javadoc of EVENT_FILTER says a handler "MAY be registered" with this property.
I am creating 2 regular 1-topic components pointing to the same handler now as workaround.
Thanks to both for trying to help. If there is something you believe I could test, just let me know.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05400 seconds