Search in sources :

Example 1 with ScriptJob

use of org.apache.karaf.scheduler.command.support.ScriptJob 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)

Aggregations

Date (java.util.Date)1 ScheduleOptions (org.apache.karaf.scheduler.ScheduleOptions)1 ScriptJob (org.apache.karaf.scheduler.command.support.ScriptJob)1