You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/02/04 10:41:20 UTC

svn commit: r618219 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon/source/ webapp/lenya/config/cocoon-xconf/source-factories/

Author: andreas
Date: Mon Feb  4 01:41:18 2008
New Revision: 618219

URL: http://svn.apache.org/viewvc?rev=618219&view=rev
Log:
Control fallback:// cache by configuration file instead of hard-coding in Java class.

Added:
    lenya/trunk/src/webapp/lenya/config/cocoon-xconf/source-factories/fallback-store.xconf.disabled
      - copied unchanged from r618212, lenya/trunk/src/webapp/lenya/config/cocoon-xconf/source-factories/fallback-store.xconf
Removed:
    lenya/trunk/src/webapp/lenya/config/cocoon-xconf/source-factories/fallback-store.xconf
Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/AggregatingFallbackSourceFactory.java
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/AggregatingFallbackSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/AggregatingFallbackSourceFactory.java?rev=618219&r1=618218&r2=618219&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/AggregatingFallbackSourceFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/AggregatingFallbackSourceFactory.java Mon Feb  4 01:41:18 2008
@@ -43,30 +43,33 @@
  */
 public class AggregatingFallbackSourceFactory extends FallbackSourceFactory {
     
-    private boolean useCache = true;
-    
     /**
      * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
      */
     public Source getSource(final String location, Map parameters) throws IOException,
             MalformedURLException {
 
-        MRUMemoryStore store = getStore();
         String[] uris;
-        final String cacheKey = getCacheKey(location);
-        final String[] cachedUris = (String[]) store.get(cacheKey);
 
-        if (!useCache || cachedUris == null) {
-            uris = findUris(location, parameters);
-            store.hold(cacheKey, uris);
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("No cached source URI for key " + cacheKey + ", caching resolved URIs.");
-            }
-        } else {
-            uris = cachedUris;
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Using cached source URIs for key " + cacheKey);
+        if (useCache()) {
+            MRUMemoryStore store = getStore();
+            final String cacheKey = getCacheKey(location);
+            final String[] cachedUris = (String[]) store.get(cacheKey);
+            if (cachedUris == null) {
+                uris = findUris(location, parameters);
+                store.hold(cacheKey, uris);
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("No cached source URI for key " + cacheKey + ", caching resolved URIs.");
+                }
+            } else {
+                uris = cachedUris;
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Using cached source URIs for key " + cacheKey);
+                }
             }
+        }
+        else {
+            uris = findUris(location, parameters);
         }
         return new AggregatingSource(location, uris, this.manager);
     }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java?rev=618219&r1=618218&r2=618219&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/source/FallbackSourceFactory.java Mon Feb  4 01:41:18 2008
@@ -63,10 +63,17 @@
         Serviceable, Contextualizable, URIAbsolutizer {
 
     protected static MRUMemoryStore store;
-    private boolean useCache = true;
-    
+    private static Boolean useCache = null;
+
     protected static final String STORE_ROLE = FallbackSourceFactory.class.getName() + "Store";
-    
+
+    protected boolean useCache() {
+        if (useCache == null) {
+            useCache = Boolean.valueOf(this.manager.hasService(STORE_ROLE));
+        }
+        return useCache.booleanValue();
+    }
+
     protected MRUMemoryStore getStore() {
         if (store == null) {
             try {
@@ -77,41 +84,51 @@
         }
         return store;
     }
-    
+
     /**
      * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
      */
     public Source getSource(final String location, Map parameters) throws IOException,
             MalformedURLException {
 
-        MRUMemoryStore store = getStore();
         Source source;
-        final String cacheKey = getCacheKey(location);
-        final String cachedSourceUri = (String) store.get(cacheKey);
 
-        if (!useCache || cachedSourceUri == null) {
-            source = findSource(location, parameters);
-            final String resolvedSourceUri = source.getURI();
-            store.hold(cacheKey, resolvedSourceUri);
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("No cached source URI for key " + cacheKey + ", caching URI " + resolvedSourceUri);
-            }
-        } else {
-            SourceResolver resolver = null;
-            try {
-                resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-                source = resolver.resolveURI(cachedSourceUri);
-            } catch (ServiceException e) {
-                throw new RuntimeException(e);
-            } finally {
-                if (resolver != null) {
-                    this.manager.release(resolver);
+        if (useCache()) {
+            MRUMemoryStore store = getStore();
+            final String cacheKey = getCacheKey(location);
+            final String cachedSourceUri = (String) store.get(cacheKey);
+
+            if (cachedSourceUri == null) {
+                source = findSource(location, parameters);
+                final String resolvedSourceUri = source.getURI();
+                store.hold(cacheKey, resolvedSourceUri);
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug(
+                            "No cached source URI for key " + cacheKey + ", caching URI "
+                                    + resolvedSourceUri);
+                }
+            } else {
+                SourceResolver resolver = null;
+                try {
+                    resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+                    source = resolver.resolveURI(cachedSourceUri);
+                } catch (ServiceException e) {
+                    throw new RuntimeException(e);
+                } finally {
+                    if (resolver != null) {
+                        this.manager.release(resolver);
+                    }
+                }
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug(
+                            "Using cached source URI " + cachedSourceUri + " for key " + cacheKey);
                 }
             }
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Using cached source URI " + cachedSourceUri + " for key " + cacheKey);
-            }
+
+        } else {
+            source = findSource(location, parameters);
         }
+
         return source;
     }
 
@@ -251,7 +268,7 @@
 
     /** The ServiceManager */
     protected ServiceManager manager;
-    
+
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org