You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Torgeir Veimo <to...@pobox.com> on 2006/07/14 14:14:37 UTC

event listener not getting any events..

I'm registering an event listener like this:
 
systemSession.getWorkspace().getObservationManager().addEventListener(new 
ProtectedNodeListener(systemSession),
   (Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | 
Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED),
   "/jcr:root",
   true,
   null,
   new String [] { "nen:protected", "nen:ace" },
   true);

But I'm not getting any events when i create nodes with mixin nodetype 
nen:protected. Any clues on what I'm doing wrong?

-- 
-Torgeir

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Torgeir Veimo wrote:
> So the code is right and the javadoc is wrong then? I find it a bit odd 
> to specify the parent node for nodetypes I want to register events for, 
> it makes it almost impossible to do what I want to do without 
> registering my eventhandler for _all_ nodetypes.

It seems something is wrong in the implementation in any case. Giving 
null as parameter instead of a nodetype name string array doesn't 
provide me any more events than before in any case.


-- 
-Torgeir

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Marcel Reutegger wrote:
> Jukka Zitting wrote:
>> Marcel, what's the rationale behind the spec?
> 
> when you have events for properties like property_added, 
> property_removed and property_changed the node type filter only makes 
> sense for the parent node. it was then decided to use the term 
> 'associated parent node' for each event and declare all filters 
> (absPath, isDeep, uuid and nodeTypeName) to apply to this associated 
> parent node, even for the node related events.
> 
> and in some cases it actually makes sense. imagine that you want to get 
> notifications when a node is added or removed from nt:folder nodes. Then 
> the API provides you with exactly that functionality. of course there 
> are other use cases such as the one mentioned by torgeir, which are not 
> properly supported by the API.

In which case the infamous advice on implementing acl based security 
using listeners and acl caches doesn't work.

It doesn't seem possible at the moment to get notification whenever 
nodes that have security information is created, updated or removed.


-- 
-Torgeir

Re: event listener not getting any events..

Posted by Marcel Reutegger <ma...@gmx.net>.
Jukka Zitting wrote:
> Marcel, what's the rationale behind the spec?

when you have events for properties like property_added, 
property_removed and property_changed the node type filter only makes 
sense for the parent node. it was then decided to use the term 
'associated parent node' for each event and declare all filters 
(absPath, isDeep, uuid and nodeTypeName) to apply to this associated 
parent node, even for the node related events.

and in some cases it actually makes sense. imagine that you want to 
get notifications when a node is added or removed from nt:folder 
nodes. Then the API provides you with exactly that functionality. of 
course there are other use cases such as the one mentioned by torgeir, 
which are not properly supported by the API.

regards
  marcel

Re: event listener not getting any events..

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 7/18/06, Torgeir Veimo <to...@pobox.com> wrote:
> So the code is right and the javadoc is wrong then? I find it a bit odd
> to specify the parent node for nodetypes I want to register events for,
> it makes it almost impossible to do what I want to do without
> registering my eventhandler for _all_ nodetypes.

I'm really not sure what would be the correct interpretation in this
case. The specification document quoted by Marcel is the normative
reference, but I agree that the specified behaviour is a bit odd. It
would have been my intuition as well that if I specify a listener for
"nt:file" events, I'd be receiving events on "nt:file" nodes, not on
"nt:resource" or whatever.

Marcel, what's the rationale behind the spec?

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Jukka Zitting wrote:
> Hi,
> 
> On 7/17/06, Marcel Reutegger <ma...@gmx.net> wrote:
>> This is expected behaviour. The spec says about the node type parameter:
>>
>> <jsr-170>
>> nodeTypeName: Only events whose associated parent node has one of the
>> node types (or a subtype of one of the node types) in this list will
>> be received. If this parameter is null then no node typerelated
>> restriction is placed on events received. Note that specifying an
>> empty array instead of null would result in no node types being
>> listened to.
>> </jsr-170>
> 
> Argh, the javax.jcr.observation.ObservationManager Javadoc says:
> 
>    nodeTypeName: Only events whose associated node has one of the
>    node types (or a subtype of one of the node types) in this list will be
>    received. If his parameter is null then no node type-related restriction
>    is placed on events received.
> 
> Cc'ing jsr-170-comments@jcp.org as this is something that definitely
> should be fixed if still possible in the upcoming JSR 170 maintenance
> release.

