Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » Using event.filter to register to event topics
Using event.filter to register to event topics [message #1711207] Wed, 14 October 2015 03:08 Go to next message
Eclipse UserFriend
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 03:22] by Moderator

Re: Using event.filter to register to event topics [message #1711210 is a reply to message #1711207] Wed, 14 October 2015 03:19 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, but I don't understand what you are doing. Are you creating an OSGi declarative service and try to use it as an event listener?
Re: Using event.filter to register to event topics [message #1711211 is a reply to message #1711210] Wed, 14 October 2015 03:24 Go to previous messageGo to next message
Eclipse UserFriend
Sorry Dirk, I just meant I declared an event handler via component model, not programmatically. Forget DS (corrige applied).

[Updated on: Wed, 14 October 2015 03:24] by Moderator

Re: Using event.filter to register to event topics [message #1711220 is a reply to message #1711211] Wed, 14 October 2015 03:53 Go to previous messageGo to next message
Eclipse UserFriend
From the EventHandler javadoc

Quote:
If the syntax of this filter is invalid, then the Event Handler must be ignored by the Event Admin service. The Event Admin service should log a warning.


Do you see a warning?

On the other hand, is that the correct approach to filter for the event topic? Shouldn't you use event.topic as property and FILTERED_TOPIC as value? This way you should only receive events for that topic. There should be no additional filter involved for such a case.
Re: Using event.filter to register to event topics [message #1711238 is a reply to message #1711220] Wed, 14 October 2015 05:10 Go to previous messageGo to next message
Eclipse UserFriend
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 #1711243 is a reply to message #1711238] Wed, 14 October 2015 05:22 Go to previous messageGo to next message
Eclipse UserFriend
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 #1711333 is a reply to message #1711243] Thu, 15 October 2015 02:21 Go to previous messageGo to next message
Eclipse UserFriend
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 02:22 Go to previous messageGo to next message
Eclipse UserFriend
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 02:25 Go to previous messageGo to next message
Eclipse UserFriend
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 02:36 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Using event.filter to register to event topics [message #1711863 is a reply to message #1711338] Tue, 20 October 2015 03:59 Go to previous messageGo to next message
Eclipse UserFriend
Why not registering to two topics with the event handler? In OSGi DS you would just add the second topic to the event.topics property like here: http://wiki.rpgnextgen.com/doku.php?id=array_value_property_for_osgi_ds_component
Re: Using event.filter to register to event topics [message #1711983 is a reply to message #1711863] Tue, 20 October 2015 10:38 Go to previous message
Eclipse UserFriend
Cool... that works.
Thank you Mihael.
Previous Topic:[Resolved] ClassNotFoundException during startup because of Application Model Changes
Next Topic:Global error handling
Goto Forum:
  


Current Time: Fri Jul 25 16:09:25 EDT 2025

Powered by FUDForum. Page generated in 0.26667 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top