roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r421331 - /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java
Date Wed, 12 Jul 2006 17:30:51 GMT
Author: agilliland
Date: Wed Jul 12 10:30:51 2006
New Revision: 421331

URL: http://svn.apache.org/viewvc?rev=421331&view=rev
Log:
updating planet cache filter to use new PlanetCache class.


Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java?rev=421331&r1=421330&r2=421331&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/filters/PlanetCacheFilter.java
Wed Jul 12 10:30:51 2006
@@ -1,33 +1,24 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-/*
- * PlanetCacheFilter.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * Created on December 12, 2005, 10:03 AM
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
  */
 
 package org.apache.roller.ui.rendering.filters;
 
 import java.io.IOException;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -39,45 +30,24 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.config.RollerConfig;
-import org.apache.roller.pojos.BookmarkData;
-import org.apache.roller.pojos.CommentData;
-import org.apache.roller.pojos.FolderData;
-import org.apache.roller.pojos.RefererData;
-import org.apache.roller.pojos.UserData;
-import org.apache.roller.pojos.WeblogCategoryData;
-import org.apache.roller.pojos.WeblogEntryData;
-import org.apache.roller.pojos.WeblogTemplate;
-import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.ui.rendering.util.PlanetRequest;
-import org.apache.roller.util.cache.Cache;
-import org.apache.roller.util.cache.CacheHandler;
-import org.apache.roller.util.cache.CacheManager;
 import org.apache.roller.ui.core.util.CacheHttpServletResponseWrapper;
 import org.apache.roller.ui.core.util.ResponseContent;
+import org.apache.roller.ui.rendering.util.PlanetCache;
+
 
 /**
- * A cache filter for Planet Roller items ... /planet.do, /planetrss
+ * A cache filter for Planet Roller page ... /planet.do
  *
  * @web.filter name="PlanetCacheFilter"
- *
- * @author Allen Gilliland
  */