So the code is right and the javadoc is wrong then? I find it a bit odd 
to specify the parent node for nodetypes I want to register events for, 
it makes it almost impossible to do what I want to do without 
registering my eventhandler for _all_ nodetypes.

-- 
-Torgeir

Re: event listener not getting any events..

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 7/17/06, Marcel Reutegger <ma...@gmx.net> wrote:
> This is expected behaviour. The spec says about the node type parameter:
>
> <jsr-170>
> nodeTypeName: Only events whose associated parent node has one of the
> node types (or a subtype of one of the node types) in this list will
> be received. If this parameter is null then no node typerelated
> restriction is placed on events received. Note that specifying an
> empty array instead of null would result in no node types being
> listened to.
> </jsr-170>

Argh, the javax.jcr.observation.ObservationManager Javadoc says:

    nodeTypeName: Only events whose associated node has one of the
    node types (or a subtype of one of the node types) in this list will be
    received. If his parameter is null then no node type-related restriction
    is placed on events received.

Cc'ing jsr-170-comments@jcp.org as this is something that definitely
should be fixed if still possible in the upcoming JSR 170 maintenance
release.

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development

Re: event listener not getting any events..

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Torgeir,

Torgeir Veimo wrote:
> systemSession.getWorkspace().getObservationManager().addEventListener(new 
> ProtectedNodeListener(systemSession),
>   (Event.NODE_ADDED | Event.NODE_REMOVED),
>   "/", true,
>   null,
>   new String [] { "nt:folder", "nt:file" },
>   true);
> 
> Then on creating an nt:folder with path /test3/blabla, the event reports 
> a NODE_ADDED with path /test3/blabla/nen:ace (which is a subnode added 
> in the same session.save() and not an nt:folder node).

This is expected behaviour. The spec says about the node type parameter:

<jsr-170>
nodeTypeName: Only events whose associated parent node has one of the
node types (or a subtype of one of the node types) in this list will
be received. If this parameter is null then no node typerelated
restriction is placed on events received. Note that specifying an
empty array instead of null would result in no node types being
listened to.
</jsr-170>

regards
  marcel

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Marcel Reutegger wrote:
> Torgeir Veimo wrote:
>> I create the test2 node of type nen:resource, mixin nen:protected, and 
>> attach a number of child nodes of type nen:ace to it. It's all done in 
>> one session which I logout of immediately after the save.
> 
> you should actually see more than just one property added event. from 
> what I can tell there should be:
> - 'property added' for jcr:primaryType on new node 'test2'
> - 'property added' for jcr:mixinTypes on new node 'test2'
> - 'property added' for jcr:primaryType for each nen:ace you add
> 
> are you able to reproduce this behaviour using predefined node types, 
> e.g. using nt:unstructured? If yes can you please put together a small 
> test case and create a jira issue? Thanks

I guess I will do that. I haven't put together a test case yet, but it 
seems the event path is wrong. When I add my listener like this:

 
systemSession.getWorkspace().getObservationManager().addEventListener(new 
ProtectedNodeListener(systemSession),
   (Event.NODE_ADDED | Event.NODE_REMOVED),
   "/", true,
   null,
   new String [] { "nt:folder", "nt:file" },
   true);

Then on creating an nt:folder with path /test3/blabla, the event reports 
a NODE_ADDED with path /test3/blabla/nen:ace (which is a subnode added 
in the same session.save() and not an nt:folder node).


-- 
-Torgeir

Re: event listener not getting any events..

