Search in sources :

Example 1 with ScheduleOptions

use of org.apache.karaf.scheduler.ScheduleOptions in project karaf by apache.

the class Schedule method execute.

@Override
public Object execute() throws Exception {
    if (cron != null && (at != null || times != -1 || period != 0)) {
        throw new IllegalArgumentException("Both cron expression and explicit execution time can not be specified");
    }
    ScheduleOptions options;
    if (cron != null) {
        options = scheduler.EXPR(cron);
    } else {
        Date date;
        if (at != null) {
            date = DatatypeConverter.parseDateTime(at).getTime();
        } else {
            date = new Date();
        }
        if (period > 0) {
            options = scheduler.AT(date, times, period);
        } else {
            options = scheduler.AT(date);
        }
    }
    if (name != null) {
        options.name(name);
    }
    if (concurrent) {
        options.canRunConcurrently(concurrent);
    }
    scheduler.schedule(new ScriptJob(session, script), options);
    return null;
}
Also used : ScheduleOptions(org.apache.karaf.scheduler.ScheduleOptions) ScriptJob(org.apache.karaf.scheduler.command.support.ScriptJob) Date(java.util.Date)

Example 2 with ScheduleOptions

use of org.apache.karaf.scheduler.ScheduleOptions in project karaf by apache.

the class List method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column("Name");
    table.column("Schedule");
    Map<Object, ScheduleOptions> jobs = scheduler.getJobs();
    for (Map.Entry<Object, ScheduleOptions> entry : jobs.entrySet()) {
        table.addRow().addContent(entry.getValue().name(), entry.getValue().schedule());
    }
    table.print(System.out);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) ScheduleOptions(org.apache.karaf.scheduler.ScheduleOptions) Map(java.util.Map)

Example 3 with ScheduleOptions

use of org.apache.karaf.scheduler.ScheduleOptions in project karaf by apache.

the class QuartzScheduler method getJobs.

@Override
public Map<Object, ScheduleOptions> getJobs() throws SchedulerException {
    Map<Object, ScheduleOptions> jobs = new HashMap<>();
    org.quartz.Scheduler s = this.scheduler;
    if (s != null) {
        for (String group : s.getJobGroupNames()) {
            for (JobKey key : s.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
                JobDetail detail = s.getJobDetail(key);
                ScheduleOptions options = (ScheduleOptions) detail.getJobDataMap().get(DATA_MAP_OPTIONS);
                Object job = detail.getJobDataMap().get(DATA_MAP_OBJECT);
                jobs.put(job, options);
            }
        }
    }
    return jobs;
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) ScheduleOptions(org.apache.karaf.scheduler.ScheduleOptions) HashMap(java.util.HashMap)

Aggregations

ScheduleOptions (org.apache.karaf.scheduler.ScheduleOptions)3 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScriptJob (org.apache.karaf.scheduler.command.support.ScriptJob)1 ShellTable (org.apache.karaf.shell.support.table.ShellTable)1 JobDetail (org.quartz.JobDetail)1 JobKey (org.quartz.JobKey)1