jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r605510 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state: ItemStateCache.java ItemStateReferenceCache.java LocalItemStateManager.java MLRUItemStateCache.java
Date Wed, 19 Dec 2007 10:50:16 GMT
Author: mreutegg
Date: Wed Dec 19 02:50:15 2007
New Revision: 605510

URL: http://svn.apache.org/viewvc?rev=605510&view=rev
Log:
JCR-1271: NullPointerException when iterating over properties

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java?rev=605510&r1=605509&r2=605510&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
Wed Dec 19 02:50:15 2007
@@ -18,9 +18,6 @@
 
 import org.apache.jackrabbit.core.ItemId;
 
-import java.util.Set;
-import java.util.Collection;
-
 /**
  * An <code>ItemStateCache</code> maintains a cache of <code>ItemState</code>
  * instances.
@@ -50,6 +47,13 @@
     ItemState retrieve(ItemId id);
 
     /**
+     * Returns all the cached item states.
+     *
+     * @return newly allocated item state array
+     */
+    ItemState[] retrieveAll();
+
+    /**
      * Stores the specified <code>ItemState</code> object in the map
      * using its <code>ItemId</code> as the key.
      *
@@ -77,29 +81,6 @@
      * @return <code>true</code> if this cache contains no entries.
      */
     boolean isEmpty();
