|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.arsdigita.acs.Scheduler
Utility class for running scheduled procedures, modelled after the AOLserver ns_schedule_proc interface. Has an interface for daily/weekly procs.
Since procedures are not first-class objects in Java, we have to pass in the procedure to be scheduled wrapped inside an object that implements the java.lang.Runnable interface. We define an abstract class, ScheduledProcedure, that serves as a record for maintaining data about a stored procedure, when it will run next, whether or not it is periodic, etc.
We keep the list of scheduled procedures in a priority queue, so that the iteration over the list to figure out whose turn is next is done when procedures are scheduled rather than on a regular basis. Each task is run in its own thread, so that other scheduled procedures are not delayed due to one procedure's execution time.
java.util.Timer
,
Thread
,
ScheduledProcedure
Constructor Summary | |
Scheduler()
Creates a new Scheduler interface and starts it running. |
Method Summary | |
static Scheduler |
getInstance()
Utility function to get a static Scheduler instance. |
static void |
main(String[] args)
|
int |
schedule(ScheduledProcedure sp,
long interval)
Schedules a procedure to run every interval seconds. |
int |
scheduleDaily(ScheduledProcedure sp,
int hour,
int minute)
Schedules a procedure to run every day at hour:minute . |
int |
scheduleDailyOnce(ScheduledProcedure sp,
int hour,
int minute)
Schedules a procedure to run once at hour:minute . |
int |
scheduleOnce(ScheduledProcedure sp,
long interval)
Schedules a procedure to run once in interval seconds. |
int |
scheduleWeekly(ScheduledProcedure sp,
int day,
int hour,
int minute)
Schedules a procedure to run each week at hour:minute ,
on day . |
int |
scheduleWeeklyOnce(ScheduledProcedure sp,
int day,
int hour,
int minute)
Schedules a procedure to run once at hour:minute ,
on day . |
void |
unschedule(int spId)
Unschedules a scheduled procedure. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public Scheduler()
Method Detail |
public static Scheduler getInstance()
public int schedule(ScheduledProcedure sp, long interval)
interval
seconds.sp
- Proc to schedule.interval
- Time between execution in seconds.public int scheduleOnce(ScheduledProcedure sp, long interval)
interval
seconds.sp
- Proc to schedule.interval
- Time until execution, in seconds.public int scheduleDaily(ScheduledProcedure sp, int hour, int minute)
hour:minute
.sp
- Proc to schedule.hour
- Hour to run proc (in 24-hour time)minute
- Minute to run procpublic int scheduleDailyOnce(ScheduledProcedure sp, int hour, int minute)
hour:minute
.
Waits until tomorrow if that time has already passed today.sp
- Proc to schedule.hour
- Hour to run proc (in 24-hour time)minute
- Minute to run procpublic int scheduleWeekly(ScheduledProcedure sp, int day, int hour, int minute)
hour:minute
,
on day
.sp
- Proc to schedule.day
- Day of week to run proc. Use the day-of-week constants
in Calendar
.hour
- Hour to run proc (in 24-hour time)minute
- Minute to run procCalendar.DAY_OF_WEEK
public int scheduleWeeklyOnce(ScheduledProcedure sp, int day, int hour, int minute)
hour:minute
,
on day
. Waits for next week if that time has
already passed this week.sp
- Proc to schedule.day
- Day of week to run proc. Use the day-of-week constants
in Calendar
.hour
- Hour to run proc (in 24-hour time)minute
- Minute to run procCalendar.DAY_OF_WEEK
public void unschedule(int spId)
spId
- The scheduled proc ID to unschedule.public static void main(String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |