jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r529913 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Date Wed, 18 Apr 2007 08:20:43 GMT
Author: jukka
Date: Wed Apr 18 01:20:41 2007
New Revision: 529913

URL: http://svn.apache.org/viewvc?view=rev&rev=529913
Log:
JCR-798: Explicitly remove all registered event listeners at the beginning of logout() to
avoid concurrent access either from the internal event delivery process or from external event
listeners.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&rev=529913&r1=529912&r2=529913
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Wed Apr 18 01:20:41 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core;
 
+import org.apache.commons.collections.IteratorUtils;
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.core.config.AccessManagerConfig;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
@@ -72,6 +73,9 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+import javax.jcr.observation.ObservationManager;
 import javax.jcr.version.VersionException;
 import javax.security.auth.Subject;
 import javax.xml.parsers.ParserConfigurationException;
@@ -91,6 +95,7 @@
 import java.security.AccessControlException;
 import java.security.Principal;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -1215,6 +1220,30 @@
     }
 
     /**
+     * Utility method that removes all registered event listeners.
+     */
+    private void removeRegisteredEventListeners() {
+        try {
+            ObservationManager manager = getWorkspace().getObservationManager();
+            // Use a copy to avoid modifying the set of registered listeners
+            // while iterating over it
+            Collection listeners =
+                IteratorUtils.toList(manager.getRegisteredEventListeners());
+            Iterator iterator = listeners.iterator();
+            while (iterator.hasNext()) {
+                EventListener listener = (EventListener) iterator.next();
+                try {
+                    manager.removeEventListener(listener);
+                } catch (RepositoryException e) {
+                    log.warn("Error removing event listener: " + listener, e);
+                }
+            }
+        } catch (RepositoryException e) {
+            log.warn("Error removing event listeners", e);
+        }
+    }
+
+    /**
      * {@inheritDoc}
      */
     public synchronized void logout() {
@@ -1222,6 +1251,10 @@
             // ignore
             return;
         }
+
+        // JCR-798: Remove all registered event listeners to avoid concurrent
+        // access to session internals by the event delivery or even listeners
+        removeRegisteredEventListeners();
 
         // discard any pending changes first as those might
         // interfere with subsequent operations



Mime
View raw message