public void schedule (Daemon daemon) {
timer = new Timer(true);
daemonTask = new DaemonTimerTask(daemon);
Logger logger = daemon.getLogger();
if (!daemon.canSchedule()) {
logger.warning("NOT STARTED!");
return;
}
boolean atFixedRate = daemon.hasFixedRate();
if (daemon.hasStartAt()) {
DateTime startAt = daemon.getStartAt();
if (daemon.hasPolling()) {
DateTime polling = daemon.getPolling();
if (atFixedRate) {
logger.info("startAt(" + startAt + ", " + polling + ")");
timer.scheduleAtFixedRate(daemonTask, startAt, daemon.getPeriod());
} else {
logger.info("startAt(" + startAt + ", " + polling + ", constantRate)");
timer.schedule(daemonTask, startAt, daemon.getPeriod());
}
return;
}
logger.info("runOnceAt(" + startAt + ")");
timer.schedule(daemonTask, startAt);
return;
}
if (daemon.hasDelay()) {
DateTime delay = daemon.getDelay();
if (daemon.hasPolling()) {
DateTime polling = daemon.getPolling();
if (atFixedRate) {
logger.info("delay(" + delay + ", " + polling + ")");
timer.scheduleAtFixedRate(daemonTask, daemon.getDelayMillis(), daemon.getPeriod());
} else {
logger.info("delay(" + delay + ", " + polling + ", constantRate)");
timer.schedule(daemonTask, daemon.getDelayMillis(), daemon.getPeriod());
}
return;
}
logger.info("runOnceOnDelay(" + delay + ")");
timer.schedule(daemonTask, daemon.getDelayMillis());
return;
}
logger.warning("NOT SCHEDULED!");
return;
}