roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r996336 - in /roller/trunk/weblogger-business/src: main/java/org/apache/roller/weblogger/business/ main/java/org/apache/roller/weblogger/business/pings/ main/java/org/apache/roller/weblogger/business/runnable/ main/java/org/apache/roller/we...
Date Sun, 12 Sep 2010 16:29:36 GMT
Author: snoopdave
Date: Sun Sep 12 16:29:35 2010
New Revision: 996336

URL: http://svn.apache.org/viewvc?rev=996336&view=rev
Log:
https://issues.apache.org/jira/browse/ROL-1877

Improvements to enable Roller tasks to be written in scripting language, by allowing different
instances of each task to be specified in a config file, each with different parameters (e.g.
each can have a different script file name).

Modified:
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/TestTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/pings/PingQueueTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ResetHitCountsTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTaskWithLeasing.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ScheduledEntriesTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/TurnoverReferersTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/RefreshRollerPlanetTask.java
    roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/SyncWebsitesTask.java
    roller/trunk/weblogger-business/src/test/java/org/apache/roller/weblogger/business/TaskLockTest.java

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/TestTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/TestTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/TestTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/TestTask.java
Sun Sep 12 16:29:35 2010
@@ -1,16 +1,16 @@
 package org.apache.roller.weblogger.business;
 
 import java.util.Date;
