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);
}
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);
}
}
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);
}
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);
}
}
}
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;
}
Aggregations