You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2007/01/12 18:49:38 UTC
svn commit: r495659 - in /incubator/roller/trunk:
src/org/apache/roller/business/pings/
src/org/apache/roller/business/runnable/
src/org/apache/roller/planet/tasks/ tests/org/apache/roller/business/
Author: agilliland
Date: Fri Jan 12 09:49:36 2007
New Revision: 495659
URL: http://svn.apache.org/viewvc?view=rev&rev=495659
Log:
Make RollerTask truly abstract and not require all tasks to go through the leasing process. Tasks which are meant to be synchronized amongst the cluster should extend RollerTaskWithLeasing.
Added:
incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTaskWithLeasing.java
Modified:
incubator/roller/trunk/src/org/apache/roller/business/pings/PingQueueTask.java
incubator/roller/trunk/src/org/apache/roller/business/runnable/ResetHitCountsTask.java
incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTask.java
incubator/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
incubator/roller/trunk/src/org/apache/roller/business/runnable/TurnoverReferersTask.java
incubator/roller/trunk/src/org/apache/roller/planet/tasks/RefreshEntriesTask.java
incubator/roller/trunk/src/org/apache/roller/planet/tasks/SyncWebsitesTask.java
incubator/roller/trunk/tests/org/apache/roller/business/TaskLockTest.java
Modified: incubator/roller/trunk/src/org/apache/roller/business/pings/PingQueueTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/pings/PingQueueTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/pings/PingQueueTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/pings/PingQueueTask.java Fri Jan 12 09:49:36 2007
@@ -24,7 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.business.runnable.RollerTask;
+import org.apache.roller.business.runnable.RollerTaskWithLeasing;
import org.apache.roller.config.PingConfig;
import org.apache.roller.business.Roller;
import org.apache.roller.business.RollerFactory;
@@ -37,7 +37,7 @@
*
* @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
*/
-public class PingQueueTask extends RollerTask {
+public class PingQueueTask extends RollerTaskWithLeasing {
private static Log log = LogFactory.getLog(PingQueueTask.class);
Modified: incubator/roller/trunk/src/org/apache/roller/business/runnable/ResetHitCountsTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/ResetHitCountsTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/ResetHitCountsTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/ResetHitCountsTask.java Fri Jan 12 09:49:36 2007
@@ -30,7 +30,7 @@
/**
* Reset weblog hit counts.
*/
-public class ResetHitCountsTask extends RollerTask {
+public class ResetHitCountsTask extends RollerTaskWithLeasing {
private static Log log = LogFactory.getLog(ResetHitCountsTask.class);
Modified: incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTask.java Fri Jan 12 09:49:36 2007
@@ -26,17 +26,14 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.config.RollerConfig;
-import org.apache.roller.business.RollerFactory;
-import org.apache.roller.business.runnable.ThreadManager;
import org.apache.roller.util.DateUtil;
/**
* An abstract class representing a scheduled task in Roller.
*
- * This class extends the java.util.TimerTask class and builds in some Roller
- * specifics, such as handling of locks for synchronization in clustered
- * environments.
+ * This class extends the java.util.TimerTask class and adds in some Roller
+ * specifics.
*/
public abstract class RollerTask extends TimerTask {
@@ -102,65 +99,6 @@
* @return The time this task should lease its lock for, in minutes.
*/
public abstract int getLeaseTime();
-
-
- /**
- * Run the task.
- */
- public abstract void runTask() throws RollerException;
-
-
- /**
- * The run() method as called by our thread manager.
- *
- * This method is purposely defined as "final" so that any tasks that are
- * defined may not override it and remove any of its functionality. It is
- * setup to provide some basic functionality to the running of all tasks,
- * such as lock acquisition and releasing.
- *
- * Roller tasks should put their logic in the runTask() method.
- */
- public final void run() {
-
- ThreadManager mgr = RollerFactory.getRoller().getThreadManager();
-
- boolean lockAcquired = false;
- try {
- log.debug("Attempting to acquire lock");
-
- lockAcquired = mgr.acquireLock(this);
-
- // now if we have a lock then run the task
- if(lockAcquired) {
- log.debug("Lock acquired, running task");
- this.runTask();
- } else {
- log.debug("Lock NOT acquired, cannot continue");
- return;
- }
-
- } catch (Exception ex) {
- log.error("Unexpected exception running task", ex);
- } finally {
-
- if(lockAcquired) {
-
- log.debug("Attempting to release lock");
-
- boolean lockReleased = mgr.releaseLock(this);
-
- if(lockReleased) {
- log.debug("Lock released, time to sleep");
- } else {
- log.debug("Lock NOT released, some kind of problem");
- }
- }
-
- // always release Roller session
- RollerFactory.getRoller().release();
- }
-
- }
/**
Added: incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTaskWithLeasing.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTaskWithLeasing.java?view=auto&rev=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTaskWithLeasing.java (added)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/RollerTaskWithLeasing.java Fri Jan 12 09:49:36 2007
@@ -0,0 +1,94 @@
+/*
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.business.RollerFactory;
+
+
+/**
+ * An abstract class representing a scheduled task in Roller that will always
+ * attempt to acquire a lease before doing its work.
+ */
+public abstract class RollerTaskWithLeasing extends RollerTask {
+
+ private static Log log = LogFactory.getLog(RollerTaskWithLeasing.class);
+
+
+ /**
+ * Run the task.
+ */
+ public abstract void runTask() throws RollerException;
+
+
+ /**
+ * The run() method as called by our thread manager.
+ *
+ * This method is purposely defined as "final" so that any tasks that are
+ * defined may not override it and remove any of its functionality. It is
+ * setup to provide some basic functionality to the running of all tasks,
+ * such as lease acquisition and releasing.
+ *
+ * Roller tasks should put their logic in the runTask() method.
+ */
+ public final void run() {
+
+ ThreadManager mgr = RollerFactory.getRoller().getThreadManager();
+
+ boolean lockAcquired = false;
+ try {
+ log.debug("Attempting to acquire lock");
+
+ lockAcquired = mgr.acquireLock(this);
+
+ // now if we have a lock then run the task
+ if(lockAcquired) {
+ log.debug("Lock acquired, running task");
+ this.runTask();
+ } else {
+ log.debug("Lock NOT acquired, cannot continue");
+ return;
+ }
+
+ } catch (Exception ex) {
+ log.error("Unexpected exception running task", ex);
+ } finally {
+
+ if(lockAcquired) {
+
+ log.debug("Attempting to release lock");
+
+ boolean lockReleased = mgr.releaseLock(this);
+
+ if(lockReleased) {
+ log.debug("Lock released, time to sleep");
+ } else {
+ log.debug("Lock NOT released, some kind of problem");
+ }
+ }
+
+ // always release Roller session
+ RollerFactory.getRoller().release();
+ }
+
+ }
+
+}
Modified: incubator/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/ThreadManagerImpl.java Fri Jan 12 09:49:36 2007
@@ -115,8 +115,4 @@
return true;
}
- public boolean isLocked(RollerTask task) {
- return false;
- }
-
}
Modified: incubator/roller/trunk/src/org/apache/roller/business/runnable/TurnoverReferersTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/runnable/TurnoverReferersTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/business/runnable/TurnoverReferersTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/business/runnable/TurnoverReferersTask.java Fri Jan 12 09:49:36 2007
@@ -30,7 +30,7 @@
/**
* Reset referer counts.
*/
-public class TurnoverReferersTask extends RollerTask {
+public class TurnoverReferersTask extends RollerTaskWithLeasing {
private static Log log = LogFactory.getLog(TurnoverReferersTask.class);
Modified: incubator/roller/trunk/src/org/apache/roller/planet/tasks/RefreshEntriesTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/planet/tasks/RefreshEntriesTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/planet/tasks/RefreshEntriesTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/planet/tasks/RefreshEntriesTask.java Fri Jan 12 09:49:36 2007
@@ -23,7 +23,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.business.runnable.RollerTask;
+import org.apache.roller.business.runnable.RollerTaskWithLeasing;
import org.apache.roller.planet.business.PlanetFactory;
import org.apache.roller.planet.config.PlanetConfig;
@@ -31,7 +31,7 @@
/**
* Run the Planet Roller refresh-entries method to fetch and parse newsfeeds.
*/
-public class RefreshEntriesTask extends RollerTask {
+public class RefreshEntriesTask extends RollerTaskWithLeasing {
private static Log log = LogFactory.getLog(RefreshEntriesTask.class);
Modified: incubator/roller/trunk/src/org/apache/roller/planet/tasks/SyncWebsitesTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/planet/tasks/SyncWebsitesTask.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/planet/tasks/SyncWebsitesTask.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/planet/tasks/SyncWebsitesTask.java Fri Jan 12 09:49:36 2007
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
-import org.apache.roller.business.runnable.RollerTask;
+import org.apache.roller.business.runnable.RollerTaskWithLeasing;
import org.apache.roller.config.RollerRuntimeConfig;
import org.apache.roller.planet.business.Planet;
import org.apache.roller.planet.business.PlanetFactory;
@@ -43,7 +43,7 @@
/**
* Ensure that every weblog has a subscription in Planet Roller database.
*/
-public class SyncWebsitesTask extends RollerTask {
+public class SyncWebsitesTask extends RollerTaskWithLeasing {
private static Log log = LogFactory.getLog(SyncWebsitesTask.class);
Modified: incubator/roller/trunk/tests/org/apache/roller/business/TaskLockTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/tests/org/apache/roller/business/TaskLockTest.java?view=diff&rev=495659&r1=495658&r2=495659
==============================================================================
--- incubator/roller/trunk/tests/org/apache/roller/business/TaskLockTest.java (original)
+++ incubator/roller/trunk/tests/org/apache/roller/business/TaskLockTest.java Fri Jan 12 09:49:36 2007
@@ -26,7 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.TestUtils;
import org.apache.roller.business.runnable.RollerTask;
-import org.apache.roller.business.RollerFactory;
+import org.apache.roller.business.runnable.RollerTaskWithLeasing;
import org.apache.roller.business.runnable.ThreadManager;
@@ -79,7 +79,7 @@
}
- class TestTask extends RollerTask {
+ class TestTask extends RollerTaskWithLeasing {
public String getName() { return "TestTask"; }
public String getClientId() { return "TestTaskClientId"; }