Search in sources :

Example 21 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class MachineCenterImpl method unDeployMachineMonitor.

@Override
public boolean unDeployMachineMonitor(long hostId, String ip) {
    Assert.isTrue(hostId > 0);
    Assert.hasText(ip);
    TriggerKey monitorTriggerKey = TriggerKey.triggerKey(ip, ConstUtils.MACHINE_MONITOR_TRIGGER_GROUP + hostId);
    Trigger trigger = schedulerCenter.getTrigger(monitorTriggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(monitorTriggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Example 22 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class RedisSlowLogJob method action.

@Override
public void action(JobExecutionContext context) {
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        RedisCenter redisCenter = (RedisCenter) applicationContext.getBean("redisCenter");
        JobDataMap dataMap = context.getMergedJobDataMap();
        String host = dataMap.getString(ConstUtils.HOST_KEY);
        int port = dataMap.getInt(ConstUtils.PORT_KEY);
        long appId = dataMap.getLong(ConstUtils.APP_KEY);
        Trigger trigger = context.getTrigger();
        long collectTime = ScheduleUtil.getCollectTime(trigger.getPreviousFireTime());
        redisCenter.collectRedisSlowLog(appId, collectTime, host, port);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) JobDataMap(org.quartz.JobDataMap) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) RedisCenter(com.sohu.cache.redis.RedisCenter) SchedulerContext(org.quartz.SchedulerContext) SchedulerException(org.quartz.SchedulerException)

Example 23 with Trigger

use of org.quartz.Trigger in project cachecloud by sohutv.

the class RedisCenterImpl method unDeployRedisSlowLogCollection.

@Override
public boolean unDeployRedisSlowLogCollection(long appId, String host, int port) {
    Assert.isTrue(appId > 0);
    Assert.hasText(host);
    Assert.isTrue(port > 0);
    TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_SLOWLOG_TRIGGER_GROUP + appId);
    Trigger trigger = schedulerCenter.getTrigger(triggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(triggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Example 24 with Trigger

use of org.quartz.Trigger in project camel by apache.

the class QuartzComponent method deleteJob.

public void deleteJob(String name, String group) throws SchedulerException {
    if (isClustered()) {
        // do not pause jobs which are clustered, as we want the jobs to continue running on the other nodes
        LOG.debug("Cannot delete job using trigger: {}/{} as the JobStore is clustered.", group, name);
    } else {
        Trigger trigger = getScheduler().getTrigger(name, group);
        if (trigger != null) {
            LOG.debug("Deleting job using trigger: {}/{}", group, name);
            getScheduler().unscheduleJob(name, group);
        }
    }
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger)

Example 25 with Trigger

use of org.quartz.Trigger in project camel by apache.

the class QuartzComponent method createEndpoint.

@Override
protected QuartzEndpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
    // lets split the remaining into a group/name
    URI u = new URI(uri);
    String path = ObjectHelper.after(u.getPath(), "/");
    String host = u.getHost();
    String cron = getAndRemoveParameter(parameters, "cron", String.class);
    boolean fireNow = getAndRemoveParameter(parameters, "fireNow", Boolean.class, Boolean.FALSE);
    Integer startDelayedSeconds = getAndRemoveParameter(parameters, "startDelayedSeconds", Integer.class);
    if (startDelayedSeconds != null) {
        if (scheduler.isStarted()) {
            LOG.warn("A Quartz job is already started. Cannot apply the 'startDelayedSeconds' configuration!");
        } else if (this.startDelayedSeconds != 0 && !(this.startDelayedSeconds == startDelayedSeconds)) {
            LOG.warn("A Quartz job is already configured with a different 'startDelayedSeconds' configuration! " + "All Quartz jobs must share the same 'startDelayedSeconds' configuration! Cannot apply the 'startDelayedSeconds' configuration!");
        } else {
            this.startDelayedSeconds = startDelayedSeconds;
        }
    }
    // host can be null if the uri did contain invalid host characters such as an underscore
    if (host == null) {
        host = ObjectHelper.before(remaining, "/");
        if (host == null) {
            host = remaining;
        }
    }
    // group can be optional, if so set it to Camel
    String name;
    String group;
    if (ObjectHelper.isNotEmpty(path) && ObjectHelper.isNotEmpty(host)) {
        group = host;
        name = path;
    } else {
        group = "Camel";
        name = host;
    }
    Map<String, Object> triggerParameters = IntrospectionSupport.extractProperties(parameters, "trigger.");
    Map<String, Object> jobParameters = IntrospectionSupport.extractProperties(parameters, "job.");
    Trigger trigger;
    boolean stateful = "true".equals(parameters.get("stateful"));
    // if we're starting up and not running in Quartz clustered mode or not stateful then check for a name conflict.
    if (!isClustered() && !stateful) {
        // check to see if this trigger already exists
        trigger = getScheduler().getTrigger(name, group);
        if (trigger != null) {
            String msg = "A Quartz job already exists with the name/group: " + name + "/" + group;
            throw new IllegalArgumentException(msg);
        }
    }
    // create the trigger either cron or simple
    if (ObjectHelper.isNotEmpty(cron)) {
        cron = encodeCronExpression(cron);
        trigger = createCronTrigger(cron);
    } else {
        trigger = new SimpleTrigger();
        if (fireNow) {
            String intervalString = (String) triggerParameters.get("repeatInterval");
            if (intervalString != null) {
                long interval = EndpointHelper.resolveParameter(getCamelContext(), intervalString, Long.class);
                trigger.setStartTime(new Date(System.currentTimeMillis() - interval));
            }
        }
    }
    QuartzEndpoint answer = new QuartzEndpoint(uri, this);
    answer.setGroupName(group);
    answer.setTimerName(name);
    answer.setCron(cron);
    answer.setFireNow(fireNow);
    if (startDelayedSeconds != null) {
        answer.setStartDelayedSeconds(startDelayedSeconds);
    }
    if (triggerParameters != null && !triggerParameters.isEmpty()) {
        answer.setTriggerParameters(triggerParameters);
    }
    if (jobParameters != null && !jobParameters.isEmpty()) {
        answer.setJobParameters(jobParameters);
        setProperties(answer.getJobDetail(), jobParameters);
    }
    // enrich job data map with trigger information
    if (cron != null) {
        answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
        answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, cron);
        String timeZone = EndpointHelper.resolveParameter(getCamelContext(), (String) triggerParameters.get("timeZone"), String.class);
        if (timeZone != null) {
            answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, timeZone);
        }
    } else {
        answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "simple");
        Long interval = EndpointHelper.resolveParameter(getCamelContext(), (String) triggerParameters.get("repeatInterval"), Long.class);
        if (interval != null) {
            triggerParameters.put("repeatInterval", interval);
            answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL, interval);
        }
        Integer counter = EndpointHelper.resolveParameter(getCamelContext(), (String) triggerParameters.get("repeatCount"), Integer.class);
        if (counter != null) {
            triggerParameters.put("repeatCount", counter);
            answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER, counter);
        }
    }
    setProperties(trigger, triggerParameters);
    trigger.setName(name);
    trigger.setGroup(group);
    answer.setTrigger(trigger);
    return answer;
}
Also used : URI(java.net.URI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger)

Aggregations

Trigger (org.quartz.Trigger)98 JobDetail (org.quartz.JobDetail)47 SchedulerException (org.quartz.SchedulerException)37 CronTrigger (org.quartz.CronTrigger)28 Test (org.junit.Test)23 JobDataMap (org.quartz.JobDataMap)21 Scheduler (org.quartz.Scheduler)21 TriggerKey (org.quartz.TriggerKey)20 SimpleTrigger (org.quartz.SimpleTrigger)19 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)18 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4