1 25 26 28 package de.nava.informa.utils; 29 30 import java.util.Date ; 31 import java.util.Timer ; 32 import java.util.TimerTask ; 33 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 43 public class FeedRefreshDaemon { 44 45 private static Log logger = LogFactory.getLog(FeedRefreshDaemon.class); 46 47 private Timer refreshTimer = null; 48 49 public FeedRefreshDaemon() { 50 logger.info("FeedRefresh Daemon instancied"); 51 this.refreshTimer = new Timer (true); 52 } 53 54 public void addFeed(FeedManagerEntry feed) { 55 FeedRefreshTask refreshTask = new FeedRefreshTask(); 56 refreshTask.setFeedME(feed); 57 logger.info("scheduling new feed "); 59 Date fiveMinuteLater = new Date (new Date ().getTime() + (5 * 60 * 1000)); 60 61 this.refreshTimer.schedule(refreshTask, fiveMinuteLater, (5 * 60 * 1000)); 62 } 63 64 private class FeedRefreshTask extends TimerTask { 65 66 FeedManagerEntry f = null; 67 68 int nbError = 0; 69 70 public void setFeedME(FeedManagerEntry feedME) { 71 f = feedME; 72 } 73 74 public void run() { 75 try { 76 f.getFeed(); logger.debug("feed refreshed" + f.getFeed().getLocation()); 78 } catch (Exception e) { 79 this.nbError++; 80 logger.warn("Error retrieving feed" + f.toString() + " " + e); 81 } 82 83 } 84 } 85 86 } | Popular Tags |