jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r438851 [2/2] - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: ./ state/ version/ virtual/
Date Thu, 31 Aug 2006 09:38:18 GMT
Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=438851&r1=438850&r2=438851&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Thu Aug 31 02:38:17 2006
@@ -35,6 +35,8 @@
 import org.apache.jackrabbit.core.state.PersistenceManager;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.state.ItemStateListener;
+import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.name.MalformedPathException;
@@ -58,7 +60,7 @@
 /**
  * This Class implements a VersionManager.
  */
-public class VersionManagerImpl extends AbstractVersionManager {
+public class VersionManagerImpl extends AbstractVersionManager implements ItemStateListener
{
 
     /**
      * the default logger
@@ -153,7 +155,10 @@
             }
             sharedStateMgr =
                     new VersionItemStateManager(pMgr, rootId, ntReg);
+
             stateMgr = new LocalItemStateManager(sharedStateMgr, escFactory);
+            stateMgr.addListener(this);
+
             NodeState nodeState = (NodeState) stateMgr.getItemState(rootId);
             historyRoot = new NodeStateEx(stateMgr, ntReg, nodeState, QName.JCR_VERSIONSTORAGE);
 
@@ -443,6 +448,39 @@
     SharedItemStateManager getSharedStateMgr() {
         return sharedStateMgr;
     }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Not used.
+     */
+    public void stateCreated(ItemState created) {}
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Not used.
+     */
+    public void stateModified(ItemState modified) {}
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Remove item from cache on removal.
+     */
+    public void stateDestroyed(ItemState destroyed) {
+        // evict removed item from cache
+        aquireReadLock();
+        versionItems.remove(destroyed.getId());
+        releaseReadLock();
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Not used.
+     */
+    public void stateDiscarded(ItemState discarded) {}
 
     //--------------------------------------------------------< inner classes >
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=438851&r1=438850&r2=438851&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Thu Aug 31 02:38:17 2006
@@ -34,6 +34,7 @@
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.XAItemStateManager;
+import org.apache.jackrabbit.core.state.ItemStateListener;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
 import org.apache.jackrabbit.core.virtual.VirtualNodeState;
 import org.apache.jackrabbit.core.virtual.VirtualPropertyState;
@@ -298,6 +299,22 @@
             return changeLog.get(id) != null;
         }
         return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Not needed.
+     */
+    public void addListener(ItemStateListener listener) {
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Not needed.
+     */
+    public void removeListener(ItemStateListener listener) {
     }
 
     //-----------------------------------------------< AbstractVersionManager >

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java?rev=438851&r1=438850&r2=438851&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/AbstractVISProvider.java
Thu Aug 31 02:38:17 2006
@@ -35,12 +35,14 @@
 import org.apache.jackrabbit.core.state.ItemStateListener;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.uuid.UUID;
+import org.apache.jackrabbit.util.WeakIdentityCollection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.RepositoryException;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Collection;
 
 /**
  * This Class implements a virtual item state provider, in order to expose the
@@ -73,6 +75,11 @@
     private ItemStateReferenceMap nodes = new ItemStateReferenceMap();
 
     /**
+     * Listeners (weak references)
+     */
+    private final transient Collection listeners = new WeakIdentityCollection(5);
+
+    /**
      * Creates an abstract virtual item state provider
      *
      * @param ntReg
@@ -288,6 +295,25 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public void addListener(ItemStateListener listener) {
+        synchronized (listeners) {
+            assert (!listeners.contains(listener));
+            listeners.add(listener);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeListener(ItemStateListener listener) {
+        synchronized (listeners) {
+            listeners.remove(listener);
+        }
+    }
+
+    /**
      * returns the node type manager
      *
      * @return the node type manager
@@ -396,19 +422,36 @@
      * {@inheritDoc}
      */
     public void stateCreated(ItemState created) {
+        ItemStateListener[] la;
+        synchronized (listeners) {
+            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
+        }
+        for (int i = 0; i < la.length; i++) {
+            if (la[i] != null) {
+                la[i].stateCreated(created);
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public void stateModified(ItemState modified) {
+        ItemStateListener[] la;
+        synchronized (listeners) {
+            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
+        }
+        for (int i = 0; i < la.length; i++) {
+            if (la[i] != null) {
+                la[i].stateModified(modified);
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public void stateDestroyed(ItemState destroyed) {
-        destroyed.removeListener(this);
         if (destroyed.isNode() && destroyed.getId().equals(rootNodeId)) {
             try {
                 root = createRootNodeState();
@@ -417,13 +460,22 @@
             }
         }
         evict((NodeId) destroyed.getId());
+
+        ItemStateListener[] la;
+        synchronized (listeners) {
+            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
+        }
+        for (int i = 0; i < la.length; i++) {
+            if (la[i] != null) {
+                la[i].stateDestroyed(destroyed);
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      */
     public void stateDiscarded(ItemState discarded) {
-        discarded.removeListener(this);
         if (discarded.isNode() && discarded.getId().equals(rootNodeId)) {
             try {
                 root = createRootNodeState();
@@ -432,5 +484,15 @@
             }
         }
         evict((NodeId) discarded.getId());
+
+        ItemStateListener[] la;
+        synchronized (listeners) {
+            la = (ItemStateListener[]) listeners.toArray(new ItemStateListener[listeners.size()]);
+        }
+        for (int i = 0; i < la.length; i++) {
+            if (la[i] != null) {
+                la[i].stateDiscarded(discarded);
+            }
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java?rev=438851&r1=438850&r2=438851&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualItemStateProvider.java
Thu Aug 31 02:38:17 2006
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.core.state.ItemStateListener;
 import org.apache.jackrabbit.name.QName;
 
 import javax.jcr.RepositoryException;
@@ -82,4 +83,17 @@
      */
     boolean setNodeReferences(NodeReferences refs);
 
+
+    /**
+     * Add an <code>ItemStateListener</code>
+     * @param listener the new listener to be informed on modifications
+     */
+    public void addListener(ItemStateListener listener);
+
+    /**
+     * Remove an <code>ItemStateListener</code>
+     *
+     * @param listener an existing listener
+     */
+    public void removeListener(ItemStateListener listener);
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java?rev=438851&r1=438850&r2=438851&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/virtual/VirtualNodeState.java
Thu Aug 31 02:38:17 2006
@@ -65,7 +65,7 @@
             throws RepositoryException {
         super(id, nodeTypeName, parentId, ItemState.STATUS_EXISTING, false);
         this.stateMgr = stateMgr;
-        addListener(stateMgr);
+        setContainer(stateMgr);
         // add default properties
         setPropertyValue(QName.JCR_PRIMARYTYPE, InternalValue.create(nodeTypeName));
         setMixinNodeTypes(mixins);



Mime
View raw message