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/07/18 19:48:33 UTC
svn commit: r557339 - in /roller/trunk/apps/planet:
src/java/org/apache/roller/planet/business/fetcher/
src/java/org/apache/roller/planet/business/updater/
test/java/org/apache/roller/planet/business/
Author: agilliland
Date: Wed Jul 18 10:48:32 2007
New Revision: 557339
URL: http://svn.apache.org/viewvc?view=rev&rev=557339
Log:
minor change to FeedFetcher to support conditional feed fetching based on lastModified time of the subscription. this is meant to help performance a little bit so that we don't waste time processing subscriptions that haven't changed since they were last fetched.
Modified:
roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/FeedFetcher.java
roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/RomeFeedFetcher.java
roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/updater/SingleThreadedFeedUpdater.java
roller/trunk/apps/planet/test/java/org/apache/roller/planet/business/RomeFeedFetcherTest.java
Modified: roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/FeedFetcher.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/FeedFetcher.java?view=diff&rev=557339&r1=557338&r2=557339
==============================================================================
--- roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/FeedFetcher.java (original)
+++ roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/FeedFetcher.java Wed Jul 18 10:48:32 2007
@@ -18,6 +18,7 @@
package org.apache.roller.planet.business.fetcher;
+import java.util.Date;
import org.apache.roller.planet.pojos.Subscription;
@@ -47,4 +48,25 @@
*/
public Subscription fetchSubscription(String feedURL) throws FetcherException;
+
+ /**
+ * Conditionally fetch a single subscription.
+ *
+ * This method takes in a feed url and its known last modified date and should
+ * return a transient Subscription for the feed only if the given feed has
+ * been updated since the lastModified date. This method is meant provide
+ * a more efficient way to fetch subscriptions which are being updated so
+ * subscriptions are not continually fetched when unnecessary.
+ *
+ * It is important to understand that this method will *NOT* return a
+ * persistent version of an existing Subscription if it happens to
+ * exist. This method is only here to pull feeds from their source
+ * so that they may be used in any way desired by the rest of the system.
+ *
+ * @param feedURL The feed url to use when fetching the subscription.
+ * @return Subscription The fetched subscription.
+ * @throws FetcherException If there is an error fetching the subscription.
+ */
+ public Subscription fetchSubscription(String feedURL, Date lastModified) throws FetcherException;
+
}
Modified: roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/RomeFeedFetcher.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/RomeFeedFetcher.java?view=diff&rev=557339&r1=557338&r2=557339
==============================================================================
--- roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/RomeFeedFetcher.java (original)
+++ roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/fetcher/RomeFeedFetcher.java Wed Jul 18 10:48:32 2007
@@ -63,6 +63,15 @@
*/
public Subscription fetchSubscription(String feedURL)
throws FetcherException {
+ return fetchSubscription(feedURL, null);
+ }
+
+
+ /**
+ * @inheritDoc
+ */
+ public Subscription fetchSubscription(String feedURL, Date lastModified)
+ throws FetcherException {
if(feedURL == null) {
throw new IllegalArgumentException("feed url cannot be null");
@@ -114,6 +123,11 @@
} catch (MalformedURLException ex) {
// should never happen since we check this above
}
+ }
+
+ // check if feed is unchanged and bail now if so
+ if(lastModified != null && !newSub.getLastUpdated().after(lastModified)) {
+ return null;
}
if(log.isDebugEnabled()) {
Modified: roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/updater/SingleThreadedFeedUpdater.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/updater/SingleThreadedFeedUpdater.java?view=diff&rev=557339&r1=557338&r2=557339
==============================================================================
--- roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/updater/SingleThreadedFeedUpdater.java (original)
+++ roller/trunk/apps/planet/src/java/org/apache/roller/planet/business/updater/SingleThreadedFeedUpdater.java Wed Jul 18 10:48:32 2007
@@ -66,9 +66,14 @@
try {
// fetch the latest version of the subscription
FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
- updatedSub = fetcher.fetchSubscription(sub.getFeedURL());
+ updatedSub = fetcher.fetchSubscription(sub.getFeedURL(), sub.getLastUpdated());
} catch (FetcherException ex) {
throw new UpdaterException("Error fetching updated subscription", ex);
+ }
+
+ // if sub was unchanged then we are done
+ if(updatedSub == null) {
+ return;
}
// if this subscription hasn't changed since last update then we're done
Modified: roller/trunk/apps/planet/test/java/org/apache/roller/planet/business/RomeFeedFetcherTest.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/planet/test/java/org/apache/roller/planet/business/RomeFeedFetcherTest.java?view=diff&rev=557339&r1=557338&r2=557339
==============================================================================
--- roller/trunk/apps/planet/test/java/org/apache/roller/planet/business/RomeFeedFetcherTest.java (original)
+++ roller/trunk/apps/planet/test/java/org/apache/roller/planet/business/RomeFeedFetcherTest.java Wed Jul 18 10:48:32 2007
@@ -61,4 +61,23 @@
assertTrue(sub.getEntries().size() > 0);
}
+
+ public void testFetchFeedConditionally() throws Exception {
+
+ FeedFetcher feedFetcher = PlanetFactory.getPlanet().getFeedFetcher();
+
+ // fetch feed
+ Subscription sub = feedFetcher.fetchSubscription(feed_url);
+ assertNotNull(sub);
+ assertEquals(feed_url, sub.getFeedURL());
+ assertEquals("http://rollerweblogger.org/roller/", sub.getSiteURL());
+ assertEquals("Blogging Roller", sub.getTitle());
+ assertNotNull(sub.getLastUpdated());
+ assertTrue(sub.getEntries().size() > 0);
+
+ // now do a conditional fetch and we should get back null
+ Subscription updatedSub = feedFetcher.fetchSubscription(feed_url, sub.getLastUpdated());
+ assertNull(updatedSub);
+ }
+
}