You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Lei Zhou <Le...@pointalliance.com> on 2006/11/30 18:34:21 UTC

Making an EventListener associated to all sessions of a specific workspace?

Hi,

I'd like to watch a workspace for any changes in property "State" of all 
"Document" nodes. Whenever that property is updated, an event listener 
should create a log entry and send it to another system. 

So I need to: 
1. watch all sessions connecting to the specific workspace
2. make sure the events are "indeed" fired and the listener invoked

I can of course register EventListeners on a per session basis - by 
Workspace.getObservationManager().addEventListener(). But is there a way 
to associate listeners to the Repository (or Workspace) itself and set the 
"scope" to "all_sessions"? 
This way then listeners can be registered at application initialization 
time, and I don't have to check on every user login to see if the specific 
workspace is being accessed? 

I also came across a thread by Marcel Reutegger, explaining why some 
events are not delivered to EventListener (as below).
> 
> Events are delivered with an asynchronous background thread. This way 
> the internals of jackrabbit do not have to wait for listener 
> implementations to complete the commit of changes.
> 
> because your code logs out the session immediately after save() it may 
> happen that the notification of your listener does not happen within 
> that short period of time. As soon as a session is logged out all its 
> associated EventListeners are invalidated and are not notified 
> anymore. This is because the Event instances are bound to the 
> namespace mappings of the current session. Event.getPath() must return 
> the namespace prefixes according to the currently set mapping in the 
> Session. When the session is gone, Event.getPath() would not be able 
> to return any sensible value anymore. 

If I do something like following in web application, what do I need to 
ensure the EventListener is triggered? 

try{
transaction.start();

... node modifications code

session.save();
transaction.commit();

}finally{
session.logout();
}


Regards,
Lei

Re: Making an EventListener associated to all sessions of a specific workspace?

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

On 11/30/06, Lei Zhou <Le...@pointalliance.com> wrote:
> I can of course register EventListeners on a per session basis - by
> Workspace.getObservationManager().addEventListener(). But is there a way
> to associate listeners to the Repository (or Workspace) itself and set the
> "scope" to "all_sessions"?

The best solution would be for your application to start a special
"listener" session during initialization and use that session for
observation. It'll receive notification of all events caused by any
normal sessions. This approach will also avoid the issue with event
delivery delays, since the listener session can be logged out only
when the application itself shuts down.

You should use either the superuser account or another special account
that has full read access to the workspace to ensure that you receive
notification of all changes regardless of possible access controls.

BR,

Jukka Zitting