jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1405214 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core: RootImpl.java TreeImpl.java
Date Fri, 02 Nov 2012 23:28:35 GMT
Author: mduerig
Date: Fri Nov  2 23:28:35 2012
New Revision: 1405214

URL: http://svn.apache.org/viewvc?rev=1405214&view=rev
Log:
OAK-422: Replace PurgeListener in TreeImpl with NodeBuilder.reset()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1405214&r1=1405213&r2=1405214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Fri Nov  2 23:28:35 2012
@@ -22,9 +22,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
+
 import javax.annotation.Nonnull;
 import javax.security.auth.Subject;
 
@@ -84,31 +83,11 @@ public class RootImpl implements Root {
      */
     private int modCount;
 
-    /**
-     * Listeners which needs to be notified as soon as {@link #purgePendingChanges()}
-     * is called. Listeners are removed from this list after being called. If further
-     * notifications are required, they need to explicitly re-register.
-     *
-     * The {@link TreeImpl} instances us this mechanism to dispose of its associated
-     * {@link NodeBuilder} on purge. Keeping a reference on those {@code TreeImpl}
-     * instances {@code NodeBuilder} (i.e. those which are modified) prevents them
-     * from being prematurely garbage collected.
-     */
-    private List<PurgeListener> purgePurgeListeners = new ArrayList<PurgeListener>();
-
     private volatile ConflictHandler conflictHandler = DefaultConflictHandler.OURS;
 
     private final QueryIndexProvider indexProvider;
 
     /**
-     * Purge listener.
-     * @see #purgePurgeListeners
-     */
-    public interface PurgeListener {
-        void purged();
-    }
-
-    /**
      * New instance bases on a given {@link NodeStore} and a workspace
      *
      * @param store         node store
@@ -175,6 +154,7 @@ public class RootImpl implements Root {
         purgePendingChanges();
         source.moveTo(destParent, destName);
         boolean success = branch.move(sourcePath, destPath);
+        reset();
         if (success) {
             getTree(getParentPath(sourcePath)).updateChildOrder();
             getTree(getParentPath(destPath)).updateChildOrder();
@@ -187,6 +167,7 @@ public class RootImpl implements Root {
         checkLive();
         purgePendingChanges();
         boolean success = branch.copy(sourcePath, destPath);
+        reset();
         if (success) {
             getTree(getParentPath(destPath)).updateChildOrder();
         }
@@ -328,16 +309,6 @@ public class RootImpl implements Root {
         return branch.getRoot().builder();
     }
 
-    /**
-     * Add a {@code PurgeListener} to this instance. Listeners are automatically
-     * unregistered after having been called. If further notifications are required,
-     * they need to explicitly re-register.
-     * @param purgeListener  listener
-     */
-    void addListener(PurgeListener purgeListener) {
-        purgePurgeListeners.add(purgeListener);
-    }
-
     // TODO better way to determine purge limit. See OAK-175
     void updated() {
         if (++modCount > PURGE_LIMIT) {
@@ -354,19 +325,17 @@ public class RootImpl implements Root {
 
     /**
      * Purge all pending changes to the underlying {@link NodeStoreBranch}.
-     * All registered {@link PurgeListener}s are notified.
      */
     private void purgePendingChanges() {
         branch.setRoot(rootTree.getNodeState());
-        notifyListeners();
+        reset();
     }
 
-    private void notifyListeners() {
-        List<PurgeListener> purgeListeners = this.purgePurgeListeners;
-        this.purgePurgeListeners = new ArrayList<PurgeListener>();
-
-        for (PurgeListener purgeListener : purgeListeners) {
-            purgeListener.purged();
-        }
+    /**
+     * Reset the root builder to the branch's current root state
+     */
+    private void reset() {
+        rootTree.getNodeBuilder().reset(branch.getRoot());
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1405214&r1=1405213&r2=1405214&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Fri Nov  2 23:28:35 2012
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.core.RootImpl.PurgeListener;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryPropertyBuilder;
 import org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -48,7 +47,7 @@ import static com.google.common.base.Pre
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 
-public class TreeImpl implements Tree, PurgeListener {
+public class TreeImpl implements Tree {
 
     /** Internal and hidden property that contains the child order */
     static final String OAK_CHILD_ORDER = ":childOrder";
@@ -83,7 +82,6 @@ public class TreeImpl implements Tree, P
             protected synchronized NodeBuilder getNodeBuilder() {
                 if (nodeBuilder == null) {
                     nodeBuilder = root.createRootBuilder();
-                    root.addListener(this);
                 }
                 return nodeBuilder;
             }
@@ -389,13 +387,6 @@ public class TreeImpl implements Tree, P
         return new NodeLocation(this);
     }
 
-    //--------------------------------------------------< RootImpl.Listener >---
-
-    @Override
-    public void purged() {
-        nodeBuilder = null;
-    }
-
     //----------------------------------------------------------< protected >---
 
     @CheckForNull
@@ -414,7 +405,6 @@ public class TreeImpl implements Tree, P
     protected synchronized NodeBuilder getNodeBuilder() {
         if (nodeBuilder == null) {
             nodeBuilder = parent.getNodeBuilder().child(name);
-            root.addListener(this);
         }
         return nodeBuilder;
     }



Mime
View raw message