WIDAR Classes

edu.nrao.widar.util
Class CalendarTimer

java.lang.Object
  extended by java.util.Timer
      extended by edu.nrao.widar.util.CalendarTimer

public class CalendarTimer
extends java.util.Timer

CalendarTimer is a java.util.Timer that can be set to fire at a specific time and then repeat at a period appropriate to the specified start-time. For example, setting a timer that fires every day at 1630 or 10 minutes past every hour or every minute on the minute. This cannot be done with the basic java.util.Timer unless the start time of the process using it is known. CalendarTimer is set by passing an array of one to three integers that represent the fire-time's seconds, minutes and hours. For example to specify a timer that fires everyday at 1630 one would create a CalendarTimer with the array {00, 30, 16}. For a timer that fires at 10 minutes past every hour, the array {00, 10} would be used. Finally, for firing every minute on the minute, the array would simply be {0}. The repeat period is automatically determined based on the highest unit of time passed in the input array. If hours are specified, then the repeat period is 1 day, if minutes are the highest unit specified, the repeat period is 1 hour. Finally, if only seconds are specified, the repeat period is 1 minute. If the specified firing time has already passed (for example if a timer specified to fire everyday at 1630 was started at 1631), the calculated repeat period (in this case, 1 day) will be added to the start time. java.util.Timer's repeat periods are constant from when the timer starts and cannot be varied without cancelling the previous timer and starting a new one. For that reason we do not do day-of-week, day-of-month and day-of-year events (they would require varying repeat periods to account for the varying number of days in months and leapyear (which also affects day-of-week during leapyears).

Since:
1.6
Author:
KJRyan
Created:
2012.02.24
 

Constructor Summary
CalendarTimer(java.util.TimerTask task, int[] time, boolean repeat, java.lang.String name)
          Creates a CalendarTimer using java.util.Timer's constructor that accepts a single name String parameter and either its schedule method of non-repeating or its scheduleAtFixedRate method if repeating is specified.
 
Method Summary
 
Methods inherited from class java.util.Timer
cancel, purge, schedule, schedule, schedule, schedule, scheduleAtFixedRate, scheduleAtFixedRate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CalendarTimer

public CalendarTimer(java.util.TimerTask task,
                     int[] time,
                     boolean repeat,
                     java.lang.String name)
              throws java.lang.NumberFormatException
Creates a CalendarTimer using java.util.Timer's constructor that accepts a single name String parameter and either its schedule method of non-repeating or its scheduleAtFixedRate method if repeating is specified.

Throws:
java.lang.NumberFormatException
Parameters:
task - the java.util.TimerTask that will be called when the timer fires
time - the array of integers that specifies seconds, minutes and hours; this array must specify at least seconds and must not specify more than hours (in other words, 1 <= time.length <= 3
repeat - true = repeat at appropriate rate, false = fire once only
name - the name of the Thread associated with this timer

NRAO/DRAO

National Radio Astronomy Observatory