jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1359763 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: PropertyDelegate.java SessionDelegate.java observation/ChangeProcessor.java observation/ObservationManagerImpl.java
Date Tue, 10 Jul 2012 16:34:06 GMT
Author: mduerig
Date: Tue Jul 10 16:34:05 2012
New Revision: 1359763

URL: http://svn.apache.org/viewvc?rev=1359763&view=rev
Log:
OAK-156: Observation events need Session.refresh

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1359763&r1=1359762&r2=1359763&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Tue Jul 10 16:34:05 2012
@@ -16,18 +16,19 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.Tree.Status;
-import org.apache.jackrabbit.oak.commons.PathUtils;
+import java.util.List;
 
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
-import java.util.List;
+
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Tree.Status;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 
 /**
  * {@code PropertyDelegate} serve as internal representations of {@code Property}s.
@@ -251,7 +252,7 @@ public class PropertyDelegate extends It
     //------------------------------------------------------------< private >---
 
     @Nonnull
-    private PropertyState getPropertyState() throws InvalidItemStateException {
+    private synchronized PropertyState getPropertyState() throws InvalidItemStateException
{
         resolve();
         if (parent == null) {
             throw new InvalidItemStateException("Property is stale");
@@ -261,7 +262,7 @@ public class PropertyDelegate extends It
     }
 
     @Nonnull
-    private Tree getParentTree() throws InvalidItemStateException {
+    private synchronized Tree getParentTree() throws InvalidItemStateException {
         resolve();
         if (parent == null) {
             throw new InvalidItemStateException("Property is stale");

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1359763&r1=1359762&r2=1359763&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Tue Jul 10 16:34:05 2012
@@ -179,12 +179,16 @@ public class SessionDelegate {
     }
 
     public boolean hasPendingChanges() {
-        return root.hasPendingChanges();
+        synchronized (root) {
+            return root.hasPendingChanges();
+        }
     }
 
     public void save() throws RepositoryException {
         try {
-            root.commit(conflictHandler);
+            synchronized (root) {
+                root.commit(conflictHandler);
+            }
         }
         catch (CommitFailedException e) {
             e.throwRepositoryException();
@@ -192,11 +196,13 @@ public class SessionDelegate {
     }
 
     public void refresh(boolean keepChanges) {
-        if (keepChanges) {
-            root.rebase(conflictHandler);
-        }
-        else {
-            root.refresh();
+        synchronized (root) {
+            if (keepChanges) {
+                root.rebase(conflictHandler);
+            }
+            else {
+                root.refresh();
+            }
         }
     }
 
@@ -267,7 +273,9 @@ public class SessionDelegate {
 
     @Nonnull
     public ChangeExtractor getChangeExtractor() {
-        return root.getChangeExtractor();
+        synchronized (root) {
+            return root.getChangeExtractor();
+        }
     }
 
     //----------------------------------------------------------< Workspace >---
@@ -318,37 +326,39 @@ public class SessionDelegate {
     public void move(String srcAbsPath, String destAbsPath, boolean transientOp)
             throws RepositoryException {
 
-        String srcPath = PathUtils.relativize("/", srcAbsPath);
-        String destPath = PathUtils.relativize("/", destAbsPath);
-        Root moveRoot = transientOp ? root : contentSession.getCurrentRoot();
-
-        // check destination
-        Tree dest = moveRoot.getTree(destPath);
-        if (dest != null) {
-            throw new ItemExistsException(destAbsPath);
-        }
+        synchronized (root) {
+            String srcPath = PathUtils.relativize("/", srcAbsPath);
+            String destPath = PathUtils.relativize("/", destAbsPath);
+            Root moveRoot = transientOp ? root : contentSession.getCurrentRoot();
+
+            // check destination
+            Tree dest = moveRoot.getTree(destPath);
+            if (dest != null) {
+                throw new ItemExistsException(destAbsPath);
+            }
 
-        // check parent of destination
-        String destParentPath = PathUtils.getParentPath(destPath);
-        Tree destParent = moveRoot.getTree(destParentPath);
-        if (destParent == null) {
-            throw new PathNotFoundException(PathUtils.getParentPath(destAbsPath));
-        }
+            // check parent of destination
+            String destParentPath = PathUtils.getParentPath(destPath);
+            Tree destParent = moveRoot.getTree(destParentPath);
+            if (destParent == null) {
+                throw new PathNotFoundException(PathUtils.getParentPath(destAbsPath));
+            }
 
-        // check source exists
-        Tree src = moveRoot.getTree(srcPath);
-        if (src == null) {
-            throw new PathNotFoundException(srcAbsPath);
-        }
+            // check source exists
+            Tree src = moveRoot.getTree(srcPath);
+            if (src == null) {
+                throw new PathNotFoundException(srcAbsPath);
+            }
 
-        try {
-            moveRoot.move(srcPath, destPath);
-            if (!transientOp) {
-                moveRoot.commit(DefaultConflictHandler.OURS);
+            try {
+                moveRoot.move(srcPath, destPath);
+                if (!transientOp) {
+                    moveRoot.commit(DefaultConflictHandler.OURS);
+                }
+            }
+            catch (CommitFailedException e) {
+                e.throwRepositoryException();
             }
-        }
-        catch (CommitFailedException e) {
-            e.throwRepositoryException();
         }
     }
 
@@ -394,7 +404,9 @@ public class SessionDelegate {
 
     @CheckForNull
     Tree getTree(String path) {
-        return root.getTree(path);
+        synchronized (root) {
+            return root.getTree(path);
+        }
     }
 
     @CheckForNull

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java?rev=1359763&r1=1359762&r2=1359763&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
Tue Jul 10 16:34:05 2012
@@ -29,6 +29,7 @@ import org.apache.jackrabbit.commons.ite
 import org.apache.jackrabbit.oak.api.ChangeExtractor;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.jcr.SessionDelegate;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -40,19 +41,21 @@ import static org.apache.jackrabbit.comm
 import static org.apache.jackrabbit.oak.util.Iterators.singleton;
 
 class ChangeProcessor extends TimerTask {
-    private final NamePathMapper namePathMapper;
+    private final SessionDelegate sessionDelegate;
     private final ChangeExtractor changeExtractor;
     private final EventListener listener;
     private final AtomicReference<ChangeFilter> filterRef;
+    private final NamePathMapper namePathMapper;
 
     private volatile boolean stopped;
 
-    public ChangeProcessor(NamePathMapper namePathMapper, ChangeExtractor changeExtractor,
EventListener listener,
+    public ChangeProcessor(SessionDelegate sessionDelegate, ChangeExtractor changeExtractor,
EventListener listener,
             ChangeFilter filter) {
-        this.namePathMapper = namePathMapper;
+        this.sessionDelegate = sessionDelegate;
         this.changeExtractor = changeExtractor;
         this.listener = listener;
         filterRef = new AtomicReference<ChangeFilter>(filter);
+        namePathMapper = sessionDelegate.getNamePathMapper();
     }
 
     public void setFilter(ChangeFilter filter) {
@@ -66,6 +69,7 @@ class ChangeProcessor extends TimerTask 
 
     @Override
     public void run() {
+        sessionDelegate.refresh(true);
         EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff();
         changeExtractor.getChanges(diff);
         diff.sendEvents();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java?rev=1359763&r1=1359762&r2=1359763&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
Tue Jul 10 16:34:05 2012
@@ -59,8 +59,7 @@ public class ObservationManagerImpl impl
         if (processor == null) {
             ChangeExtractor extractor = sessionDelegate.getChangeExtractor();
             ChangeFilter filter = new ChangeFilter(eventTypes, absPath, isDeep, uuid, nodeTypeName,
noLocal);
-            ChangeProcessor changeProcessor = new ChangeProcessor(sessionDelegate.getNamePathMapper(),
extractor,
-                    listener, filter);
+            ChangeProcessor changeProcessor = new ChangeProcessor(sessionDelegate, extractor,
listener, filter);
             processors.put(listener, changeProcessor);
             timer.get().schedule(changeProcessor, 0, 1000);
         }



Mime
View raw message