+import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.runnable.RollerTaskWithLeasing;
 
 public class TestTask extends RollerTaskWithLeasing {
-    
-    public TestTask() {
-        
-    }
+    public static String NAME = "TestTask";
+
+    public TestTask() {}
 
-    public String getName() {
-        return "TestTask";
+    public void init() throws WebloggerException {
+        this.init(TestTask.NAME);
     }
 
     public String getClientId() {
@@ -35,4 +35,5 @@ public class TestTask extends RollerTask
 
     public void runTask() {
     }
+
 }

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/pings/PingQueueTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/pings/PingQueueTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/pings/PingQueueTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/pings/PingQueueTask.java
Sun Sep 12 16:29:35 2010
@@ -18,7 +18,6 @@
 
 package org.apache.roller.weblogger.business.pings;
 
-import java.util.Calendar;
 import java.util.Date;
 import java.util.Properties;
 import org.apache.commons.logging.Log;
@@ -26,8 +25,8 @@ import org.apache.commons.logging.LogFac
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.runnable.RollerTaskWithLeasing;
 import org.apache.roller.weblogger.config.PingConfig;
-import org.apache.roller.weblogger.business.Weblogger;
 import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.business.runnable.ScheduledEntriesTask;
 
 
 /**
@@ -38,9 +37,10 @@ import org.apache.roller.weblogger.busin
  * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
  */
 public class PingQueueTask extends RollerTaskWithLeasing {
-    
     private static Log log = LogFactory.getLog(PingQueueTask.class);
-    
+
+    public static String NAME = "PingQueueTask";
+
     // 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;
@@ -55,10 +55,6 @@ public class PingQueueTask extends Rolle
     private int leaseTime = 30;
     
     
-    public String getName() {
-        return "PingQueueTask";
-    }
-    
     public String getClientId() {
         return clientId;
     }
@@ -81,7 +77,12 @@ public class PingQueueTask extends Rolle
     
     
     public void init() throws WebloggerException {
-        
+        this.init(PingQueueTask.NAME);
+    }
+
+    public void init(String name) throws WebloggerException {
+        super.init(name);
+
         // get relevant props
         Properties props = this.getTaskProperties();
         

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ResetHitCountsTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ResetHitCountsTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ResetHitCountsTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ResetHitCountsTask.java
Sun Sep 12 16:29:35 2010
@@ -31,9 +31,11 @@ import org.apache.roller.weblogger.busin
  * Reset weblog hit counts.
  */
 public class ResetHitCountsTask extends RollerTaskWithLeasing {
-    
     private static Log log = LogFactory.getLog(ResetHitCountsTask.class);
-    
+
+    public static String NAME = "ResetHitCountsTask";
+
+
     // 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;
@@ -48,10 +50,6 @@ public class ResetHitCountsTask extends 
     private int leaseTime = 30;
     
     
-    public String getName() {
-        return "ResetHitCountsTask";
-    }
-    
     public String getClientId() {
         return clientId;
     }
@@ -74,6 +72,11 @@ public class ResetHitCountsTask extends 
     
     
     public void init() throws WebloggerException {
+        this.init(ResetHitCountsTask.NAME);
+    }
+
+    public void init(String name) throws WebloggerException {
+        super.init(name);
         
         // get relevant props
         Properties props = this.getTaskProperties();

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTask.java
Sun Sep 12 16:29:35 2010
@@ -21,8 +21,6 @@ package org.apache.roller.weblogger.busi
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.util.DateUtil;
@@ -35,24 +33,25 @@ import org.apache.roller.util.DateUtil;
  * specifics.
  */
 public abstract class RollerTask implements Runnable {
-    
-    private static Log log = LogFactory.getLog(RollerTask.class);
-    
+    private String taskName = null;
+
     
     /**
-     * Initialization.  Run once before the task is started.
+     * Initialization. Run once before the task is started.
      */
-    public void init() throws WebloggerException {
-        // no-op by default
+    public void init(String name) throws WebloggerException {
+        this.taskName = name;
     }
-    
-    
+
+
     /**
      * Get the unique name for this task.
      *
      * @return The unique name for this task.
      */
-    public abstract String getName();
+    public final String getName() {
+        return taskName;
+    }
     
     
     /**
@@ -91,9 +90,9 @@ public abstract class RollerTask impleme
     
     
     /**
-     * How often should the task run, in seconds.
+     * How often should the task run, in minutes.
      *
-     * example: 3600 means this task runs once every hour.
+     * example: 60 means this task runs once every hour.
      *
      * @return The interval the task should be run at, in minutes.
      */
@@ -101,9 +100,9 @@ public abstract class RollerTask impleme
     
     
     /**
-     * Get the time, in seconds, this task wants to be leased for.
+     * Get the time, in minutes, this task wants to be leased for.
      *
-     * example: 300 means the task is allowed 5 minutes to run.
+     * example: 5 means the task is allowed 5 minutes to run.
      *
      * @return The time this task should lease its lock for, in minutes.
      */

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTaskWithLeasing.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTaskWithLeasing.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTaskWithLeasing.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/RollerTaskWithLeasing.java
Sun Sep 12 16:29:35 2010
@@ -29,7 +29,6 @@ import org.apache.roller.weblogger.busin
  * attempt to acquire a lease before doing its work.
  */
 public abstract class RollerTaskWithLeasing extends RollerTask {
-    
     private static Log log = LogFactory.getLog(RollerTaskWithLeasing.class);
     
     

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ScheduledEntriesTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ScheduledEntriesTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ScheduledEntriesTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ScheduledEntriesTask.java
Sun Sep 12 16:29:35 2010
@@ -37,9 +37,11 @@ import org.apache.roller.weblogger.util.
  * status when their publication time has been reached.
  */
 public class ScheduledEntriesTask extends RollerTaskWithLeasing {
-    
     private static Log log = LogFactory.getLog(ScheduledEntriesTask.class);
     
+    public static String NAME = "ScheduledEntriesTask";
+
+    
     // 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;
@@ -53,11 +55,7 @@ public class ScheduledEntriesTask extend
     // lease time given to task lock, default is 30 minutes
     private int leaseTime = 30;
     
-    
-    public String getName() {
-        return "ScheduledEntriesTask";
-    }
-    
+
     public String getClientId() {
         return clientId;
     }
@@ -80,7 +78,13 @@ public class ScheduledEntriesTask extend
     
     
     public void init() throws WebloggerException {
-        
+        this.init(ScheduledEntriesTask.NAME);
+    }
+
+    @Override
+    public void init(String name) throws WebloggerException {
+        super.init(name);
+
         // get relevant props
         Properties props = this.getTaskProperties();
         

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/ThreadManagerImpl.java
Sun Sep 12 16:29:35 2010
@@ -71,7 +71,7 @@ public abstract class ThreadManagerImpl 
                 try {
                     Class taskClass = Class.forName(taskClassName);
                     RollerTask task = (RollerTask) taskClass.newInstance();
-                    task.init();
+                    task.init(taskName);
                     
                     // make sure there is a tasklock record in the db
                     TaskLock taskLock = getTaskLockByName(task.getName());

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/TurnoverReferersTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/TurnoverReferersTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/TurnoverReferersTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/business/runnable/TurnoverReferersTask.java
Sun Sep 12 16:29:35 2010
@@ -31,9 +31,10 @@ import org.apache.roller.weblogger.busin
  * Reset referer counts.
  */
 public class TurnoverReferersTask extends RollerTaskWithLeasing {
-    
     private static Log log = LogFactory.getLog(TurnoverReferersTask.class);
-    
+
+    public static String NAME = "TurnoverReferersTask";
+
     // 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;
@@ -46,11 +47,7 @@ public class TurnoverReferersTask extend
     
     // lease time given to task lock, default is 30 minutes
     private int leaseTime = 30;
-    
-    
-    public String getName() {
-        return "TurnoverReferersTask";
-    }
+
     
     public String getClientId() {
         return clientId;
@@ -72,8 +69,12 @@ public class TurnoverReferersTask extend
         return this.leaseTime;
     }
     
-    
     public void init() throws WebloggerException {
+        this.init(TurnoverReferersTask.NAME);
+    }
+
+    public void init(String name) throws WebloggerException {
+        super.init(name);
         
         // get relevant props
         Properties props = this.getTaskProperties();

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/RefreshRollerPlanetTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/RefreshRollerPlanetTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/RefreshRollerPlanetTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/RefreshRollerPlanetTask.java
Sun Sep 12 16:29:35 2010
@@ -41,10 +41,11 @@ import org.apache.roller.weblogger.confi
  * - Calls Planet business layer to refresh entries
  * </pre>
  */
-public class RefreshRollerPlanetTask extends RollerTaskWithLeasing {
-    
+public class RefreshRollerPlanetTask extends RollerTaskWithLeasing {    
     private static Log log = LogFactory.getLog(RefreshRollerPlanetTask.class);
     
+    public static String NAME = "RefreshRollerPlanetTask";
+    
     // a unique id for this specific task instance
     // this is meant to be unique for each client in a clustered environment
     private String clientId = "unspecifiedClientId";
@@ -57,11 +58,7 @@ public class RefreshRollerPlanetTask ext
     
     // lease time given to task, default is 10 minutes
     private int leaseTime = 10;
-    
-    
-    public String getName() {
-        return "RefreshRollerPlanetTask";
-    }
+
     
     public String getClientId() {
         return clientId;
@@ -83,10 +80,14 @@ public class RefreshRollerPlanetTask ext
         return this.leaseTime;
     }
     
-    
-    @Override
     public void init() throws WebloggerException {
-        
+        this.init(RefreshRollerPlanetTask.NAME);
+    }
+
+    @Override
+    public void init(String name) throws WebloggerException {
+        super.init(name);
+
         // get relevant props
         Properties props = this.getTaskProperties();
         

Modified: roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/SyncWebsitesTask.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/SyncWebsitesTask.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/SyncWebsitesTask.java
(original)
+++ roller/trunk/weblogger-business/src/main/java/org/apache/roller/weblogger/planet/tasks/SyncWebsitesTask.java
Sun Sep 12 16:29:35 2010
@@ -36,7 +36,6 @@ import org.apache.roller.planet.pojos.Pl
 import org.apache.roller.planet.pojos.PlanetGroup;
 import org.apache.roller.planet.pojos.Subscription;
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.UserManager;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.business.runnable.RollerTaskWithLeasing;
 import org.apache.roller.weblogger.config.WebloggerConfig;
@@ -49,9 +48,10 @@ import org.apache.roller.weblogger.pojos
  * of deleting subsctiptions for weblogs that no longer exist.
  */
 public class SyncWebsitesTask extends RollerTaskWithLeasing {
-    
     private static Log log = LogFactory.getLog(SyncWebsitesTask.class);
-    
+
+    public static String NAME = "SyncWebsitesTask";
+
     // a unique id for this specific task instance
     // this is meant to be unique for each client in a clustered environment
     private String clientId = "unspecifiedClientId";
@@ -65,11 +65,6 @@ public class SyncWebsitesTask extends Ro
     // lease time given to ping task lock, default is 30 minutes
     private int leaseTime = 30;
     
-    
-    public String getName() {
-        return "SyncWebsitesTask";
-    }
-    
     public String getClientId() {
         return clientId;
     }
@@ -92,7 +87,12 @@ public class SyncWebsitesTask extends Ro
     
     
     public void init() throws WebloggerException {
-        
+        this.init(RefreshRollerPlanetTask.NAME);
+    }
+
+    public void init(String name) throws WebloggerException {
+        super.init(name);
+
         // get relevant props
         Properties props = this.getTaskProperties();
         
@@ -249,7 +249,7 @@ public class SyncWebsitesTask extends Ro
         PlanetFactory.bootstrap(provider);
         
         SyncWebsitesTask task = new SyncWebsitesTask();
-        task.init();
+        task.init(); // use default name
         task.run();
     }
     

Modified: roller/trunk/weblogger-business/src/test/java/org/apache/roller/weblogger/business/TaskLockTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-business/src/test/java/org/apache/roller/weblogger/business/TaskLockTest.java?rev=996336&r1=996335&r2=996336&view=diff
==============================================================================
--- roller/trunk/weblogger-business/src/test/java/org/apache/roller/weblogger/business/TaskLockTest.java
(original)
+++ roller/trunk/weblogger-business/src/test/java/org/apache/roller/weblogger/business/TaskLockTest.java
Sun Sep 12 16:29:35 2010
@@ -64,7 +64,8 @@ public class TaskLockTest extends TestCa
         ThreadManager mgr = WebloggerFactory.getWeblogger().getThreadManager();
         
         // need a test task to play with
-        RollerTask task = new TestTask();
+        TestTask task = new TestTask();
+        task.init();
         
         // try to acquire a lock
         assertTrue("Failed to acquire lease.",mgr.registerLease(task));



Mime
View raw message