jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r412344 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
Date Wed, 07 Jun 2006 09:36:55 GMT
Author: tripod
Date: Wed Jun  7 02:36:55 2006
New Revision: 412344

URL: http://svn.apache.org/viewvc?rev=412344&view=rev
Log:
JCR-453: add/remove dispatchers from DelegatingObservationDispatcher is not synchronized

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java?rev=412344&r1=412343&r2=412344&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
Wed Jun  7 02:36:55 2006
@@ -19,9 +19,10 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.name.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -31,6 +32,11 @@
 public class DelegatingObservationDispatcher extends EventDispatcher {
 
     /**
+     * Logger instance.
+     */
+    private static Logger log = LoggerFactory.getLogger(DelegatingObservationDispatcher.class);
+
+    /**
      * the set of dispatchers
      */
     private final HashSet dispatchers = new HashSet();
@@ -41,7 +47,9 @@
      * @param disp
      */
     public void addDispatcher(ObservationManagerFactory disp) {
-        dispatchers.add(disp);
+        synchronized (dispatchers) {
+            dispatchers.add(disp);
+        }
     }
 
     /**
@@ -50,7 +58,9 @@
      * @param disp
      */
     public void removeDispatcher(ObservationManagerFactory disp) {
-        dispatchers.remove(disp);
+        synchronized (dispatchers) {
+            dispatchers.remove(disp);
+        }
     }
 
     /**
@@ -97,13 +107,21 @@
      * @param session
      */
     public void dispatch(List eventList, SessionImpl session, Path pathPrefix) {
-        Iterator iter = dispatchers.iterator();
-        while (iter.hasNext()) {
-            ObservationManagerFactory fac = (ObservationManagerFactory) iter.next();
-            EventStateCollection events = new EventStateCollection(fac, session, pathPrefix);
-            events.addAll(eventList);
-            events.prepare();
-            events.dispatch();
+        ObservationManagerFactory[] disp;
+        synchronized (dispatchers) {
+            disp = (ObservationManagerFactory[]) dispatchers.toArray(
+                    new ObservationManagerFactory[dispatchers.size()]);
+        }
+        for (int i=0; i< disp.length; i++) {
+            EventStateCollection events =
+                    new EventStateCollection(disp[i], session, pathPrefix);
+            try {
+                events.addAll(eventList);
+                events.prepare();
+                events.dispatch();
+            } catch (Exception e) {
+                log.error("Error while dispatching events.", e);
+            }
         }
     }
 }



Mime
View raw message