org.oddjob.schedules.schedules
Class TimeSchedule

java.lang.Object
  extended by org.oddjob.schedules.AbstractSchedule
      extended by org.oddjob.schedules.schedules.TimeSchedule
All Implemented Interfaces:
Serializable, RefineableSchedule, Schedule

public final class TimeSchedule
extends AbstractSchedule
implements Serializable

Description

Provide a schedule for an interval of time. When used as a refinement this schedule will narrow the parent interval down to an interval of time on the first day of the parent interval, or if the toLast property is specified, from the first day to the last day of the parent interval. When used as the topmost definition for a schedule then this schedule specifies a single interval of time starting on the current day.

To provide a schedule for each day at a certain time see the DailySchedule schedules.

Example

A simple time example.
<schedules:time at="10:00" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
When used with a Timer this would run a job just once at 10am, and never again. If the timer was started after 10am, then the job would run the following day at 10am. If it was required that the job would run any time the timer was started after 10am then the from property should be used instead of the at property.

Example

Using an interval with time to schedule something every 15 minutes between 10pm and 4am the next day. The end time is 03:50 yet the last interval is 03:45 to 04:00 because the interval starts before the end time.
<schedules:time from="22:00" to="03:50" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
    <refinement>
        <schedules:interval interval="00:15"/>
    </refinement>
</schedules:time>

Example

Schedule something over a whole week between two times. This demonstrates how the toLast property works.
<schedules:weekly from="Monday" to="Friday" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
    <refinement>
        <schedules:time from="08:00" toLast="18:00">
            <refinement>
                <schedules:interval interval="02:00"/>
            </refinement>
        </schedules:time>
    </refinement>
</schedules:weekly>
The schedule would be due every two hours all day and all night from 8am Monday morning until 6pm Friday afternoon.
See Also:
Serialized Form
Author:
Rob Gordon

Constructor Summary
TimeSchedule()
           
 
Method Summary
protected  Calendar fromCalendar(ScheduleContext context)
           
 String getFrom()
           
 String getTo()
           
 String getToLast()
           
protected  CalendarUnit intervalBetween()
           
protected  Interval lastInterval(ScheduleContext context)
          Calculate the last interval.
 ScheduleResult nextDue(ScheduleContext context)
          For a given date a schedule will provide the interval this schedule should next be scheduled in.
protected  Interval nextInterval(ScheduleContext context)
          /** Calculate the next interval, without children.
protected  Calendar nowCalendar(ScheduleContext context)
           
 void setAt(String at)
           
 void setFrom(String from)
           
 void setTo(String to)
           
 void setToLast(String toLast)
           
protected  Calendar shiftFromCalendar(Calendar calendar, int intervals)
           
protected  Calendar shiftToCalendar(Calendar calendar, int intervals)
           
protected  Calendar toCalendar(ScheduleContext context)
           
 String toString()
          Override toString.
 
Methods inherited from class org.oddjob.schedules.AbstractSchedule
getRefinement, setRefinement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimeSchedule

public TimeSchedule()
Method Detail

setFrom

public void setFrom(String from)

Property: from

Description: The from time.

Required: No. Defaults to the start of any parent interval or the beginning of time.

Parameters:
from - The from date.

getFrom

public String getFrom()

setTo

public void setTo(String to)

Property: to

Description: The to time. If specified, this is the time on the first day of the parent interval.

Required: No. Defaults to the end of the last day of the parent interval, or the end of time.

Parameters:
to - The to date.

getTo

public String getTo()

setAt

public void setAt(String at)

Property: at

Description: The time at which this schedule is for. This has the same effect as setting from and to to the same thing.

Required: No.

Parameters:
at - The at time.

getToLast

public String getToLast()

setToLast

public void setToLast(String toLast)

Property: toLast

Description: The to time for the end of the parent interval. This differs from the to property in that the to property is for the first day of the parent interval.

Required: No. The to property, or it's default value, will be used instead.

Parameters:
toLast - The to last time of the interval.

intervalBetween

protected CalendarUnit intervalBetween()

fromCalendar

protected Calendar fromCalendar(ScheduleContext context)

toCalendar

protected Calendar toCalendar(ScheduleContext context)

nowCalendar

protected Calendar nowCalendar(ScheduleContext context)
Parameters:
context -
Returns:

nextInterval

protected final Interval nextInterval(ScheduleContext context)
/** Calculate the next interval, without children.

Parameters:
context -
Returns:

lastInterval

protected final Interval lastInterval(ScheduleContext context)
Calculate the last interval.

Parameters:
context -
Returns:

shiftFromCalendar

protected Calendar shiftFromCalendar(Calendar calendar,
                                     int intervals)

shiftToCalendar

protected Calendar shiftToCalendar(Calendar calendar,
                                   int intervals)

nextDue

public ScheduleResult nextDue(ScheduleContext context)
Description copied from interface: Schedule
For a given date a schedule will provide the interval this schedule should next be scheduled in.

If the schedule is never due again for the given date, null is returned.

Specified by:
nextDue in interface Schedule
Returns:
The next due interval for the schedule.

toString

public String toString()
Override toString.

Overrides:
toString in class Object
Returns:
A description of the schedule.