You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2008/03/26 12:58:49 UTC

svn commit: r641272 - in /jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state: ItemStateCache.java ItemStateReferenceCache.java LocalItemStateManager.java MLRUItemStateCache.java

Author: jukka
Date: Wed Mar 26 04:58:38 2008
New Revision: 641272

URL: http://svn.apache.org/viewvc?rev=641272&view=rev
Log:
1.3: Merged revision 605510 (JCR-1271)

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

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java?rev=641272&r1=641271&r2=641272&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java Wed Mar 26 04:58:38 2008
@@ -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/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java?rev=641272&r1=641271&r2=641272&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java Wed Mar 26 04:58:38 2008
@@ -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/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?rev=641272&r1=641271&r2=641272&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java Wed Mar 26 04:58:38 2008
@@ -37,7 +37,7 @@
      * cache of weak references to ItemState objects issued by this
      * ItemStateManager
      */
-    private final ItemStateReferenceCache cache;
+    private final ItemStateCache cache;
 
     /**
      * Shared item state manager
@@ -142,7 +142,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
@@ -335,13 +335,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/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?rev=641272&r1=641271&r2=641272&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java (original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java Wed Mar 26 04:58:38 2008
@@ -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;
         }
     }