-
-    /**
-     * Returns the number of entries in this cache.
-     *
-     * @return number of entries in this cache.
-     */
-    int size();
-
-    /**
-     * Returns an unmodifiable set view of the keys (i.e. <code>ItemId</code>
-     * objects) of the cached entries.
-     *
-     * @return a set view of the keys of the cached entries.
-     */
-    Set keySet();
-
-    /**
-     * Returns an unmodifiable collection view of the values (i.e.
-     * <code>ItemState</code> objects) contained in this cache.
-     *
-     * @return a collection view of the values contained in this cache.
-     */
-    Collection values();
 
     /**
      * Informs the cache that the item was modified and the cache might need to

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java?rev=605510&r1=605509&r2=605510&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
Wed Dec 19 02:50:15 2007
@@ -21,9 +21,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Set;
-import java.util.Collections;
-import java.util.Collection;
 import java.io.PrintStream;
 
 /**
@@ -42,6 +39,7 @@
  * collector if they are thus rendered weakly reachable.
  * </li>
  * </ul>
+ * This implementation of ItemStateCache is thread-safe.
  */
 public class ItemStateReferenceCache implements ItemStateCache, Dumpable {
 
@@ -86,7 +84,7 @@
     /**
      * {@inheritDoc}
      */
-    public boolean isCached(ItemId id) {
+    public synchronized boolean isCached(ItemId id) {
         // check primary cache
         return refs.contains(id);
     }
@@ -94,7 +92,7 @@
     /**
      * {@inheritDoc}
      */
-    public ItemState retrieve(ItemId id) {
+    public synchronized ItemState retrieve(ItemId id) {
         // fake call to update stats of secondary cache
         cache.retrieve(id);
 
@@ -105,7 +103,15 @@
     /**
      * {@inheritDoc}
      */
-    public void cache(ItemState state) {
+    public synchronized ItemState[] retrieveAll() {
+        // values of primary cache
+        return (ItemState[]) refs.values().toArray(new ItemState[refs.size()]);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized void cache(ItemState state) {
         ItemId id = state.getId();
         if (refs.contains(id)) {
             log.warn("overwriting cached entry " + id);
@@ -120,7 +126,7 @@
     /**
      * {@inheritDoc}
      */
-    public void evict(ItemId id) {
+    public synchronized void evict(ItemId id) {
         // fake call to update stats of secondary cache
         cache.evict(id);
         // remove from primary cache
@@ -130,14 +136,14 @@
     /**
      * {@inheritDoc}
      */
-    public void dispose() {
+    public synchronized void dispose() {
         cache.dispose();
     }
 
     /**
      * {@inheritDoc}
      */
-    public void evictAll() {
+    public synchronized void evictAll() {
         // fake call to update stats of secondary cache
         cache.evictAll();
         // remove all weak references from primary cache
@@ -147,7 +153,7 @@
     /**
      * {@inheritDoc}
      */
-    public void update(ItemId id) {
+    public synchronized void update(ItemId id) {
         // delegate
         cache.update(id);
     }
@@ -155,40 +161,16 @@
     /**
      * {@inheritDoc}
      */
-    public boolean isEmpty() {
+    public synchronized boolean isEmpty() {
         // check primary cache
         return refs.isEmpty();
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public int size() {
-        // size of primary cache
-        return refs.size();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Set keySet() {
-        // keys of primary cache
-        return Collections.unmodifiableSet(refs.keySet());
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Collection values() {
-        // values of primary cache
-        return Collections.unmodifiableCollection(refs.values());
-    }
-
     //-------------------------------------------------------------< Dumpable >
     /**
      * {@inheritDoc}
      */
-    public void dump(PrintStream ps) {
+    public synchronized void dump(PrintStream ps) {
         ps.println("ItemStateReferenceCache (" + this + ")");
         ps.println();
         ps.print("[refs] ");

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?rev=605510&r1=605509&r2=605510&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
Wed Dec 19 02:50:15 2007
@@ -35,7 +35,7 @@
      * cache of weak references to ItemState objects issued by this
      * ItemStateManager
      */
-    private final ItemStateReferenceCache cache;
+    private final ItemStateCache cache;
 
     /**
      * Shared item state manager
@@ -140,7 +140,7 @@
         }
 
         // check cache. synchronized to ensure an entry is not created twice.
-        synchronized (cache) {
+        synchronized (this) {
             state = cache.retrieve(id);
             if (state == null) {
                 // regular behaviour
@@ -333,13 +333,9 @@
 
         // this LocalItemStateManager instance is no longer needed;
         // cached item states can now be safely discarded
-
-        // JCR-798: copy cached item states to array
-        // to avoid ConcurrentModificationException
-        ItemState[] isa = (ItemState[]) cache.values().toArray(
-                new ItemState[cache.size()]);
-        for (int i = 0; i < isa.length; i++) {
-            ItemState state = isa[i];
+        ItemState[] states = cache.retrieveAll();
+        for (int i = 0; i < states.length; i++) {
+            ItemState state = states[i];
             if (state != null) {
                 dispatcher.notifyStateDiscarded(state);
                 // let the item state know that it has been disposed

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?rev=605510&r1=605509&r2=605510&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
Wed Dec 19 02:50:15 2007
@@ -16,17 +16,13 @@
  */
 package org.apache.jackrabbit.core.state;
 
+import java.util.Iterator;
+
 import org.apache.commons.collections.map.LinkedMap;
 import org.apache.jackrabbit.core.ItemId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Set;
-import java.util.Collections;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Iterator;
-
 /**
  * An <code>ItemStateCache</code> implementation that internally uses a
  * {@link LinkedMap} to maintain a cache of <code>ItemState</code> objects. The
@@ -112,6 +108,15 @@
     /**
      * {@inheritDoc}
      */
+    public ItemState[] retrieveAll() {
+        synchronized (cache) {
+            return (ItemState[]) cache.values().toArray(new ItemState[cache.size()]);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void update(ItemId id) {
         touch();
         synchronized (cache) {
@@ -185,39 +190,6 @@
     public boolean isEmpty() {
         synchronized (cache) {
             return cache.isEmpty();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public int size() {
-        synchronized (cache) {
-            return cache.size();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Set keySet() {
-        synchronized (cache) {
-            return Collections.unmodifiableSet(cache.keySet());
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Collection values() {
-        synchronized (cache) {
-            ArrayList list = new ArrayList(cache.size());
-            Iterator iter = cache.values().iterator();
-            while (iter.hasNext()) {
-                Entry entry = (Entry) iter.next();
-                list.add(entry.state);
-            }
-            return list;
         }
     }
 



Mime
View raw message