roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r520042 - in /incubator/roller/trunk/apps/planet/src/java/org/apache/roller: planet/tasks/ planet/ui/core/ util/
Date Mon, 19 Mar 2007 18:43:58 GMT
Author: agilliland
Date: Mon Mar 19 11:43:57 2007
New Revision: 520042

URL: http://svn.apache.org/viewvc?view=rev&rev=520042
Log:
fixing up initialization process for standalone tasks.


Added:
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/PlanetTask.java
Modified:
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/GeneratePlanetTask.java
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/RefreshPlanetTask.java
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/TechnoratiRankingsTask.java
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/core/PlanetContext.java
    incubator/roller/trunk/apps/planet/src/java/org/apache/roller/util/TaskRunner.java

Modified: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/GeneratePlanetTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/GeneratePlanetTask.java?view=diff&rev=520042&r1=520041&r2=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/GeneratePlanetTask.java
(original)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/GeneratePlanetTask.java
Mon Mar 19 11:43:57 2007
@@ -44,9 +44,11 @@
  * - Uses Velocity Texen to generate the static files
  * </pre>
  */
-public class GeneratePlanetTask implements Runnable {
+public class GeneratePlanetTask extends PlanetTask {
+    
     private static Log log = LogFactory.getLog(GeneratePlanetTask.class);
     
+    
     public void run() {
         try {            
             Planet planet = PlanetFactory.getPlanet();
@@ -113,5 +115,12 @@
         } catch (Exception e) {
             log.error("ERROR generating planet", e);
         }
-    }   
+    }
+    
+    public static void main(String[] args) throws Exception{
+        GeneratePlanetTask task = new GeneratePlanetTask();
+        task.initialize();
+        task.run();
+    }
+    
 }

Added: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/PlanetTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/PlanetTask.java?view=auto&rev=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/PlanetTask.java
(added)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/PlanetTask.java
Mon Mar 19 11:43:57 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.planet.tasks;
+
+import org.apache.roller.planet.business.FeedFetcher;
+import org.apache.roller.planet.business.PlanetFactory;
+import org.apache.roller.planet.business.URLStrategy;
+import org.apache.roller.planet.config.PlanetConfig;
+
+
+/**
+ * An abstract class representing a scheduled task in Roller Planet.
+ */
+public abstract class PlanetTask implements Runnable {
+    
+    /**
+     * Initialize the task basically the same way the webapp would initialize.
+     */
+    public void initialize() throws Exception {
+        setupURLStrategy();
+        setupFeedFetcher();
+    }
+    
+    
+    /**
+     * Lookup configured URLStrategy from config and plug it in.
+     *
+     * If no URLStrategy can be configured then we bail and spew errors.
+     */
+    protected void setupURLStrategy() throws Exception {
+        
+        String urlStratClass = PlanetConfig.getProperty("urlstrategy.classname");
+        if(urlStratClass == null || urlStratClass.trim().length() < 1) {
+            throw new Exception("No URLStrategy configured!!!");
+        }
+        
+        Class stratClass = Class.forName(urlStratClass);
+        URLStrategy urlStrategy = (URLStrategy) stratClass.newInstance();
+        
+        // plug it in
+        PlanetFactory.getPlanet().setURLStrategy(urlStrategy);
+    }
+    
+    
+    /**
+     * Lookup configured FeedFetcher from config and plug it in.
+     *
+     * If no FeedFetcher can be configured then we bail and spew errors.
+     */
+    protected void setupFeedFetcher() throws Exception {
+        
+        String feedFetchClass = PlanetConfig.getProperty("feedfetcher.classname");
+        if(feedFetchClass == null || feedFetchClass.trim().length() < 1) {
+            throw new Exception("No FeedFetcher configured!!!");
+        }
+        
+        Class fetchClass = Class.forName(feedFetchClass);
+        FeedFetcher feedFetcher = (FeedFetcher) fetchClass.newInstance();
+        
+        // plug it in
+        PlanetFactory.getPlanet().setFeedFetcher(feedFetcher);
+    }
+    
+}

