You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by mmjose26 <mm...@yahoo.com.mx> on 2011/08/03 18:29:45 UTC
using Asynchronous listener
Hi! I'm trying to implement some logic after of add some nodes to repository.
I'm using asynchronous listener, and for each node of type X, the listener
do version on it.
I'm using transactional scenario, and all happen on commit. Almost always,
the commit invalidate the session just before that the listener be notified
at all. and the listener is not called.
I don't know how work around this behaviour.
Any help on this would be appreciated!
--
View this message in context: http://jackrabbit.510166.n4.nabble.com/using-Asynchronous-listener-tp3716110p3716110.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: using Asynchronous listener
Posted by mmjose26 <mm...@yahoo.com.mx>.
Tanks very much for your reply and suggestions, I will try with queue and
background worker thread.
I'm using a new fresh session for each new event, but onEvent() method
never is called.
Maybe I found the reason of this behavior and I will try to explain what I
found when debugging my app
Please correct me if I'm wrong with my assumptions.
1) We need register a Event Listener via observationManager, this
observationManager uses the current session object, adding a new
EventConsumer( using the current session object).
2) On commit:
a) Synchronous eventListeners are executed and the asynchronous listeners
are queued.
b) Active session is invalidated after that.
But, because of we have dealing with threads,
in some point of time maybe after or before (here the point!) of session
is invalidated,
notificationThread(the daemon thread of Observationdispatcher) call the run
method and the EventConsumer.consumeEvent is called too. This method
validate if the session (the object session used to register this
evenConsumer) is valid.
if commit ends with session before that consumeEvent, the onEvent method is
never called due to this validation, but we need to validate the session
object, because Event object need it.
Tanks for your help!
--
View this message in context: http://jackrabbit.510166.n4.nabble.com/using-Asynchronous-listener-tp3716110p3717305.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
Re: using Asynchronous listener
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Wed, Aug 3, 2011 at 6:29 PM, mmjose26 <mm...@yahoo.com.mx> wrote:
> Hi! I'm trying to implement some logic after of add some nodes to repository.
> I'm using asynchronous listener, and for each node of type X, the listener
> do version on it.
>
> I'm using transactional scenario, and all happen on commit. Almost always,
> the commit invalidate the session just before that the listener be notified
> at all. and the listener is not called.
Are you using the same session for both the listener and the
transaction? It's generally a good idea to use a separate long-lived
session for any event listeners you have.
Also, note that using the listener session for anything during the
onEvent() call is a bad practice, as you can't easily prevent
concurrent use of the session. Instead, if you need to do something
like create a new version in an event handler, I recommend either
using a task queue and a background worker thread (with its own
separate session) or launching a fresh new session for each new event
that needs repository writes.
BR,
Jukka Zitting