Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener

2014-03-12 Thread Michael Dürig


Hi,

On 11.3.14 2:29 , Angela Schreiber wrote:

alternatively, we could make this a Jackrabbit API extension to the JCR
API and explicitly allow for multiple paths to be specified. this would be
backwards compatible as well and less error prone when it comes to
specification compliance.


This seems like the best solution to me. I've created 
https://issues.apache.org/jira/browse/JCR-3745


Michael


Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener

2014-03-11 Thread Michael Dürig



On 11.3.14 3:30 , Jukka Zitting wrote:

Hi,

On Tue, Mar 11, 2014 at 6:12 AM, Michael Dürig  wrote:

One way we could address this in an backward compatible way is to slightly
extend the semantics of the absPath parameter and allow for a list of path
instead of a single one.


Couldn't the client achieve the same effect by registering multiple
copies of the listener, one for each path?


Yes it could and in fact that was the initially proposed solution. I 
came up with this approach to make the client's life easier, but have my 
own reservations re. this.


Michael



A utility class like the one shown below should do the trick.

BR,

Jukka Zitting



public class MultiListener implements EventListener {

 private final ObservationManager manager;

 private final EventListener listener;

 private final List proxies = new ArrayList();

 public void register(
 int eventTypes, Collection paths, boolean isDeep,
 String[] uuid, String[] nodeTypeNames, boolean noLocal)
 throws RepositoryException {
 for (String path : paths) {
 EventListener proxy = new EventListener() {
 @Override
 public void onEvent(EventIterator events) {
 listener.onEvent(events);
 }
 };
 manager.addEventListener(
 proxy, eventTypes, path,
 isDeep, uuid, nodeTypeNames, noLocal);
 proxies.add(proxy);
 }
 }

 public void unregister() throws RepositoryException {
 for (EventListener proxy : proxies) {
 manager.removeEventListener(proxy);
 }
 }

}