Expand my Community achievements bar.

SOLVED

Register two EventListeners in single event listener class

Avatar

Level 4

I have a scenario where we need to listeners to be registered in the same eventListener class. The listeners we are registering for two events as :

1. Asset upload’s listener in DAM

2. Page property changed listener for a page

adminSession.getWorkspace().getObservationManager().addEventListener(this,Event.NODE_ADDED | Event.NODE_MOVED, "/content/dam",true, null, {dam:Asset}, false);

adminSession.getWorkspace().getObservationManager().addEventListener(this,Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED,<some page path>, true, null,{nt:unstructured}, false);

Now the issue I am facing is that only one listener is being triggered which in my case is the latter one. So what ever listener I specify last will get registered and only that will fire on that event.

Please share any inputs which can make this scenario work and where I can register two event listeners in the same event listener class.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

I've never tried to register 2 listeners in the very same service, but I don't see any reason, why it shouldn't work; what I suggest first is to ask on the jackrabbit-user list [1], if there's any limitation in that area.As workaround I would try to register instances of 2 different inner classes instead of "this".

HTH,
Jörg

[1] http://jackrabbit.apache.org/mailing-lists.html

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

Hi,

I've never tried to register 2 listeners in the very same service, but I don't see any reason, why it shouldn't work; what I suggest first is to ask on the jackrabbit-user list [1], if there's any limitation in that area.As workaround I would try to register instances of 2 different inner classes instead of "this".

HTH,
Jörg

[1] http://jackrabbit.apache.org/mailing-lists.html

Avatar

Level 4

Hi Jorg,

Thanks. I will ask at user list of jackrabbit. About the workaround, I didn't quite understand what you were trying to suggest, sorry for this. What I did is, I tried using the instance of my listener class instead of "this", like : 

adminSession.getWorkspace().getObservationManager().addEventListener(new XYZListener(),Event.NODE_ADDED | Event.NODE_MOVED"/content/dam",truenull, {dam:Asset}, false);

adminSession.getWorkspace().getObservationManager().addEventListener(new XYZListener(),Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED,<some page path>,truenull,{nt:unstructured}, false)

Now here both the listeners fire which is good but the issue here is only one listener out of these works well, the other listener doesn't get the @Reference Objects and throws null pointer where we use objects initialized by @Reference like resourceResolver, queryhelper etc. Can you tell me why its showing this behaviour and how can I handle this, if any way is there. 

 

Thanks & Regards.

Sameer