private void startSchedule(Scheduler sched, String name, CronData data) throws XmlBlasterException {
try {
log.info("Starting scheduler " + data.toString());
Class clazz = Class.forName(data.getCommand());
JobDetail jobDetail = new JobDetail(name, null, clazz);
Object obj = global.getObjectEntry(ORIGINAL_ENGINE_GLOBAL);
if (obj != null)
jobDetail.getJobDataMap().put(ORIGINAL_ENGINE_GLOBAL, obj);
else
throw new XmlBlasterException(global, ErrorCode.INTERNAL, "SchedulerPlugin.doInit", "Could not find the ServerScope");
String triggerName = name;
Trigger trigger = null;
if (data.getMonth() > -1)
throw new XmlBlasterException(global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "Yearly Events are not implemented");
int dayOfMonth = data.getDayOfMonth();
int hour = data.getHour();
int min = data.getMin();
if (dayOfMonth > -1) { // monthly trigger
if (hour < 0)
throw new XmlBlasterException(this.global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "On monthly triggers the hour must be specified");
if (min < 0)
throw new XmlBlasterException(this.global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "On monthly triggers the min must be specified");
trigger = TriggerUtils.makeMonthlyTrigger(triggerName, dayOfMonth, hour, min);
trigger.setStartTime(new Date()); // start now
}
else {
int dayOfWeek = data.getDayOfWeek();
if (dayOfWeek > -1) {
if (hour < 0)
throw new XmlBlasterException(this.global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "On weekly triggers the hour must be specified");
if (min < 0)
throw new XmlBlasterException(this.global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "On weekly triggers the min must be specified");
trigger = TriggerUtils.makeWeeklyTrigger(triggerName, dayOfWeek+1, hour, min);
trigger.setStartTime(new Date()); // start now
}
else {
if (hour > -1) {
if (min < 0)
throw new XmlBlasterException(this.global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "On daily triggers the min must be specified");
trigger = TriggerUtils.makeDailyTrigger(triggerName, hour, min);
trigger.setStartTime(new Date()); // start now
}
else {
if (min > -1) {
trigger = TriggerUtils.makeHourlyTrigger(1);
trigger.setName(triggerName);
Date startTime = TriggerUtils.getNextGivenMinuteDate(new Date(), min);
trigger.setStartTime(startTime);
}
else {
throw new XmlBlasterException(global, ErrorCode.USER_CONFIGURATION, "SchedulerPlugin.doInit", "No time has been specified in the configuration");
}
}
}
}
String[] args = data.getArguments();
for (int i=0; i < args.length; i++)
jobDetail.getJobDataMap().put("arg" + i, args[i]);
sched.scheduleJob(jobDetail, trigger);
cronDataMap.put(name, data);
}
catch (ClassNotFoundException ex) {
throw new XmlBlasterException(this.global, ErrorCode.RESOURCE, "", "SchedulerPlugin.doInit", ex);