roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r495784 - in /incubator/roller/trunk: src/org/apache/roller/business/runnable/ src/org/apache/roller/util/cache/ web/WEB-INF/classes/
Date Fri, 12 Jan 2007 23:16:24 GMT
Author: agilliland
Date: Fri Jan 12 15:16:23 2007
New Revision: 495784

URL: http://svn.apache.org/viewvc?view=rev&rev=495784
Log:
The task for promoting scheduled entries to published status should be a RollerTask instead
of custom thread managed by the cache manager.


Added:
    incubator/roller/trunk/src/org/apache/roller/business/runnable/ScheduledEntriesTask.java
Removed:
    incubator/roller/trunk/src/org/apache/roller/util/cache/FuturePostingsInvalidationJob.java
Modified:
    incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java
    incubator/roller/trunk/web/WEB-INF/classes/roller.properties

Added: incubator/roller/trunk/src/org/apache/roller/business/runnable/ScheduledEntriesTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/ScheduledEntriesTask.java?view=auto&rev=495784
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/ScheduledEntriesTask.java
(added)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/ScheduledEntriesTask.java
Fri Jan 12 15:16:23 2007
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+package org.apache.roller.business.runnable;
+
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+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.business.WeblogManager;
+import org.apache.roller.business.search.IndexManager;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.util.cache.CacheManager;
+
+
+/**
+ * This task is used to promote SCHEDULED weblog entries to the PUBLISHED
+ * status when their publication time has been reached.
+ */
+public class ScheduledEntriesTask extends RollerTaskWithLeasing {
+    
+    private static Log log = LogFactory.getLog(ScheduledEntriesTask.class);
+    
+    // a unique id for this specific task instance
+    // this is meant to be unique for each client in a clustered environment
+    private String clientId = null;
+    
+    // a String description of when to start this task
+    private String startTimeDesc = "immediate";
+    
+    // interval at which the task is run, default is once per minute
+    private int interval = 1;
+    
+    // lease time given to task lock, default is 30 minutes
+    private int leaseTime = 30;
+    
+    
+    public String getName() {
+        return "ScheduledEntriesTask";
+    }
+    
+    public String getClientId() {
+        return clientId;
+    }
+    
+    public Date getStartTime(Date currentTime) {
+        return getAdjustedTime(currentTime, startTimeDesc);
+    }
+    
+    public int getInterval() {
+        return this.interval;
+    }
+    
+    public int getLeaseTime() {
+        return this.leaseTime;
+    }
+    
+    
+    public void init() throws RollerException {
+        
+        // get relevant props
+        Properties props = this.getTaskProperties();
+        
+        // extract clientId
+        String client = props.getProperty("clientId");
+        if(client != null) {
+            this.clientId = client;
+        }
+        
+        // extract start time
+        String startTimeStr = props.getProperty("startTime");
+        if(startTimeStr != null) {
+            this.startTimeDesc = startTimeStr;
+        }
+        
+        // extract interval
+        String intervalStr = props.getProperty("interval");
+        if(intervalStr != null) {
+            try {
+                this.interval = Integer.parseInt(intervalStr);
+            } catch (NumberFormatException ex) {
+                log.warn("Invalid interval: "+intervalStr);
+            }
+        }
+        
+        // extract lease time
+        String leaseTimeStr = props.getProperty("leaseTime");
+        if(leaseTimeStr != null) {
+            try {
+                this.leaseTime = Integer.parseInt(leaseTimeStr);
+            } catch (NumberFormatException ex) {
+                log.warn("Invalid leaseTime: "+leaseTimeStr);
+            }
+        }
+    }
+    
+    
+    /**
+     * Execute the task.
+     */
+    public void runTask() {
+        
+        try {
+            WeblogManager wMgr = RollerFactory.getRoller().getWeblogManager();
+            IndexManager searchMgr = RollerFactory.getRoller().getIndexManager();
+            
+            Date now = new Date();
+            
+            log.debug("looking up scheduled entries older than "+now);
+            
+            // get all published entries older than current time
+            List scheduledEntries = wMgr.getWeblogEntries(null, null, null, now, null, 
+                    null, null, WeblogEntryData.SCHEDULED, null, null, 0, -1);
+            
+            WeblogEntryData entry = null;
+            Iterator it = scheduledEntries.iterator();
+            while(it.hasNext()) {
+                entry = (WeblogEntryData) it.next();
+                
+                // update status to PUBLISHED and save
+                entry.setStatus(WeblogEntryData.PUBLISHED);
+                wMgr.saveWeblogEntry(entry);
+            }
+            
+            // commit the changes
+            RollerFactory.getRoller().flush();
+            
+            // take a second pass to trigger reindexing and cache invalidations
+            // this is because we need the updated entries flushed first
+            it = scheduledEntries.iterator();
+            while(it.hasNext()) {
+                entry = (WeblogEntryData) it.next();
+                
+                // trigger a cache invalidation
+                CacheManager.invalidate(entry);
+                
+                // trigger search index on entry
+                searchMgr.addEntryReIndexOperation(entry);
+            }
+            
+        } catch (RollerException e) {
+            log.error("Error getting scheduled entries", e);
+        } catch(Exception e) {
+            log.error("Unexpected exception running task", e);
+        } finally {
+            // always release
+            RollerFactory.getRoller().release();
+        }
+        
+    }
+    
+    
+    /**
+     * Main method so that this task may be run from outside the webapp.
+     */
+    public static void main(String[] args) throws Exception {
+        try {
+            ScheduledEntriesTask task = new ScheduledEntriesTask();
+            task.init();
+            task.run();
+            System.exit(0);
+        } catch (RollerException ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        }
+    }
+    
+}

