roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r470630 - in /incubator/roller/branches/roller_3.1/src/org/apache/roller: business/HitCountQueue.java business/pings/PingQueueProcessor.java business/runnable/HitCountProcessingJob.java ui/rendering/servlets/ResourceServlet.java
Date Fri, 03 Nov 2006 01:33:05 GMT
Author: agilliland
Date: Thu Nov  2 17:33:03 2006
New Revision: 470630

URL: http://svn.apache.org/viewvc?view=rev&rev=470630
Log:
merging changes from trunk between revisions 470519 and 470627 which includes these changes
...

- fixes closing of resource streams in ResourceServlet if there is an exception
- updates ping queue processor to be a little less verbose with WARN messages
- updates process of hit count tracking


Modified:
    incubator/roller/branches/roller_3.1/src/org/apache/roller/business/HitCountQueue.java
    incubator/roller/branches/roller_3.1/src/org/apache/roller/business/pings/PingQueueProcessor.java
    incubator/roller/branches/roller_3.1/src/org/apache/roller/business/runnable/HitCountProcessingJob.java
    incubator/roller/branches/roller_3.1/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java

Modified: incubator/roller/branches/roller_3.1/src/org/apache/roller/business/HitCountQueue.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.1/src/org/apache/roller/business/HitCountQueue.java?view=diff&rev=470630&r1=470629&r2=470630
==============================================================================
--- incubator/roller/branches/roller_3.1/src/org/apache/roller/business/HitCountQueue.java
(original)
+++ incubator/roller/branches/roller_3.1/src/org/apache/roller/business/HitCountQueue.java
Thu Nov  2 17:33:03 2006
@@ -20,10 +20,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.business.runnable.ContinuousWorkerThread;
@@ -38,10 +35,10 @@
  * an asynchronous manner at give intervals.
  *
  * We also start up a single thread which runs continously to take the queued
- * hit counts and record them into the db.
+ * hit counts, tally them, and record them into the db.
  *
  * TODO: we may want to make this an interface that is pluggable if there is
