jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r470745 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: CachingHierarchyManager.java state/LocalItemStateManager.java state/NodeStateListener.java state/SessionItemStateManager.java state/StateChangeDispatcher.java
Date Fri, 03 Nov 2006 10:09:04 GMT
Author: tripod
Date: Fri Nov  3 02:09:04 2006
New Revision: 470745

URL: http://svn.apache.org/viewvc?view=rev&rev=470745
Log:
JCR-617 CachingHieraarchyManager may serve moved items

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/NodeStateListener.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/StateChangeDispatcher.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?view=diff&rev=470745&r1=470744&r2=470745
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
Fri Nov  3 02:09:04 2006
@@ -284,14 +284,16 @@
      */
     public void stateModified(ItemState modified) {
         if (modified.isNode()) {
-            stateModified((NodeState) modified);
+            nodeModified((NodeState) modified);
         }
     }
 
     /**
+     * {@inheritDoc}
+     *
      * Evict moved or renamed items from the cache.
      */
-    private void stateModified(NodeState modified) {
+    public void nodeModified(NodeState modified) {
         synchronized (cacheMonitor) {
             LRUEntry entry = (LRUEntry) idCache.get(modified.getNodeId());
             if (entry == null) {
@@ -601,6 +603,8 @@
      *
      * @param path child path
      * @param id   node id
+     *
+     * @throws PathNotFoundException if hte path was not found
      */
     private void insert(Path path, ItemId id) throws PathNotFoundException {
         synchronized (cacheMonitor) {
@@ -631,6 +635,8 @@
      *
      * @param path child path
      * @param id   node id
+     *
+     * @throws PathNotFoundException if the path was not found
      */
     private void remove(Path path, ItemId id) throws PathNotFoundException {
         synchronized (cacheMonitor) {
@@ -677,6 +683,7 @@
          * Create a new instance of this class
          *
          * @param id node id
+         * @param element the path map element for this entry
          */
         public LRUEntry(NodeId id, PathMap.Element element) {
             this.id = id;

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?view=diff&rev=470745&r1=470744&r2=470745
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
Fri Nov  3 02:09:04 2006
@@ -22,9 +22,10 @@
 import org.apache.jackrabbit.core.observation.EventStateCollectionFactory;
 import org.apache.jackrabbit.name.QName;
 
-import javax.jcr.ReferentialIntegrityException;
 import java.util.Iterator;
 
+import javax.jcr.ReferentialIntegrityException;
+
 /**
  * Local <code>ItemStateManager</code> that isolates changes to
  * persistent states from other clients.
@@ -402,7 +403,7 @@
      * we're listening to.
      */
     public void stateModified(ItemState modified) {
-        ItemState local = null;
+        ItemState local;
         if (modified.getContainer() != this) {
             // shared state was modified
             local = cache.retrieve(modified.getId());
@@ -416,6 +417,12 @@
         }
         if (local != null) {
             dispatcher.notifyStateModified(local);
+        } else if (modified.isNode()) {
+            // if the state is not ours (and is not cached) it could have been
+            // vanished from the week-ref cache due to a gc. but there could
+            // still be some listeners (e.g. CachingHierarchyManager) that want
+            // to get notified.
+            dispatcher.notifyNodeModified((NodeState) modified);
         }
     }
 
@@ -487,6 +494,16 @@
      */
     public void nodesReplaced(NodeState state) {
         dispatcher.notifyNodesReplaced(state);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Optimization: shared state manager we're listening to does not deliver node state
changes, therefore the state
+     * concerned must be a local state.
+     */
+    public void nodeModified(NodeState state) {
+        dispatcher.notifyNodeModified(state);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/NodeStateListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/NodeStateListener.java?view=diff&rev=470745&r1=470744&r2=470745
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/NodeStateListener.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/NodeStateListener.java
Fri Nov  3 02:09:04 2006
@@ -37,6 +37,17 @@
                    QName name, int index, NodeId id);
 
     /**
+     * Called when a node has been modified, typically as a result of removal
+     * or addition of a child node.
+     * <p/>
+     * Please note, that this method is not called if 
+     * {@link #stateModified(ItemState)} was called.
+     *
+     * @param state node state that changed
+     */
+    void nodeModified(NodeState state);
+
+    /**
      * Called when the children nodes were replaced by other nodes, typically
      * as result of a reorder operation.
      *

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java?view=diff&rev=470745&r1=470744&r2=470745
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
Fri Nov  3 02:09:04 2006
@@ -21,24 +21,25 @@
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.ItemId;
 import org.apache.jackrabbit.core.NodeId;
-import org.apache.jackrabbit.core.ZombieHierarchyManager;
 import org.apache.jackrabbit.core.PropertyId;
+import org.apache.jackrabbit.core.ZombieHierarchyManager;
 import org.apache.jackrabbit.core.util.Dumpable;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.QName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.ReferentialIntegrityException;
-import javax.jcr.RepositoryException;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Collection;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.RepositoryException;
 
 /**
  * Item state manager that handles both transient and persistent items.
@@ -82,9 +83,9 @@
     /**
      * Creates a new <code>SessionItemStateManager</code> instance.
      *
-     * @param rootNodeId
-     * @param stateMgr
-     * @param nsResolver
+     * @param rootNodeId the root node id
+     * @param stateMgr the local item state manager
+     * @param nsResolver the namespace resolver
      */
     public SessionItemStateManager(NodeId rootNodeId,
                                    LocalItemStateManager stateMgr,
@@ -839,6 +840,18 @@
     public void nodesReplaced(NodeState state) {
         if (state.getContainer() == this || !transientStore.contains(state.getId())) {
             dispatcher.notifyNodesReplaced(state);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Pass notification to listeners if a transient state was modified
+     * or if the local state is not overlayed.
+     */
+    public void nodeModified(NodeState state) {
+        if (state.getContainer() == this || !transientStore.contains(state.getId())) {
+            dispatcher.notifyNodeModified(state);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/StateChangeDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/StateChangeDispatcher.java?view=diff&rev=470745&r1=470744&r2=470745
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/StateChangeDispatcher.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/state/StateChangeDispatcher.java
Fri Nov  3 02:09:04 2006
@@ -177,6 +177,25 @@
     /**
      * Notify listeners about changes to some state.
      * @param state node state that changed
+     */
+    public void notifyNodeModified(NodeState state) {
+        // small optimization as there are only a few clients interested in node state modifications
+        if (!nsListeners.isEmpty()) {
+            NodeStateListener[] la;
+            synchronized (nsListeners) {
+                la = (NodeStateListener[]) nsListeners.toArray(new NodeStateListener[nsListeners.size()]);
+            }
+            for (int i = 0; i < la.length; i++) {
+                if (la[i] != null) {
+                    la[i].nodeModified(state);
+                }
+            }
+        }
+    }
+
+    /**
+     * Notify listeners about changes to some state.
+     * @param state node state that changed
      * @param name  name of node that was added
      * @param index index of new node
      * @param id    id of new node



Mime
View raw message