jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1494931 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
Date Thu, 20 Jun 2013 11:23:01 GMT
Author: mduerig
Date: Thu Jun 20 11:23:01 2013
New Revision: 1494931

URL: http://svn.apache.org/r1494931
Log:
OAK-144 Implement Observation
- avoid race condition between creating changes sets and dispatching them, which could lead
to bogus events

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java?rev=1494931&r1=1494930&r2=1494931&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
Thu Jun 20 11:23:01 2013
@@ -93,34 +93,26 @@ public class ChangeDispatcher {
         return listener;
     }
 
-    private void contentChanged(@Nonnull NodeState before, @Nonnull NodeState after, ContentSession
contentSession) {
-        ChangeSet extChanges;
-        ChangeSet intChange;
-        synchronized (this) {
-            extChanges = externalChange(checkNotNull(before));
-            intChange = internalChange(checkNotNull(after), contentSession);
-        }
-        if (extChanges != null) {
-            add(extChanges);
-        }
-        add(intChange);
-    }
-
-    @CheckForNull
-    private synchronized ChangeSet externalChange(NodeState root) {
-        if (root != previousRoot) {
-            ChangeSet changeSet = ChangeSet.external(previousRoot, root);
+    private synchronized void contentChanged(@Nonnull NodeState before, @Nonnull NodeState
after,
+            ContentSession contentSession) {
+        externalChange(checkNotNull(before));
+        internalChange(checkNotNull(after), contentSession);
+    }
+
+    private void externalChange(NodeState root) {
+        if (!root.equals(previousRoot)) {
+            add(ChangeSet.external(previousRoot, root));
             previousRoot = root;
-            return changeSet;
         }
-        return null;
     }
 
-    @Nonnull
-    private synchronized ChangeSet internalChange(NodeState root, ContentSession contentSession)
{
-        ChangeSet changeSet = ChangeSet.local(previousRoot, root, contentSession);
+    private void internalChange(NodeState root, ContentSession contentSession) {
+        add(ChangeSet.local(previousRoot, root, contentSession));
         previousRoot = root;
-        return changeSet;
+    }
+
+    private synchronized void externalChange() {
+        externalChange(store.getRoot());
     }
 
     private void register(Listener listener) {
@@ -192,10 +184,7 @@ public class ChangeDispatcher {
         @CheckForNull
         public ChangeSet getChanges() {
             if (changeSets.isEmpty()) {
-                ChangeSet changeSet = externalChange(store.getRoot());
-                if (changeSet != null) {
-                    add(changeSet);
-                }
+                externalChange();
             }
             return changeSets.isEmpty() ? null : changeSets.remove();
         }



Mime
View raw message