1 package org.oddjob.schedules.schedules; 2 3 import java.io.Serializable ; 4 import java.util.Date ; 5 6 import org.apache.log4j.Logger; 7 import org.oddjob.schedules.AbstractSchedule; 8 import org.oddjob.schedules.DateUtils; 9 import org.oddjob.schedules.Interval; 10 import org.oddjob.schedules.Schedule; 11 import org.oddjob.schedules.ScheduleContext; 12 13 32 33 final public class LastSchedule extends AbstractSchedule implements Serializable { 34 35 private static final long serialVersionUID = 20050226; 36 37 private static final Logger logger = Logger.getLogger(LastSchedule.class); 38 39 42 public Interval nextDue(ScheduleContext context) { 43 Date now = context.getDate(); 44 if (now == null) { 45 return null; 46 } 47 if (getChildSchedule() == null) { 48 throw new IllegalStateException ("Last must have a child schedule."); 49 } 50 51 logger.debug(this + ": in date is " + now); 52 53 Interval last = null; 54 Date use = now; 55 56 Schedule child = getChildSchedule(); 57 child.setLimits(getLimits()); 58 while(true) { 59 logger.debug(this + ": use date is " + use); 60 Interval candidate = child.nextDue(context.spawn(use)); 61 if (candidate == null) { 62 break; 63 } 64 last = candidate; 65 use = DateUtils.oneMillisAfter(candidate.getToDate()); 66 } 67 68 return last; 69 } 70 71 74 75 public String toString() { 76 return "Last Schedule"; 77 } 78 79 } 80 | Popular Tags |