-public class PlanetCacheFilter implements Filter, CacheHandler {
+public class PlanetCacheFilter implements Filter {
     
-    private static Log mLogger = LogFactory.getLog(PlanetCacheFilter.class);
+    private static Log log = LogFactory.getLog(PlanetCacheFilter.class);
     
-    // a unique identifier for this cache, this is used as the prefix for
-    // roller config properties that apply to this cache
-    private static final String CACHE_ID = "cache.planet";
+    private PlanetCache planetCache = null;
     
     private boolean excludeOwnerPages = false;
-    private Cache mCache = null;
-    
-    // for metrics
-    private double hits = 0;
-    private double misses = 0;
-    private double skips = 0;
-    private Date startTime = new Date();
     
     
     /**
@@ -86,7 +56,7 @@
     public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
             throws IOException, ServletException {
         
-        mLogger.debug("entering");
+        log.debug("entering");
         
         HttpServletRequest request = (HttpServletRequest) req;
         HttpServletResponse response = (HttpServletResponse) res;
@@ -96,7 +66,7 @@
             planetRequest = new PlanetRequest(request);
         } catch(Exception e) {
             // some kind of error parsing the request
-            mLogger.error("error creating planet request", e);
+            log.error("error creating planet request", e);
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
             return;
         }
@@ -106,13 +76,10 @@
         try {
             ResponseContent respContent = null;
             if(!this.excludeOwnerPages || !planetRequest.isLoggedIn()) {
-                respContent = (ResponseContent) this.mCache.get(key);
+                respContent = (ResponseContent) this.planetCache.get(key);
             }
             
             if(respContent == null) {
-
-                mLogger.debug("MISS "+key);
-                this.misses++;
                 
                 CacheHttpServletResponseWrapper cacheResponse =
                         new CacheHttpServletResponseWrapper(response);
@@ -123,26 +90,21 @@
                 
                 // only cache if we didn't get an exception
                 if (request.getAttribute("DisplayException") == null) {
-                    ResponseContent rc = cacheResponse.getContent();
                     
                     // only cache if this is not a logged in user?
                     if(!this.excludeOwnerPages || !planetRequest.isLoggedIn()) {
-                        this.mCache.put(key, rc);
+                        ResponseContent rc = cacheResponse.getContent();
+                        this.planetCache.put(key, rc);
                     } else {
-                        mLogger.debug("SKIPPED "+key);
-                        this.skips++;
+                        log.debug("SKIPPED "+key);
                     }
                 } else {
                     // it is expected that whoever caught this display exception
                     // is the one who reported it to the logs
-                    mLogger.debug("Display exception "+key);
+                    log.debug("Display exception "+key);
                 }
                 
             } else {
-                
-                mLogger.debug("HIT "+key);
-                this.hits++;
-                
                 respContent.writeTo(response);
             }
             
@@ -150,21 +112,21 @@
             
             if(ex.getMessage().indexOf("ClientAbort") != -1) {
                 // ClientAbortException ... ignored
-                mLogger.debug(ex.getMessage());
+                log.debug(ex.getMessage());
                 
             } else if(ex.getMessage().indexOf("SocketException") != -1) {
                 // SocketException ... ignored
-                mLogger.debug(ex.getMessage());
+                log.debug(ex.getMessage());
                 
             } else {
-                mLogger.error("Unexpected exception rendering page "+key, ex);
+                log.error("Unexpected exception rendering page "+key, ex);
             }
             
             // gotta send something to the client
             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
         }
         
-        mLogger.debug("exiting");
+        log.debug("exiting");
     }
     
     
@@ -214,110 +176,6 @@
     
     
     /**
-     * A weblog entry has changed.
-     */
-    public void invalidate(WeblogEntryData entry) {
-        // ignored
-    }
-    
-    
-    /**
-     * A weblog has changed.
-     */
-    public void invalidate(WebsiteData website) {
-        // ignored
-    }
-    
-    
-    /**
-     * A bookmark has changed.
-     */
-    public void invalidate(BookmarkData bookmark) {
-        // ignored
-    }
-    
-    
-    /**
-     * A folder has changed.
-     */
-    public void invalidate(FolderData folder) {
-        // ignored
-    }
-    
-    
-    /**
-     * A comment has changed.
-     */
-    public void invalidate(CommentData comment) {
-        // ignored
-    }
-    
-    
-    /**
-     * A referer has changed.
-     */
-    public void invalidate(RefererData referer) {
-        // ignored
-    }
-    
-    
-    /**
-     * A user profile has changed.
-     */
-    public void invalidate(UserData user) {
-        // ignored
-    }
-    
-    
-    /**
-     * A category has changed.
-     */
-    public void invalidate(WeblogCategoryData category) {
-        // ignored
-    }
-    
-    
-    /**
-     * A weblog template has changed.
-     */
-    public void invalidate(WeblogTemplate template) {
-        // ignored
-    }
-    
-    
-    /**
-     * Clear the entire cache.
-     */
-    public void clear() {
-        mLogger.info("Clearing cache");
-        this.mCache.clear();
-        this.startTime = new Date();
-        this.hits = 0;
-        this.misses = 0;
-        this.skips = 0;
-    }
-    
-    
-    public Map getStats() {
-        
-        Map stats = new HashMap();
-        stats.put("cacheType", this.mCache.getClass().getName());
-        stats.put("startTime", this.startTime);
-        stats.put("hits", new Double(this.hits));
-        stats.put("misses", new Double(this.misses));
-        stats.put("skips", new Double(this.skips));
-        
-        // calculate efficiency
-        if(misses > 0) {
-            double efficiency = hits / (misses + hits);
-            stats.put("efficiency", new Double(efficiency * 100));
-        }
-        
-        return stats;
-    }
-    
-    
-    /**
      * Destroy method for this filter
      */
     public void destroy() {
@@ -329,27 +187,12 @@
      */
     public void init(FilterConfig filterConfig) {
         
-        mLogger.info("Initializing planet cache");
+        log.info("Initializing planet cache");
         
         this.excludeOwnerPages = 
                 RollerConfig.getBooleanProperty("cache.planet.excludeOwnerEditPages");
         
-        Map cacheProps = new HashMap();
-        Enumeration allProps = RollerConfig.keys();
-        String prop = null;
-        while(allProps.hasMoreElements()) {
-            prop = (String) allProps.nextElement();
-            
-            // we are only interested in props for this cache
-            if(prop.startsWith(CACHE_ID+".")) {
-                cacheProps.put(prop.substring(CACHE_ID.length()+1), 
-                        RollerConfig.getProperty(prop));
-            }
-        }
-        
-        mLogger.info(cacheProps);
-        
-        mCache = CacheManager.constructCache(this, cacheProps);
+        this.planetCache = PlanetCache.getInstance();
     }
     
 }



Mime
View raw message