use of com.swiftmq.swiftlet.scheduler.InvalidScheduleException in project swiftmq-ce by iitsoftware.
the class ScheduleFactory method createSchedule.
public static Schedule createSchedule(SwiftletContext ctx, String name, String jobGroup, String jobName, String calendar, String dateFrom, String dateTo, String timeExpr, String maxRt, boolean enabledLogging) throws InvalidScheduleException {
Schedule schedule = null;
if (timeExpr == null)
throw new InvalidScheduleException("Missing time expression!");
if (dateFrom != null && dateFrom.toLowerCase().equals(NOW))
dateFrom = null;
if (dateFrom != null) {
try {
fmt.parse(dateFrom);
} catch (ParseException e) {
throw new InvalidScheduleException(e.getMessage());
}
}
if (dateTo != null && dateTo.toLowerCase().equals(FOREVER))
dateTo = null;
if (dateTo != null) {
try {
fmt.parse(dateTo);
} catch (ParseException e) {
throw new InvalidScheduleException(e.getMessage());
}
}
if (dateFrom != null && dateTo != null && dateFrom.compareTo(dateTo) > 0)
throw new InvalidScheduleException("Date From (" + dateFrom + ") is greater than Date To (" + dateTo + ")!");
long maxRuntime = -1;
try {
if (maxRt != null && maxRt.trim().length() > 0)
maxRuntime = parseTime(maxRt);
} catch (Exception e) {
throw new InvalidScheduleException(e.getMessage());
}
boolean isAt = isAtExpression(timeExpr);
if (isAt) {
try {
schedule = new AtSchedule(name, true, enabledLogging, jobGroup, jobName, calendar, dateFrom, dateTo, maxRuntime, timeExpr, parseAt(timeExpr));
} catch (Exception e) {
throw new InvalidScheduleException(e.getMessage());
}
} else {
int[] vals = new int[0];
try {
vals = parseRepeat(timeExpr);
} catch (Exception e) {
throw new InvalidScheduleException(e.getMessage());
}
schedule = new RepeatSchedule(name, true, enabledLogging, jobGroup, jobName, calendar, dateFrom, dateTo, maxRuntime, timeExpr, vals[0], vals[1], vals[2], vals[3]);
}
return schedule;
}
use of com.swiftmq.swiftlet.scheduler.InvalidScheduleException in project swiftmq-ce by iitsoftware.
the class SchedulerSwiftletImpl method addTemporarySchedule.
public void addTemporarySchedule(String name, String jobGroup, String jobName, String calendar, String dateFrom, String dateTo, String timeExpr, String maxRuntime, boolean loggingEnabled) throws InvalidScheduleException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "addTemporarySchedule, name=" + name + " ...");
Schedule schedule = ScheduleFactory.createSchedule(ctx, name, jobGroup, jobName, calendar, dateFrom, dateTo, timeExpr, maxRuntime, loggingEnabled);
schedule.setEnabled(true);
try {
ctx.scheduler.enqueue(new ScheduleAdded(schedule.createCopy()));
} catch (Exception e) {
throw new InvalidScheduleException(e.toString());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "addTemporarySchedule, name=" + name + " done");
}
Aggregations