Author: bcarothers
Date: 2010-01-07 09:47:53 -0500 (Thu, 07 Jan 2010)
New Revision: 1551
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultCacheStatistics.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/NoCachePolicy.java
Removed:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultPathCachePolicy.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySource.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/InMemoryWorkspaceCache.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/PathRepositoryCache.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/WorkspaceCache.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/package-info.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySourceTest.java
Log:
DNA-626 Change Default Path Repository Cache Behavior to Not Cache
Applied patch that reverts the default caching behavior for the path repository
implementations to not cache. It is still possible to override the cache policy for any
path repository by calling setCachePolicy(PathCachePolicy) on the repository source.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySource.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySource.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySource.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -37,7 +37,7 @@
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.connector.RepositoryContext;
import org.jboss.dna.graph.connector.RepositorySourceException;
-import org.jboss.dna.graph.connector.path.cache.DefaultPathCachePolicy;
+import org.jboss.dna.graph.connector.path.cache.NoCachePolicy;
import org.jboss.dna.graph.connector.path.cache.PathCachePolicy;
import org.jboss.dna.graph.connector.path.cache.PathRepositoryCache;
@@ -59,12 +59,10 @@
*/
public static final int DEFAULT_RETRY_LIMIT = 0;
- private static final int DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS = 30;
-
/**
- * The default cache policy for this repository source (cache all nodes which remain
valid for 30 seconds)
+ * The default cache policy for this repository source (no caching)
*/
- public static final PathCachePolicy DEFAULT_CACHE_POLICY = new
DefaultPathCachePolicy(DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS);
+ public static final PathCachePolicy DEFAULT_CACHE_POLICY = new NoCachePolicy();
protected int retryLimit = DEFAULT_RETRY_LIMIT;
protected String name;
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultCacheStatistics.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultCacheStatistics.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultCacheStatistics.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -0,0 +1,48 @@
+package org.jboss.dna.graph.connector.path.cache;
+
+import java.util.concurrent.atomic.AtomicLong;
+import net.jcip.annotations.ThreadSafe;
+
+/**
+ * Default, thread-safe implementation of {@link CacheStatistics} that uses {@link
AtomicLong AtomicLongs} as counters for the
+ * statistics.
+ */
+@ThreadSafe
+public final class DefaultCacheStatistics implements CacheStatistics {
+ private final AtomicLong writes = new AtomicLong(0);
+ private final AtomicLong hits = new AtomicLong(0);
+ private final AtomicLong misses = new AtomicLong(0);
+ private final AtomicLong expirations = new AtomicLong(0);
+
+ public long getWrites() {
+ return writes.get();
+ }
+
+ public long getHits() {
+ return hits.get();
+ }
+
+ public long getMisses() {
+ return misses.get();
+ }
+
+ public long getExpirations() {
+ return expirations.get();
+ }
+
+ public long incrementWrites() {
+ return writes.getAndIncrement();
+ }
+
+ public long incrementHits() {
+ return hits.getAndIncrement();
+ }
+
+ public long incrementMisses() {
+ return misses.getAndIncrement();
+ }
+
+ public long incrementExpirations() {
+ return expirations.getAndIncrement();
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultCacheStatistics.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultPathCachePolicy.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultPathCachePolicy.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultPathCachePolicy.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -1,63 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.graph.connector.path.cache;
-
-import net.jcip.annotations.Immutable;
-import org.jboss.dna.graph.connector.path.PathNode;
-
-/**
- * Trivial path cache policy implementation that caches all nodes in an in-memory cache.
- * <p>
- * As a result, this cache policy may not be safe for use with some large repositories as
it does not attempt to limit cache
- * attempts based on the size of the node or the current size of the cache.
- * </p>
- */
-@Immutable
-public class DefaultPathCachePolicy implements PathCachePolicy {
-
- private static final long serialVersionUID = 1L;
-
- private final long cacheTimeToLiveInSeconds;
-
- public DefaultPathCachePolicy( long cacheTimeToLiveInSeconds ) {
- super();
- this.cacheTimeToLiveInSeconds = cacheTimeToLiveInSeconds;
- }
-
- /**
- * @return true for all nodes
- * @see PathCachePolicy#shouldCache(PathNode)
- */
- public boolean shouldCache( PathNode node ) {
- return true;
- }
-
- public long getTimeToLive() {
- return this.cacheTimeToLiveInSeconds;
- }
-
- public Class<? extends WorkspaceCache> getCacheClass() {
- return InMemoryWorkspaceCache.class;
- }
-}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/InMemoryWorkspaceCache.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/InMemoryWorkspaceCache.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/InMemoryWorkspaceCache.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -27,7 +27,6 @@
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicLong;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.graph.connector.path.PathNode;
import org.jboss.dna.graph.property.Path;
@@ -39,9 +38,10 @@
public class InMemoryWorkspaceCache implements WorkspaceCache {
private final ConcurrentMap<Path, CacheEntry> nodesByPath = new
ConcurrentHashMap<Path, CacheEntry>();
private PathCachePolicy policy = null;
- private InMemoryStatistics statistics = new InMemoryStatistics();
+ private DefaultCacheStatistics statistics = new DefaultCacheStatistics();
- public void initialize( PathCachePolicy policy ) {
+ public void initialize( PathCachePolicy policy,
+ String workspaceName ) {
if (this.policy != null) {
throw new IllegalStateException();
}
@@ -49,8 +49,12 @@
this.policy = policy;
}
+ protected PathCachePolicy policy() {
+ return policy;
+ }
+
public void clearStatistics() {
- statistics = new InMemoryStatistics();
+ statistics = new DefaultCacheStatistics();
}
public CacheStatistics getStatistics() {
@@ -81,7 +85,7 @@
assert node != null;
if (!policy.shouldCache(node)) return;
-
+
statistics.incrementWrites();
nodesByPath.put(node.getPath(), new CacheEntry(node));
}
@@ -104,10 +108,6 @@
this.statistics = null;
}
- protected PathCachePolicy policy() {
- return this.policy;
- }
-
class CacheEntry {
private final SoftReference<PathNode> ref;
private final long expiryTime;
@@ -126,42 +126,38 @@
}
}
- class InMemoryStatistics implements CacheStatistics {
- private final AtomicLong writes = new AtomicLong(0);
- private final AtomicLong hits = new AtomicLong(0);
- private final AtomicLong misses = new AtomicLong(0);
- private final AtomicLong expirations = new AtomicLong(0);
+ /**
+ * Trivial path cache policy implementation that caches all nodes in an in-memory
cache.
+ * <p>
+ * As a result, this cache policy may not be safe for use with some large
repositories as it does not attempt to limit cache
+ * attempts based on the size of the node or the current size of the cache.
+ * </p>
+ */
+ public static class InMemoryCachePolicy implements PathCachePolicy {
- public long getWrites() {
- return writes.get();
- }
+ private static final long serialVersionUID = 1L;
- public long getHits() {
- return hits.get();
- }
+ private final long cacheTimeToLiveInSeconds;
- public long getMisses() {
- return misses.get();
+ public InMemoryCachePolicy( long cacheTimeToLiveInSeconds ) {
+ super();
+ this.cacheTimeToLiveInSeconds = cacheTimeToLiveInSeconds;
}
- public long getExpirations() {
- return expirations.get();
+ /**
+ * @return true for all nodes
+ * @see PathCachePolicy#shouldCache(PathNode)
+ */
+ public boolean shouldCache( PathNode node ) {
+ return true;
}
- public long incrementWrites() {
- return writes.getAndIncrement();
+ public long getTimeToLive() {
+ return this.cacheTimeToLiveInSeconds;
}
- public long incrementHits() {
- return hits.getAndIncrement();
+ public Class<? extends WorkspaceCache> getCacheClass() {
+ return InMemoryWorkspaceCache.class;
}
-
- public long incrementMisses() {
- return misses.getAndIncrement();
- }
-
- public long incrementExpirations() {
- return expirations.getAndIncrement();
- }
}
}
Copied:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/NoCachePolicy.java
(from rev 1529,
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/DefaultPathCachePolicy.java)
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/NoCachePolicy.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/NoCachePolicy.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -0,0 +1,52 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph.connector.path.cache;
+
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.graph.connector.path.PathNode;
+
+/**
+ * Trivial path cache policy implementation that performs no caching at all
+ */
+@Immutable
+public class NoCachePolicy implements PathCachePolicy {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @return false for all nodes
+ * @see PathCachePolicy#shouldCache(PathNode)
+ */
+ public boolean shouldCache( PathNode node ) {
+ return false;
+ }
+
+ public long getTimeToLive() {
+ return 0;
+ }
+
+ public Class<? extends WorkspaceCache> getCacheClass() {
+ return InMemoryWorkspaceCache.class;
+ }
+}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/PathRepositoryCache.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/PathRepositoryCache.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/PathRepositoryCache.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -63,18 +63,18 @@
WorkspaceCache cache = cachesByName.get(workspaceName);
if (cache != null) return cache;
- cache = newCache();
+ cache = newCache(workspaceName);
cachesByName.putIfAbsent(workspaceName, cache);
return cachesByName.get(workspaceName);
}
- private final WorkspaceCache newCache() {
+ private final WorkspaceCache newCache( String workspaceName ) {
WorkspaceCache cache = null;
try {
cache = policy.getCacheClass().newInstance();
- cache.initialize(policy);
+ cache.initialize(policy, workspaceName);
} catch (IllegalAccessException iae) {
throw new IllegalStateException(iae);
} catch (InstantiationException ie) {
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/WorkspaceCache.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/WorkspaceCache.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/WorkspaceCache.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -31,7 +31,7 @@
* The basic contract for a workspace-level cache of paths to the nodes stored at that
path.
* <p>
* Implementations must provide a no-argument constructor in order to be instantiated by
{@link PathRepositoryCache}. After
- * instantiation, the {@link #initialize(PathCachePolicy)} method will be called to
inject the cache policy into the
+ * instantiation, the {@link #initialize(PathCachePolicy, String)} method will be called
to inject the cache policy into the
* implementation.
* </p>
* <p>
@@ -45,9 +45,11 @@
* Injects the cache policy into the cache
*
* @param policy the active cache policy for the repository source with which this
cache is associated
+ * @param workspaceName the name of the workspace that this cache is managing
* @throws IllegalStateException if this method is called on a cache that has already
been initialized.
*/
- public void initialize( PathCachePolicy policy );
+ public void initialize( PathCachePolicy policy,
+ String workspaceName );
/**
* Clears all statistics for this cache
@@ -71,7 +73,7 @@
/**
* Attempts to cache the given node. Implementations must call {@link
PathCachePolicy#shouldCache(PathNode)} on the policy
- * from the {@link #initialize(PathCachePolicy)} method to determine if the node
should be cached.
+ * from the {@link #initialize(PathCachePolicy, String)} method to determine if the
node should be cached.
*
* @param node the node that is to be cached; may not be null
*/
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/package-info.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/package-info.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/path/cache/package-info.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -29,7 +29,7 @@
* <p>
* Each {@code AbstractPathRepositorySource} has a local instance of {@link
PathRepositoryCache} that reads the {@code PathCachePolicy} for the source and uses it to
create instances of
* {@link WorkspaceCache} for each workspace in the repository. When a workspace cache
instance is requested for the first time from the {@link
PathRepositoryCache#getCache(String)} method,
- * an instance of the class is created using the no-argument constructor for the class
and {@link WorkspaceCache#initialize(PathCachePolicy)} is called with the current cache
policy.
+ * an instance of the class is created using the no-argument constructor for the class
and {@link WorkspaceCache#initialize(PathCachePolicy, String)} is called with the current
cache policy.
* </p>
* <p>
* When {@link
org.jboss.dna.graph.connector.path.AbstractPathRepositorySource#setCachePolicy(PathCachePolicy)
the cache policy is changed} on the source, the existing {@code PathRepositoryCache}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySourceTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySourceTest.java 2010-01-07
14:43:33 UTC (rev 1550)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/path/AbstractPathRepositorySourceTest.java 2010-01-07
14:47:53 UTC (rev 1551)
@@ -134,7 +134,8 @@
boolean closed = false;
PathCachePolicy policy;
- public void initialize( PathCachePolicy policy ) {
+ public void initialize( PathCachePolicy policy,
+ String workspaceName ) {
this.policy = policy;
}