Modified: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/RefreshPlanetTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/RefreshPlanetTask.java?view=diff&rev=520042&r1=520041&r2=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/RefreshPlanetTask.java
(original)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/RefreshPlanetTask.java
Mon Mar 19 11:43:57 2007
@@ -33,9 +33,11 @@
  * - Calls Planet business layer to refresh entries
  * </pre>
  */
-public class RefreshPlanetTask implements Runnable {
+public class RefreshPlanetTask extends PlanetTask {
+    
     private static Log log = LogFactory.getLog(RefreshPlanetTask.class);
     
+    
     public void run() {
         try {            
             // Update all feeds in planet
@@ -52,8 +54,10 @@
     }
     
     
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception{
         RefreshPlanetTask task = new RefreshPlanetTask();
+        task.initialize();
         task.run();
     }
+    
 }

Modified: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/TechnoratiRankingsTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/TechnoratiRankingsTask.java?view=diff&rev=520042&r1=520041&r2=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/TechnoratiRankingsTask.java
(original)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/tasks/TechnoratiRankingsTask.java
Mon Mar 19 11:43:57 2007
@@ -35,7 +35,7 @@
 /**
  * Rank each subscription by populating Technorati inbound blog and link counts.
  */
-public class TechnoratiRankingsTask implements Runnable {
+public class TechnoratiRankingsTask extends PlanetTask {
     
     private static Log log = LogFactory.getLog(TechnoratiRankingsTask.class);
     
@@ -131,6 +131,13 @@
         } catch (Exception e) {
             log.error("ERROR ranking subscriptions", e);
         }
+    }
+    
+    
+    public static void main(String[] args) throws Exception{
+        TechnoratiRankingsTask task = new TechnoratiRankingsTask();
+        task.initialize();
+        task.run();
     }
     
 }

Modified: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/core/PlanetContext.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/core/PlanetContext.java?view=diff&rev=520042&r1=520041&r2=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/core/PlanetContext.java
(original)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/planet/ui/core/PlanetContext.java
Mon Mar 19 11:43:57 2007
@@ -65,7 +65,7 @@
      */
     public void contextInitialized(ServletContextEvent sce) {
         
-        log.debug("Roller Planet Initializing ... ");
+        log.info("Roller Planet Initializing ... ");
         
         // keep a reverence to ServletContext object
         this.context = sce.getServletContext();
@@ -94,7 +94,7 @@
             throw new RuntimeException(t);
         }
         
-        log.debug("Roller Planet Initialization Complete");
+        log.info("Roller Planet Initialization Complete");
     }
     
     

Modified: incubator/roller/trunk/apps/planet/src/java/org/apache/roller/util/TaskRunner.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/apps/planet/src/java/org/apache/roller/util/TaskRunner.java?view=diff&rev=520042&r1=520041&r2=520042
==============================================================================
--- incubator/roller/trunk/apps/planet/src/java/org/apache/roller/util/TaskRunner.java (original)
+++ incubator/roller/trunk/apps/planet/src/java/org/apache/roller/util/TaskRunner.java Mon
Mar 19 11:43:57 2007
@@ -18,7 +18,7 @@
 package org.apache.roller.util;
         
 import java.io.File;
-import org.apache.roller.util.StandaloneWebappClassLoader;
+import org.apache.roller.planet.tasks.PlanetTask;
 
 /**
  * Sets up classpath for Roller and runs a task. 
@@ -61,7 +61,8 @@
 
         // Go!
         Class taskClass = cl.loadClass(taskClassName);
-        Runnable task = (Runnable)taskClass.newInstance();
+        PlanetTask task = (PlanetTask) taskClass.newInstance();
+        task.initialize();
         task.run();
     }
 }



Mime
View raw message