Modified: incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java?view=diff&rev=495784&r1=495783&r2=495784
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/util/cache/CacheManager.java Fri Jan 12 15:16:23
2007
@@ -72,8 +72,6 @@
     // a map of all registered caches
     private static Map caches = new HashMap();
     
-    private static ContinuousWorkerThread futureInvalidationsThread = null;
-    
     
     static {
         // lookup what cache factory we want to use
@@ -126,33 +124,6 @@
                 }
             }
         }
-        
-        // determine future invalidations peering window
-        Integer peerTime = new Integer(5);
-        String peerTimeString = RollerConfig.getProperty("cache.futureInvalidations.peerTime");
-        try {
-            peerTime = new Integer(peerTimeString);
-        } catch(NumberFormatException nfe) {
-            // bad input from config file, default already set
-        }
-        
-        // thread time is always 10 secs less than peer time to make sure
-        // there is a little overlap so we don't miss any entries
-        // this means every XX seconds we peer XX + 10 seconds into the future
-        int threadTime = (peerTime.intValue() * 60 * 1000) - (10 * 1000);
-        
-        // start up future invalidations job, running continuously
-        futureInvalidationsThread = new ContinuousWorkerThread("future invalidations thread",
threadTime);
-        Job futureInvalidationsJob = new FuturePostingsInvalidationJob();
-        
-        // inputs
-        Map inputs = new HashMap();
-        inputs.put("peerTime", peerTime);
-        futureInvalidationsJob.input(inputs);
-        
-        // set job and start it
-        futureInvalidationsThread.setJob(futureInvalidationsJob);
-        futureInvalidationsThread.start();
     }
     
     
@@ -402,11 +373,7 @@
      * Place to do any cleanup tasks for cache system.
      */
     public static void shutdown() {
-        
-        // stop our future invalidations thread
-        if(futureInvalidationsThread != null) {
-            futureInvalidationsThread.interrupt();
-        }
+        // no-op
     }
     
 }

Modified: incubator/roller/trunk/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/classes/roller.properties?view=diff&rev=495784&r1=495783&r2=495784
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/roller.properties Fri Jan 12 15:16:23 2007
@@ -267,10 +267,16 @@
 # The *enabled* tasks are defined by tasks.enabled=<taskname>[,<taskname>]
 
 # Tasks which are enabled.  Only tasks listed here will be run.
-tasks.enabled=ResetHitCountsTask,TurnoverReferersTask,PingQueueTask
+tasks.enabled=ScheduledEntriesTask,ResetHitCountsTask,TurnoverReferersTask,PingQueueTask
 
 # client identifier.  should be unique for each instance in a cluster.
 tasks.clientId=defaultClientId
+
+# Publish scheduled weblog entries
+tasks.ScheduledEntriesTask.class=org.apache.roller.business.runnable.ScheduledEntriesTask
+tasks.ScheduledEntriesTask.startTime=immediate
+tasks.ScheduledEntriesTask.interval=1
+tasks.ScheduledEntriesTask.leaseTime=30
 
 # Reset hit counts
 tasks.ResetHitCountsTask.class=org.apache.roller.business.runnable.ResetHitCountsTask



Mime
View raw message