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.DateUtils; 8 import org.oddjob.schedules.Interval; 9 import org.oddjob.schedules.Schedule; 10 import org.oddjob.schedules.ScheduleContext; 11 12 13 14 46 47 public class BrokenSchedule implements Serializable , Schedule { 48 49 private static final long serialVersionUID = 20050226; 50 51 private static final Logger logger = Logger.getLogger(BrokenSchedule.class); 52 53 54 private Schedule schedule; 55 56 57 private Schedule breaks; 58 59 60 private Interval limits; 61 62 66 public void setLimits(Interval limits) { 67 this.limits = limits; 68 } 69 70 75 public Interval getLimits() { 76 return limits; 77 } 78 79 84 public void setSchedule(Schedule schedule) { 85 this.schedule = schedule; 86 } 87 88 93 public Schedule getSchedule() { 94 return this.schedule; 95 } 96 97 102 public void setBreaks(Schedule breaks) { 103 this.breaks = breaks; 104 } 105 106 111 112 public Schedule getBreaks() { 113 return this.breaks; 114 } 115 116 119 public Interval nextDue(ScheduleContext context) { 120 Date now = context.getDate(); 121 122 logger.debug(this + ": in interval is " + now); 123 124 if (schedule == null) { 126 return null; 127 } 128 schedule.setLimits(getLimits()); 129 if (breaks == null) { 130 return schedule.nextDue(context); 131 } 132 133 Date use = now; 134 135 while (true) { 137 if (use == null) { 138 return null; 139 } 140 141 Interval next = schedule.nextDue(context.spawn(use)); 142 if (next == null) { 144 return null; 145 } 146 147 Interval exclude = breaks.nextDue(context.spawn(next.getFromDate())); 149 150 if (exclude == null) { 151 return next; 152 } 153 if (next.isBefore(exclude)) { 155 return next; 156 } 157 158 use = DateUtils.oneMillisAfter(next.getToDate()); 161 } 162 } 163 164 167 public String toString() { 168 return "Broken Schedule"; 169 } 170 } 171 | Popular Tags |