jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lei Zhou <L...@pointalliance.com>
Subject Making an EventListener associated to all sessions of a specific workspace?
Date Thu, 30 Nov 2006 17:34:21 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message