}
public void refreshEntries() throws RollerException {
Roller roller = RollerFactory.getRoller();
Date now = new Date();
long startTime = System.currentTimeMillis();
PlanetConfigData config = getConfiguration();
// can't continue without cache dir
if (config == null || config.getCacheDir() == null) {
log.warn("Planet cache directory not set, aborting refresh");
return;
}
// allow ${user.home} in cache dir property
String cacheDirName = config.getCacheDir().replaceFirst(
"\\$\\{user.home}",System.getProperty("user.home"));
// allow ${catalina.home} in cache dir property
cacheDirName = cacheDirName.replaceFirst(
"\\$\\{catalina.home}",System.getProperty("catalina.home"));
// create cache dir if it does not exist
File cacheDir = null;
try {
cacheDir = new File(cacheDirName);
if (!cacheDir.exists()) cacheDir.mkdirs();
} catch (Exception e) {
log.error("Unable to create planet cache directory");
return;
}
// abort if cache dir is not writable
if (!cacheDir.canWrite()) {
log.error("Planet cache directory is not writable");
return;
}
FeedFetcherCache feedInfoCache =
new DiskFeedInfoCache(cacheDirName);
if (config.getProxyHost()!=null && config.getProxyPort() > 0) {
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", config.getProxyHost());
System.setProperty("http.proxyPort",
Integer.toString(config.getProxyPort()));
}
/** a hack to set 15 sec timeouts for java.net.HttpURLConnection */
System.setProperty("sun.net.client.defaultConnectTimeout", "15000");
System.setProperty("sun.net.client.defaultReadTimeout", "15000");
FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
//FeedFetcher feedFetcher = new HttpClientFeedFetcher(feedInfoCache);
feedFetcher.setUsingDeltaEncoding(false);
feedFetcher.setUserAgent("RollerPlanetAggregator");
// Loop through all subscriptions in the system
Iterator subs = getAllSubscriptions();
while (subs.hasNext()) {
long subStartTime = System.currentTimeMillis();
PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
// reattach sub. sub gets detached as we iterate
sub = this.getSubscriptionById(sub.getId());
// Fetch latest entries for each subscription
// Set newEntries = null;
// int count = 0;
// if (!StringUtils.isEmpty(localURL) && sub.getFeedUrl().startsWith(localURL)) {
// newEntries = getNewEntriesLocal(sub, feedFetcher, feedInfoCache);
// } else {
// newEntries = getNewEntriesRemote(sub, feedFetcher, feedInfoCache);
// }
Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
int count = newEntries.size();
log.debug(" Entry count: " + count);
if (count > 0) {
sub.purgeEntries();
sub.addEntries(newEntries);
this.saveSubscription(sub);
if(roller != null) roller.flush();
}
long subEndTime = System.currentTimeMillis();
log.info(" " + count + " - "
+ ((subEndTime-subStartTime)/1000.0)
+ " seconds to process (" + count + ") entries of "