Expand my Community achievements bar.

SOLVED

Event Listener

Avatar

Level 4

Hello All,

I am writing two eventListener methods in activate method with two different paths.

The event is not getting fired when I have both methods, but will work fine only if one method is used.

 

Thanks,

Vish

1 Accepted Solution

Avatar

Correct answer by
Administrator

HI 

"The filters of an already-registered EventListener can be changed at runtime by re-registering the same EventListener object (i.e. the same actual Java object) with a new set of filter arguments. The implementation must ensure that no events are lost during the changeover."

So in above mentioned code, we can see that we have 2 event listener. Try this (create 2 listeners), if it would work for you.

 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

View solution in original post

3 Replies

Avatar

Administrator

Hi vishwanath881

I tried to search online, but i have not found any case where we have multiple EventListner in a function (activate).

Workaround could be,

Option 1: Create 2 OSGI bundles for both listner.

Option 2 (Not tried): Create 2 ObservationManager object and add listener to respective ObservationManager  object.

Rest i will let community to take on this answer.

I hope this would help you a bit.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Administrator

Hi 

I have found a reference link, i hope this would help you.

Example 4

  8 
vote

From project jackrabbit, under directory /jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/acl/, in source file EntryCollector.java

 

/** * @param systemSession * @param rootID * @throws RepositoryException */protected EntryCollector(SessionImpl systemSession,NodeId rootID) throws RepositoryException {this.systemSession=systemSession;this.rootID=rootID;ObservationManager observationMgr=systemSession.getWorkspace().getObservationManager();int events=Event.PROPERTY_CHANGED | Event.NODE_ADDED | Event.NODE_REMOVED;String[] ntNames=new String[]{systemSession.getJCRName(NT_REP_ACCESS_CONTROLLABLE),systemSession.getJCRName(NT_REP_ACL),systemSession.getJCRName(NT_REP_ACE)};String rootPath=systemSession.getRootNode().getPath();observationMgr.addEventListener(this,events,rootPath,true,null,ntNames,true);moveListener=new MoveListener();observationMgr.addEventListener(moveListener,Event.NODE_MOVED,rootPath,true,null,null,true);}
 

Link:- http://www.programcreek.com/java-api-examples/index.php?api=javax.jcr.observation.ObservationManager (Example 4)

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Correct answer by
Administrator

HI 

"The filters of an already-registered EventListener can be changed at runtime by re-registering the same EventListener object (i.e. the same actual Java object) with a new set of filter arguments. The implementation must ensure that no events are lost during the changeover."

So in above mentioned code, we can see that we have 2 event listener. Try this (create 2 listeners), if it would work for you.

 

Thanks and Regards

Kautuk Sahni



Kautuk Sahni