use of org.quartz.JobDataMap in project cachecloud by sohutv.
the class MachineJob method action.
@Override
public void action(JobExecutionContext context) {
try {
JobDataMap dataMap = context.getMergedJobDataMap();
Date now = new Date();
dataMap.put(ConstUtils.TRIGGER_TIME_KEY, now);
SchedulerContext schedulerContext = context.getScheduler().getContext();
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
MachineCenter machineCenter = applicationContext.getBean("machineCenter", MachineCenter.class);
String ip = dataMap.getString(ConstUtils.HOST_KEY);
long hostId = dataMap.getLong(ConstUtils.HOST_ID_KEY);
machineCenter.asyncCollectMachineInfo(hostId, ScheduleUtil.getCollectTime(new Date()), ip);
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
use of org.quartz.JobDataMap in project cachecloud by sohutv.
the class RedisJob method action.
/**
* 实现收集任务,通过RedisCenter
*
* @param context
*/
@Override
public void action(JobExecutionContext context) {
JobDataMap dataMap = new JobDataMap();
try {
SchedulerContext schedulerContext = context.getScheduler().getContext();
ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
RedisCenter redisCenter = (RedisCenter) applicationContext.getBean("redisCenter");
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.collectRedisInfo(appId, collectTime, host, port);
} catch (SchedulerException e) {
logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
logger.error(e.getMessage(), e);
} catch (Exception e) {
logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
logger.error(e.getMessage(), e);
}
}
use of org.quartz.JobDataMap in project series-rest-api by 52North.
the class PreRenderingJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (interrupted) {
return;
}
LOGGER.info("Start prerendering task");
final Stopwatch stopwatch = Stopwatch.startStopwatch();
final JobDetail details = context.getJobDetail();
JobDataMap jobDataMap = details.getJobDataMap();
taskConfigPrerendering = readJobConfig(jobDataMap.getString(JOB_DATA_CONFIG_FILE));
webappFolder = jobDataMap.getString(JOB_DATA_WEBAPP_FOLDER);
List<RenderingConfig> phenomenonStyles = taskConfigPrerendering.getPhenomenonStyles();
List<RenderingConfig> styles = taskConfigPrerendering.getSeriesStyles();
for (RenderingConfig config : phenomenonStyles) {
Map<String, String> parameters = new HashMap<>();
parameters.put("phenomenon", config.getId());
IoParameters query = QueryParameters.createFromQuery(parameters);
for (DatasetOutput<?, ?> metadata : datasetService.getCondensedParameters(query)) {
String timeseriesId = metadata.getId();
renderConfiguredIntervals(timeseriesId, config);
if (interrupted) {
return;
}
}
}
for (RenderingConfig config : styles) {
renderConfiguredIntervals(config.getId(), config);
if (interrupted) {
return;
}
}
LOGGER.debug("prerendering took '{}'", stopwatch.stopInSeconds());
}
use of org.quartz.JobDataMap in project camel by apache.
the class QuartzManuallyTriggerJobTest method testQuartzCronRoute.
@Test
public void testQuartzCronRoute() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
Scheduler scheduler = component.getScheduler();
// collect all jobKeys of this route (ideally only one).
ArrayList<JobKey> jobKeys = new ArrayList<JobKey>();
for (String group : scheduler.getJobGroupNames()) {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
jobKeys.add(jobKey);
}
}
JobDataMap jobDataMap = scheduler.getJobDetail(jobKeys.get(0)).getJobDataMap();
// trigger job manually
scheduler.triggerJob(jobKeys.get(0), jobDataMap);
assertMockEndpointsSatisfied();
}
use of org.quartz.JobDataMap in project deltaspike by apache.
the class DynamicExpressionObserverJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
String configExpression = jobDataMap.getString(CONFIG_EXPRESSION_KEY);
String triggerId = jobDataMap.getString(TRIGGER_ID_KEY);
String activeCronExpression = jobDataMap.getString(ACTIVE_CRON_EXPRESSION_KEY);
String configKey = configExpression.substring(1, configExpression.length() - 1);
String configuredValue = ConfigResolver.getPropertyAwarePropertyValue(configKey, activeCronExpression);
if (!activeCronExpression.equals(configuredValue)) {
//both #put calls are needed currently
context.getJobDetail().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);
context.getTrigger().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);
BeanProvider.injectFields(this);
JobKey observerJobKey = context.getJobDetail().getKey();
String observedJobName = observerJobKey.getName().substring(0, observerJobKey.getName().length() - OBSERVER_POSTFIX.length());
JobKey observedJobKey = new JobKey(observedJobName, observerJobKey.getGroup());
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerId).forJob(observedJobName, observedJobKey.getGroup()).withSchedule(CronScheduleBuilder.cronSchedule(configuredValue)).build();
//use rescheduleJob instead of delete + add
//(unwrap is ok here, because this class will only get active in case of a quartz-scheduler)
org.quartz.Scheduler quartzScheduler = scheduler.unwrap(org.quartz.Scheduler.class);
try {
quartzScheduler.rescheduleJob(trigger.getKey(), trigger);
} catch (SchedulerException e) {
LOG.warning("failed to updated cron-expression for " + observedJobKey);
}
}
}
Aggregations