- *   some indication that users may want to override this implementation.
+ *   some indication that users want to override this implementation.
  */
 public class HitCountQueue {
     
@@ -52,7 +49,7 @@
     private int numWorkers = 1;
     private int sleepTime = 180000;
     private WorkerThread worker = null;
-    private Map queue = null;
+    private List queue = null;
     
     
     static {
@@ -73,7 +70,7 @@
         }
         
         // create the hits queue
-        this.queue = Collections.synchronizedMap(new HashMap());
+        this.queue = Collections.synchronizedList(new ArrayList());
         
         // start up a worker to process the hits at intervals
         HitCountProcessingJob job = new HitCountProcessingJob();
@@ -89,19 +86,16 @@
     
     public void processHit(WebsiteData weblog, String url, String referrer) {
         
-        // just update the count for the weblog
-        Long count = (Long) this.queue.get(weblog.getHandle());
-        if(count == null) {
-            count = new Long(1);
-        } else {
-            count = new Long(count.longValue()+1);
+        // if the weblog isn't null then just drop it's handle in the queue
+        // each entry in the queue is a weblog handle and indicates a single hit
+        if(weblog != null) {
+            this.queue.add(weblog.getHandle());
         }
-        this.queue.put(weblog.getHandle(), count);
     }
     
     
-    public Map getHits() {
-        return new HashMap(this.queue);
+    public List getHits() {
+        return new ArrayList(this.queue);
     }
     
     
@@ -109,7 +103,7 @@
      * Reset the queued hits.
      */
     public synchronized void resetHits() {
-        this.queue = Collections.synchronizedMap(new HashMap());
+        this.queue = Collections.synchronizedList(new ArrayList());
     }
     
     

Modified: incubator/roller/branches/roller_3.1/src/org/apache/roller/business/pings/PingQueueProcessor.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.1/src/org/apache/roller/business/pings/PingQueueProcessor.java?view=diff&rev=470630&r1=470629&r2=470630
==============================================================================
--- incubator/roller/branches/roller_3.1/src/org/apache/roller/business/pings/PingQueueProcessor.java
(original)
+++ incubator/roller/branches/roller_3.1/src/org/apache/roller/business/pings/PingQueueProcessor.java
Thu Nov  2 17:33:03 2006
@@ -16,22 +16,20 @@
  * directory of this distribution.
  */
 
-
 package org.apache.roller.business.pings;
 
+import java.util.Iterator;
+import java.util.List;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
+import org.apache.roller.business.RollerFactory;
 import org.apache.roller.config.PingConfig;
 import org.apache.roller.config.RollerRuntimeConfig;
-import org.apache.roller.business.pings.PingQueueManager;
-import org.apache.roller.business.RollerFactory;
 import org.apache.roller.pojos.PingQueueEntryData;
 import org.apache.roller.pojos.PingTargetData;
 import org.apache.roller.pojos.WebsiteData;
 
-import java.util.Iterator;
-import java.util.List;
 
 /**
  * Ping Queue Processor.  Singleton encapsulating logic for processing the weblog update
ping queue.
@@ -39,21 +37,24 @@
  * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
  */
 public class PingQueueProcessor {
+    
     private static final Log logger = LogFactory.getLog(PingQueueProcessor.class);
-
+    
     private static PingQueueProcessor theInstance;
-
-
+    
     private PingQueueManager pingQueueMgr;
-
+    
+    
     public static PingQueueProcessor getInstance() {
         return theInstance;
     }
-
+    
+    
     private PingQueueProcessor() throws RollerException {
         pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
     }
-
+    
+    
     /**
      * Initialize the singleton.  This is called during <code>RollerContext</code>
initialization.
      *
@@ -67,7 +68,8 @@
         theInstance = new PingQueueProcessor();
         if (logger.isDebugEnabled()) logger.debug("Ping queue processor initialized.");
     }
-
+    
+    
     /**
      * Process the ping queue.  Performs one pass through the ping queue, processing every
entry once.  On ping failure
      * an entry is requeued for processing on subsequent passes until the configured maximum
number of attempts is
@@ -78,23 +80,23 @@
             logger.info("Ping processing has been suspended.  Skipping current round of ping
queue processing.");
             return;
         }
-
+        
         String absoluteContextUrl = RollerRuntimeConfig.getAbsoluteContextURL();
         if (absoluteContextUrl == null) {
             logger.warn("WARNING: Skipping current ping queue processing round because we
cannot yet determine the site's absolute context url.");
             return;
         }
-
+        
         // TODO: Group by ping target and ping all sites for that target?
         // We're currently not taking advantage of grouping by ping target site and then
sending
         // all of the pings for that target at once.  If it becomes an efficiency issue,
we should do
         // that.
-
+        
         try {
             if (logger.isDebugEnabled()) logger.debug("Started processing ping queue.");
             // Get all of the entries
             List entries = pingQueueMgr.getAllQueueEntries();
-
+            
             // Process each entry
             for (Iterator i = entries.iterator(); i.hasNext();) {
                 PingQueueEntryData pingQueueEntry = (PingQueueEntryData) i.next();
@@ -105,7 +107,8 @@
             logger.error("Unexpected exception processing ping queue!  Aborting this pass
of ping queue processing.", ex);
         }
     }
-
+    
+    
     /**
      * Process an individual ping queue entry.
      *
@@ -115,7 +118,7 @@
      */
     private void processQueueEntry(PingQueueEntryData pingQueueEntry) throws RollerException
{
         if (logger.isDebugEnabled()) logger.debug("Processing ping queue entry: " + pingQueueEntry);
-
+        
         PingTargetData pingTarget = pingQueueEntry.getPingTarget();
         WebsiteData website = pingQueueEntry.getWebsite();
         boolean pingSucceeded = false;
@@ -142,7 +145,8 @@
             pingQueueMgr.removeQueueEntry(pingQueueEntry);
         }
     }
-
+    
+    
     /**
      * Handle any ping error.
      *
@@ -150,22 +154,22 @@
      * @param ex             the exception that occurred on the ping attempt
      * @throws RollerException
      */
-    private void handlePingError(PingQueueEntryData pingQueueEntry, Exception ex) throws
RollerException {
-        if ((pingQueueEntry.incrementAttempts() < PingConfig.getMaxPingAttempts()) &&
WeblogUpdatePinger.shouldRetry(ex))
-        {
+    private void handlePingError(PingQueueEntryData pingQueueEntry, Exception ex)
+            throws RollerException {
+        
+        if ((pingQueueEntry.incrementAttempts() < PingConfig.getMaxPingAttempts()) &&
WeblogUpdatePinger.shouldRetry(ex)) {
             // We have attempts remaining, and it looks like we should retry,
             // so requeue the entry for processing on subsequent rounds
-            logger.warn("Error on ping attempt (" + pingQueueEntry.getAttempts() + ") for
" + pingQueueEntry + ": [" + ex.getMessage() + "]. Will re-queue for later attempts.");
-            if (logger.isDebugEnabled()) logger.debug("Error on last ping attempt was: ",
ex);
+            logger.debug("Error on ping attempt (" + pingQueueEntry.getAttempts() + ") for
" + pingQueueEntry + ": [" + ex.getMessage() + "]. Will re-queue for later attempts.");
+            logger.debug("Error on last ping attempt was: ", ex);
             pingQueueMgr.saveQueueEntry(pingQueueEntry);
         } else {
             // Remove the entry
             logger.warn("Error on ping attempt (" + pingQueueEntry.getAttempts() + ") for
" + pingQueueEntry + ": [" + ex.getMessage() + "].  Entry will be REMOVED from ping queue.");
-            if (logger.isDebugEnabled()) logger.debug("Error on last ping attempt was: ",
ex);
+            logger.debug("Error on last ping attempt was: ", ex);
             pingQueueMgr.removeQueueEntry(pingQueueEntry);
             // TODO: mark ping target invalid?
         }
     }
-
-
+    
 }

Modified: incubator/roller/branches/roller_3.1/src/org/apache/roller/business/runnable/HitCountProcessingJob.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.1/src/org/apache/roller/business/runnable/HitCountProcessingJob.java?view=diff&rev=470630&r1=470629&r2=470630
==============================================================================
--- incubator/roller/branches/roller_3.1/src/org/apache/roller/business/runnable/HitCountProcessingJob.java
(original)
+++ incubator/roller/branches/roller_3.1/src/org/apache/roller/business/runnable/HitCountProcessingJob.java
Thu Nov  2 17:33:03 2006
@@ -18,7 +18,9 @@
 
 package org.apache.roller.business.runnable;
 
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -61,34 +63,48 @@
             return;
         }
         
-        HitCountQueue counter = HitCountQueue.getInstance();
-        HitCountQueue hitCounter = (HitCountQueue) counter;
+        HitCountQueue hitCounter = HitCountQueue.getInstance();
         
         // first get the current set of hits
-        Map currentHits = hitCounter.getHits();
+        List currentHits = hitCounter.getHits();
         
         // now reset the queued hits
         hitCounter.resetHits();
         
-        // iterate over the hits and store them in the db
+        // tally the counts, grouped by weblog handle
+        Map hitsTally = new HashMap();
+        String weblogHandle = null;
+        for(int i=0; i < currentHits.size(); i++) {
+            weblogHandle = (String) currentHits.get(i);
+            
+            Long count = (Long) hitsTally.get(weblogHandle);
+            if(count == null) {
+                count = new Long(1);
+            } else {
+                count = new Long(count.longValue()+1);
+            }
+            hitsTally.put(weblogHandle, count);
+        }
+        
+        // iterate over the tallied hits and store them in the db
         try {
             long startTime = System.currentTimeMillis();
             
             WebsiteData weblog = null;
             String key = null;
-            Iterator it = currentHits.keySet().iterator();
+            Iterator it = hitsTally.keySet().iterator();
             while(it.hasNext()) {
                 key = (String) it.next();
                 
                 try {
                     weblog = umgr.getWebsiteByHandle(key);
-                    wmgr.incrementHitCount(weblog, ((Long)currentHits.get(key)).intValue());
+                    wmgr.incrementHitCount(weblog, ((Long)hitsTally.get(key)).intValue());
                 } catch (RollerException ex) {
                     log.error(ex);
                 }
             }
             
-            // make sure and flush the results
+            // flush the results to the db
             RollerFactory.getRoller().flush();
             
             long endTime = System.currentTimeMillis();

Modified: incubator/roller/branches/roller_3.1/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.1/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java?view=diff&rev=470630&r1=470629&r2=470630
==============================================================================
--- incubator/roller/branches/roller_3.1/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
(original)
+++ incubator/roller/branches/roller_3.1/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
Thu Nov  2 17:33:03 2006
@@ -158,16 +158,17 @@
                 out.write(buf, 0, length);
             }
             
-            // cleanup
+            // close output stream
             out.close();
-            resourceStream.close();
             
         } catch (Exception ex) {
-            log.error("Error writing resource file", ex);
             if(!response.isCommitted()) {
                 response.reset();
                 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             }
+        } finally {
+            // make sure stream to resource file is closed
+            resourceStream.close();
         }
 
     }



Mime
View raw message