Posted by Marcel Reutegger <ma...@gmx.net>.
Torgeir Veimo wrote:
> I create the test2 node of type nen:resource, mixin nen:protected, and 
> attach a number of child nodes of type nen:ace to it. It's all done in 
> one session which I logout of immediately after the save.

you should actually see more than just one property added event. from 
what I can tell there should be:
- 'property added' for jcr:primaryType on new node 'test2'
- 'property added' for jcr:mixinTypes on new node 'test2'
- 'property added' for jcr:primaryType for each nen:ace you add

are you able to reproduce this behaviour using predefined node types, 
e.g. using nt:unstructured? If yes can you please put together a small 
test case and create a jira issue? Thanks

regards
  marcel

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Marcel Reutegger wrote:
> Torgeir Veimo wrote:
>> Quick followup question; when i create a node with child nodes, I seem 
>> to be getting only one event with type PROPERTY_ADDED on one of the 
>> children of the new node. Eg I create a node
>>
>> /pages/test2 of type nen:resource, mixin nen:protected, with childen 
>> nen:ace.
>>
>> The node I get the event for is the node
>>
>> /pages/test2/nen:ace/jcr:primaryType
>>
>> Is there something wrong with my listener registration?
> 
> do you set any other properties on /pages/test2/nen:ace ?

I create the test2 node of type nen:resource, mixin nen:protected, and 
attach a number of child nodes of type nen:ace to it. It's all done in 
one session which I logout of immediately after the save.

> a listener also does not get events for an item it's not allowed to see. 
> i.e. restricted by access rights.

Ok, I'm not actually restricting any operations by any access manager 
just yet.


-- 
-Torgeir

Re: event listener not getting any events..

Posted by Marcel Reutegger <ma...@gmx.net>.
Torgeir Veimo wrote:
> Quick followup question; when i create a node with child nodes, I seem 
> to be getting only one event with type PROPERTY_ADDED on one of the 
> children of the new node. Eg I create a node
> 
> /pages/test2 of type nen:resource, mixin nen:protected, with childen 
> nen:ace.
> 
> The node I get the event for is the node
> 
> /pages/test2/nen:ace/jcr:primaryType
> 
> Is there something wrong with my listener registration?

do you set any other properties on /pages/test2/nen:ace ?

a listener also does not get events for an item it's not allowed to 
see. i.e. restricted by access rights.

regards
  marcel

Re: event listener not getting any events..

Posted by Torgeir Veimo <to...@pobox.com>.
Marcel Reutegger wrote:
> Torgeir Veimo wrote:
>> I'm registering an event listener like this:
>>
>> systemSession.getWorkspace().getObservationManager().addEventListener(new 
>> ProtectedNodeListener(systemSession),
>>   (Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | 
>> Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED),
>>   "/jcr:root",
> 
> what you rather want here is "/" not "/jcr:root" ;)
> 
> /jcr:root is only used in context of a document view mapping, such as 
> document view export or XPath queries.

Thx!

Quick followup question; when i create a node with child nodes, I seem 
to be getting only one event with type PROPERTY_ADDED on one of the 
children of the new node. Eg I create a node

/pages/test2 of type nen:resource, mixin nen:protected, with childen 
nen:ace.

The node I get the event for is the node

/pages/test2/nen:ace/jcr:primaryType

Is there something wrong with my listener registration?

-- 
-Torgeir

Re: event listener not getting any events..

Posted by Marcel Reutegger <ma...@gmx.net>.
Torgeir Veimo wrote:
> I'm registering an event listener like this:
> 
> systemSession.getWorkspace().getObservationManager().addEventListener(new 
> ProtectedNodeListener(systemSession),
>   (Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | 
> Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED),
>   "/jcr:root",

what you rather want here is "/" not "/jcr:root" ;)

/jcr:root is only used in context of a document view mapping, such as 
document view export or XPath queries.

>   true,
>   null,
>   new String [] { "nen:protected", "nen:ace" },
>   true);

regards
  marcel