You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Michael Dürig <md...@apache.org> on 2014/03/11 11:12:28 UTC
Extending semantics of absPath Parameter of ObservationManager.addEventListener
Hi,
Since JCR observation only supports listening on a single path per
listener, a commonly seen pattern is listeners registered on the root
path and then filtering for the required paths in the event handler.
This causes a lot of overhead in the case where the number of events on
the target paths is low wrt. the total number of events.
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. AFICS we could use | for
separating such paths (e.g. /foo/bar|/baz/qox). This could then also be
back ported to JR2 if needed. WDYT?
Michael
Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener
Posted by Michael Dürig <md...@apache.org>.
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
Posted by Felix Meschberger <fm...@adobe.com>.
Hi
I am with Angela on this and would prefer a new method instead of overloading the string semantics.
Regards
Felix
Am 11.03.2014 um 14:29 schrieb Angela Schreiber <an...@adobe.com>:
> hi michael
>
>> Since JCR observation only supports listening on a single path per
>> listener, a commonly seen pattern is listeners registered on the root
>> path and then filtering for the required paths in the event handler.
>
> yes, i have seen this a lot.
>
>>
>> This causes a lot of overhead in the case where the number of events on
>> the target paths is low wrt. the total number of events.
>>
>> 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. AFICS we could use | for
>> separating such paths (e.g. /foo/bar|/baz/qox). This could then also be
>> back ported to JR2 if needed. WDYT?
>
> that would be an option... but one that violates the API contract as the
> path param is defined to be an absolute path.
>
> 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.
>
> kind regards
> angela
>
Re: Extending semantics of absPath Parameter of
ObservationManager.addEventListener
Posted by Angela Schreiber <an...@adobe.com>.
hi michael
>Since JCR observation only supports listening on a single path per
>listener, a commonly seen pattern is listeners registered on the root
>path and then filtering for the required paths in the event handler.
yes, i have seen this a lot.
>
>This causes a lot of overhead in the case where the number of events on
>the target paths is low wrt. the total number of events.
>
>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. AFICS we could use | for
>separating such paths (e.g. /foo/bar|/baz/qox). This could then also be
>back ported to JR2 if needed. WDYT?
that would be an option... but one that violates the API contract as the
path param is defined to be an absolute path.
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.
kind regards
angela
Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener
Posted by Michael Dürig <md...@apache.org>.
On 11.3.14 3:30 , Jukka Zitting wrote:
> Hi,
>
> On Tue, Mar 11, 2014 at 6:12 AM, Michael Dürig <md...@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);
> }
> }
>
> }
>
Re: Extending semantics of absPath Parameter of ObservationManager.addEventListener
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Tue, Mar 11, 2014 at 6:12 AM, Michael Dürig <md...@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?
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);
}
}
}