1 18 19 package org.apache.roller.util.cache; 20 21 import java.util.Calendar ; 22 import java.util.Date ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.roller.RollerException; 31 import org.apache.roller.business.runnable.Job; 32 import org.apache.roller.model.RollerFactory; 33 import org.apache.roller.model.UserManager; 34 import org.apache.roller.model.WeblogManager; 35 import org.apache.roller.pojos.WeblogEntryData; 36 import org.apache.roller.pojos.WebsiteData; 37 38 39 56 public class FuturePostingsInvalidationJob implements Job { 57 58 private static Log log = LogFactory.getLog(FuturePostingsInvalidationJob.class); 59 60 private Map inputs = null; 62 63 private Set nextExpirations = null; 65 66 int peerTime = 5; 68 69 public void execute() { 70 71 log.debug("starting"); 72 73 try { 74 WeblogManager wMgr = RollerFactory.getRoller().getWeblogManager(); 75 UserManager uMgr = RollerFactory.getRoller().getUserManager(); 76 77 Date now = new Date (); 78 79 if(nextExpirations != null) { 80 String websiteid = null; 81 WebsiteData weblog = null; 82 83 Iterator weblogs = nextExpirations.iterator(); 84 while(weblogs.hasNext()) { 85 websiteid = (String ) weblogs.next(); 86 87 try { 88 weblog = uMgr.getWebsite(websiteid); 90 91 log.debug("expiring"+weblog.getHandle()); 92 93 weblog.setLastModified(now); 96 uMgr.saveWebsite(weblog); 97 98 } catch (RollerException ex) { 99 log.warn("couldn't lookup entry "+websiteid); 100 } 101 } 102 103 RollerFactory.getRoller().flush(); 105 } 106 107 Calendar cal = Calendar.getInstance(); 109 cal.setTime(now); 110 cal.add(Calendar.MINUTE, this.peerTime); 111 Date end = cal.getTime(); 112 113 log.debug("looking up entries between "+now+" and "+end); 114 115 List expiringEntries = wMgr.getWeblogEntries(null, null, now, end, null, 117 null, WeblogEntryData.PUBLISHED, null, 0, -1); 118 119 Set expiringWeblogs = new HashSet (); 121 Iterator it = expiringEntries.iterator(); 122 while(it.hasNext()) { 123 expiringWeblogs.add(((WeblogEntryData) it.next()).getWebsite().getId()); 124 } 125 126 this.nextExpirations = expiringWeblogs; 127 128 } catch(Exception e) { 129 log.error(e); 130 } 131 132 log.debug("finished"); 133 } 134 135 136 public Map output() { 137 return null; 138 } 139 140 141 public void input(Map input) { 142 this.inputs = input; 143 144 Integer pTime = (Integer ) this.inputs.get("peerTime"); 146 if(pTime != null) { 147 this.peerTime = pTime.intValue(); 148 } 149 150 log.info("Peeking "+this.peerTime+" minutes into the future each pass"); 151 } 152 153 } 154 | Popular Tags |