use of org.xbib.elasticsearch.common.cron.CronExpression in project elasticsearch-jdbc by jprante.
the class JDBCImporter method schedule.
private List<Future> schedule(Settings settings) {
List<Future> futures = new LinkedList<>();
if (threadPoolExecutor != null) {
logger.info("already scheduled");
return futures;
}
String[] schedule = settings.getAsArray("schedule");
Long seconds = settings.getAsTime("interval", TimeValue.timeValueSeconds(0)).seconds();
if (schedule != null && schedule.length > 0) {
Thread thread = new Thread(this);
CronThreadPoolExecutor cronThreadPoolExecutor = new CronThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
for (String cron : schedule) {
futures.add(cronThreadPoolExecutor.schedule(thread, new CronExpression(cron)));
}
this.threadPoolExecutor = cronThreadPoolExecutor;
logger.info("scheduled with cron expressions {}", Arrays.asList(schedule));
} else if (seconds > 0L) {
Thread thread = new Thread(this);
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(settings.getAsInt("threadpoolsize", 1));
futures.add(scheduledThreadPoolExecutor.scheduleAtFixedRate(thread, 0L, seconds, TimeUnit.SECONDS));
this.threadPoolExecutor = scheduledThreadPoolExecutor;
logger.info("scheduled at fixed rate of {} seconds", seconds);
}
return futures;
}
Aggregations