You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ga...@apache.org on 2006/07/22 20:33:14 UTC
svn commit: r424615 [2/2] - in
/incubator/roller/branches/roller_3.0/src/org/apache/roller: config/ pojos/
ui/admin/struts/actions/ ui/authoring/struts/actions/ ui/core/pings/ util/
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueProcessor.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueProcessor.java?rev=424615&r1=424614&r2=424615&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueProcessor.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueProcessor.java Sat Jul 22 11:33:13 2006
@@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.config.PingConfig;
+import org.apache.roller.config.RollerRuntimeConfig;
import org.apache.roller.model.PingQueueManager;
import org.apache.roller.model.RollerFactory;
import org.apache.roller.pojos.PingQueueEntryData;
@@ -32,15 +33,13 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.roller.config.RollerRuntimeConfig;
/**
* Ping Queue Processor. Singleton encapsulating logic for processing the weblog update ping queue.
*
* @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
*/
-public class PingQueueProcessor
-{
+public class PingQueueProcessor {
private static final Log logger = LogFactory.getLog(PingQueueProcessor.class);
private static PingQueueProcessor theInstance;
@@ -49,13 +48,11 @@
private RollerContext rollerContext;
private PingQueueManager pingQueueMgr;
- public static PingQueueProcessor getInstance()
- {
+ public static PingQueueProcessor getInstance() {
return theInstance;
}
- private PingQueueProcessor(RollerContext rc) throws RollerException
- {
+ private PingQueueProcessor(RollerContext rc) throws RollerException {
rollerContext = rc;
pingQueueMgr = RollerFactory.getRoller().getPingQueueManager();
}
@@ -66,10 +63,8 @@
* @param rc the Roller context
* @throws RollerException
*/
- public static synchronized void init(RollerContext rc) throws RollerException
- {
- if (theInstance != null)
- {
+ public static synchronized void init(RollerContext rc) throws RollerException {
+ if (theInstance != null) {
logger.warn("Ignoring duplicate initialization of PingQueueProcessor!");
return;
}
@@ -82,16 +77,14 @@
* an entry is requeued for processing on subsequent passes until the configured maximum number of attempts is
* reached.
*/
- public synchronized void processQueue()
- {
+ public synchronized void processQueue() {
if (PingConfig.getSuspendPingProcessing()) {
logger.info("Ping processing has been suspended. Skipping current round of ping queue processing.");
return;
}
String absoluteContextUrl = RollerRuntimeConfig.getAbsoluteContextURL();
- if (absoluteContextUrl == null)
- {
+ if (absoluteContextUrl == null) {
logger.warn("WARNING: Skipping current ping queue processing round because we cannot yet determine the site's absolute context url.");
return;
}
@@ -101,22 +94,18 @@
// all of the pings for that target at once. If it becomes an efficiency issue, we should do
// that.
- try
- {
+ 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();)
- {
+ for (Iterator i = entries.iterator(); i.hasNext();) {
PingQueueEntryData pingQueueEntry = (PingQueueEntryData) i.next();
processQueueEntry(absoluteContextUrl, pingQueueEntry);
}
if (logger.isDebugEnabled()) logger.debug("Finished processing ping queue.");
- }
- catch (Exception ex)
- {
+ } catch (Exception ex) {
logger.error("Unexpected exception processing ping queue! Aborting this pass of ping queue processing.", ex);
}
}
@@ -129,40 +118,31 @@
* @throws RollerException only if there are problems processing the queue. Exceptions from sending pings are
* handled, not thrown.
*/
- private void processQueueEntry(String absoluteContextUrl, PingQueueEntryData pingQueueEntry)
- throws RollerException
- {
+ private void processQueueEntry(String absoluteContextUrl, 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;
- if (PingConfig.getLogPingsOnly())
- {
+ if (PingConfig.getLogPingsOnly()) {
// Just log the ping and pretend it succeeded.
logger.info("Logging simulated ping for ping queue entry " + pingQueueEntry);
pingSucceeded = true;
- }
- else
- {
+ } else {
// Actually process the ping
- try
- {
+ try {
// Send the ping
WeblogUpdatePinger.sendPing(absoluteContextUrl, pingTarget, website);
// Consider successful ping transmission if we didn't get an exception. We don't care here
// about the result of the ping if it was transmitted.
pingSucceeded = true;
- }
- catch (Exception ex)
- {
+ } catch (Exception ex) {
// Handle the ping error, either removing or requeuing the ping queue entry.
handlePingError(pingQueueEntry, ex);
}
}
// We do this outside of the previous try-catch because we don't want an exception here to be considered a ping error.
- if (pingSucceeded)
- {
+ if (pingSucceeded) {
if (logger.isDebugEnabled()) logger.debug("Processed ping: " + pingQueueEntry);
pingQueueMgr.removeQueueEntry(pingQueueEntry);
}
@@ -175,24 +155,17 @@
* @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.");
+ 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);
pingQueueMgr.saveQueueEntry(pingQueueEntry);
- }
- else
- {
+ } else {
// Remove the entry
- logger.warn("Error on ping attempt (" + pingQueueEntry.getAttempts() + ") for " + pingQueueEntry +
- ": [" + ex.getMessage() + "]. Entry will be REMOVED from ping queue.");
+ 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);
pingQueueMgr.removeQueueEntry(pingQueueEntry);
// TODO: mark ping target invalid?
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueTask.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueTask.java?rev=424615&r1=424614&r2=424615&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueTask.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/PingQueueTask.java Sat Jul 22 11:33:13 2006
@@ -34,8 +34,7 @@
*
* @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
*/
-public class PingQueueTask extends TimerTask
-{
+public class PingQueueTask extends TimerTask {
private static final Log logger = LogFactory.getLog(PingQueueTask.class);
// The periodic interval (in minutes) at which we are configured to run
@@ -47,8 +46,7 @@
* @param rc the Roller context.
* @throws RollerException
*/
- public void init(RollerContext rc, long intervalMins) throws RollerException
- {
+ public void init(RollerContext rc, long intervalMins) throws RollerException {
PingQueueProcessor.init(rc);
this.intervalMins = intervalMins;
}
@@ -58,31 +56,24 @@
*
* @return the tasks configured interval (in minutes).
*/
- public long getIntervalMins()
- {
+ public long getIntervalMins() {
return intervalMins;
}
/**
* Run the task once.
*/
- public void run()
- {
+ public void run() {
// Call the ping queue processor to process the queue
Roller roller = null;
- try
- {
+ try {
roller = RollerFactory.getRoller();
PingQueueProcessor.getInstance().processQueue();
roller.flush();
- }
- catch (RollerException e)
- {
+ } catch (RollerException e) {
// This is probably duplicate logging. May want to eliminate it, but should be rare.
logger.error("Error while processing ping queuer", e);
- }
- finally
- {
+ } finally {
if (roller != null) roller.release();
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/WeblogUpdatePinger.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/WeblogUpdatePinger.java?rev=424615&r1=424614&r2=424615&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/WeblogUpdatePinger.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/pings/WeblogUpdatePinger.java Sat Jul 22 11:33:13 2006
@@ -20,12 +20,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.xmlrpc.XmlRpcClient;
-import org.apache.xmlrpc.XmlRpcException;
import org.apache.roller.RollerException;
-import org.apache.roller.model.RollerFactory;
import org.apache.roller.pojos.PingTargetData;
import org.apache.roller.pojos.WebsiteData;
+import org.apache.xmlrpc.XmlRpcClient;
+import org.apache.xmlrpc.XmlRpcException;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -39,56 +38,44 @@
* @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
* @author llavandowska (for code refactored from the now-defunct <code>RollerXmlRpcClient</code>)
*/
-public class WeblogUpdatePinger
-{
+public class WeblogUpdatePinger {
public static final Log logger = LogFactory.getLog(WeblogUpdatePinger.class);
/**
* Conveys a ping result.
*/
- public static class PingResult
- {
+ public static class PingResult {
boolean error;
String message;
- public PingResult(Boolean error, String message)
- {
+ public PingResult(Boolean error, String message) {
this.error = error != null ? error.booleanValue() : false;
this.message = message;
}
- public boolean isError()
- {
+ public boolean isError() {
return error;
}
- public void setError(boolean error)
- {
+ public void setError(boolean error) {
this.error = error;
}
- public String getMessage()
- {
+ public String getMessage() {
return message;
}
- public void setMessage(String message)
- {
+ public void setMessage(String message) {
this.message = message;
}
- public String toString()
- {
- return "PingResult{" +
- "error=" + error +
- ", message='" + message + "'" +
- "}";
+ public String toString() {
+ return "PingResult{" + "error=" + error + ", message='" + message + "'" + "}";
}
}
// Inhibit construction
- private WeblogUpdatePinger()
- {
+ private WeblogUpdatePinger() {
}
/**
@@ -102,9 +89,7 @@
* @throws XmlRpcException
* @throws RollerException
*/
- public static PingResult sendPing(String absoluteContextUrl, PingTargetData pingTarget, WebsiteData website)
- throws RollerException, IOException, XmlRpcException
- {
+ public static PingResult sendPing(String absoluteContextUrl, PingTargetData pingTarget, WebsiteData website) throws RollerException, IOException, XmlRpcException {
// Figure out the url of the user's website.
String websiteUrl = website.getAbsoluteURL();
@@ -112,10 +97,8 @@
Vector params = new Vector();
params.addElement(website.getName());
params.addElement(websiteUrl);
- if (logger.isDebugEnabled())
- {
- logger.debug("Executing ping to '" + pingTarget.getPingUrl() + "' for website '" +
- websiteUrl + "' (" + website.getName() + ")");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Executing ping to '" + pingTarget.getPingUrl() + "' for website '" + websiteUrl + "' (" + website.getName() + ")");
}
// Send the ping
@@ -132,18 +115,14 @@
* @param ex an exception thrown by the <coce>sendPing</code> operation
* @return true if the error warrants retrial
*/
- public static boolean shouldRetry(Exception ex)
- {
+ public static boolean shouldRetry(Exception ex) {
// Determine if error appears transient (warranting retrial)
// We give most errors the "benefit of the doubt" by considering them transient
// This picks out a few that we consider non-transient
- if (ex instanceof UnknownHostException)
- {
+ if (ex instanceof UnknownHostException) {
// User probably mistyped the url in the custom target.
return false;
- }
- else if (ex instanceof MalformedURLException)
- {
+ } else if (ex instanceof MalformedURLException) {
// This should never happen due to validations but if we get here, retrial won't fix it.
return false;
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/PropertyExpander.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/PropertyExpander.java?rev=424615&r1=424614&r2=424615&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/PropertyExpander.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/PropertyExpander.java Sat Jul 22 11:33:13 2006
@@ -29,15 +29,12 @@
* ROL-613)
* @since Roller 1.3
*/
-public class PropertyExpander
-{
- private PropertyExpander()
- {
+public class PropertyExpander {
+ private PropertyExpander() {
}
// The pattern for a system property. Matches ${property.name}, with the interior matched reluctantly.
- private static final Pattern EXPANSION_PATTERN =
- Pattern.compile("(\\$\\{([^}]+?)\\})", java.util.regex.Pattern.MULTILINE);
+ private static final Pattern EXPANSION_PATTERN = Pattern.compile("(\\$\\{([^}]+?)\\})", java.util.regex.Pattern.MULTILINE);
/**
* Expand property expressions in the input. Expands property expressions of the form <code>${propertyname}</code>
@@ -55,15 +52,13 @@
* @return the result of replacing property expressions with the values of the corresponding properties from the
* supplied property map, null if the input string is null.
*/
- public static String expandProperties(String input, Map props)
- {
+ public static String expandProperties(String input, Map props) {
if (input == null) return null;
Matcher matcher = EXPANSION_PATTERN.matcher(input);
StringBuffer expanded = new StringBuffer(input.length());
- while (matcher.find())
- {
+ while (matcher.find()) {
String propName = matcher.group(2);
String value = (String) props.get(propName);
// if no value is found, use a value equal to the original expression
@@ -85,8 +80,7 @@
* @return the result of replacing property expressions with the values of the corresponding system properties.
* @see System#getProperties()
*/
- public static String expandSystemProperties(String input)
- {
+ public static String expandSystemProperties(String input) {
return expandProperties(input, System.getProperties());
}
}