jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dürig <mdue...@apache.org>
Subject Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener
Date Tue, 11 Mar 2014 14:48:26 GMT


On 11.3.14 3:30 , Jukka Zitting wrote:
> Hi,
>
> On Tue, Mar 11, 2014 at 6:12 AM, Michael Dürig <mduerig@apache.org> 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<EventListener> proxies = new ArrayList<EventListener>();
>
>      public void register(
>              int eventTypes, Collection<String> 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);
>          }
>      }
>
> }
>

Mime
View raw message