Search in sources :

Example 46 with JobDataMap

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ApplicationContext(org.springframework.context.ApplicationContext) MachineCenter(com.sohu.cache.machine.MachineCenter) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException)

Example 47 with JobDataMap

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ApplicationContext(org.springframework.context.ApplicationContext) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) RedisCenter(com.sohu.cache.redis.RedisCenter) SchedulerContext(org.quartz.SchedulerContext) SchedulerException(org.quartz.SchedulerException)

Example 48 with JobDataMap

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());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) Stopwatch(org.n52.web.common.Stopwatch) IoParameters(org.n52.io.request.IoParameters) RenderingConfig(org.n52.io.PrerenderingJobConfig.RenderingConfig)

Example 49 with JobDataMap

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();
}
Also used : JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 50 with JobDataMap

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);
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException)

Aggregations

JobDataMap (org.quartz.JobDataMap)59 Trigger (org.quartz.Trigger)21 JobDetail (org.quartz.JobDetail)20 SchedulerException (org.quartz.SchedulerException)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 Scheduler (org.quartz.Scheduler)10 JobExecutionException (org.quartz.JobExecutionException)9 ApplicationContext (org.springframework.context.ApplicationContext)9 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6 TriggerBean (org.akaza.openclinica.bean.admin.TriggerBean)6 Command (org.openhab.core.types.Command)5 SchedulerContext (org.quartz.SchedulerContext)5 SimpleTrigger (org.quartz.SimpleTrigger)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 Locale (java.util.Locale)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4