Java Code Examples for org.quartz.Scheduler#getContext()

The following examples show how to use org.quartz.Scheduler#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobDataMapManager.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化自动的调度器数据
 *
 * @param scheduler 调度器
 * @param jobBeanFactory JobBean工厂
 */
static void initAutomaticScheduler(Scheduler scheduler, JobBeanFactory jobBeanFactory) {
    try {
        SchedulerContext schedulerContext = scheduler.getContext();
        schedulerContext.put(JOB_BEAN_FACTORY_KEY, jobBeanFactory);
        schedulerContext.put(SCHEDULE_MODE_KEY, ScheduleMode.AUTOMATIC);
    } catch (SchedulerException e) {
        LoggerHelper.error("get schedule context failed.", e);
        throw new NiubiException(e);
    }
}
 
Example 2
Source File: JobDataMapManager.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化手动的调度器数据
 *
 * @param scheduler 调度器
 */
static void initManualScheduler(Scheduler scheduler) {
    try {
        SchedulerContext schedulerContext = scheduler.getContext();
        schedulerContext.put(SCHEDULE_MODE_KEY, ScheduleMode.MANUAL);
    } catch (SchedulerException e) {
        LoggerHelper.error("get schedule context failed.", e);
        throw new NiubiException(e);
    }
}
 
Example 3
Source File: AbstractJob.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the job context holder.
 *
 * @param jobContext
 *            the job context
 * @return the job context holder
 */
protected final JobContextHolder getJobContextHolder(final JobExecutionContext jobContext) {
	final Scheduler scheduler = jobContext.getScheduler();
	    JobContextHolder bean = null;
	    try {
	    	final SchedulerContext schedulerContext = scheduler.getContext();
	        final ApplicationContext appContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT);
	        bean = appContext.getBean(JobContextHolder.class);
	    } catch (final SchedulerException e) {
	       LOGGER.error("Failed to get JobContextHolder",e );
	    }

	return bean;
}
 
Example 4
Source File: QuartzWebManager.java    From quartz-web with Apache License 2.0 4 votes vote down vote up
/**
 * 获取Scheduler基本信息
 *
 * @return 返回基本信息的Map
 * @throws SchedulerException 异常
 */
public static List<SchedulerInfo> getAllSchedulerInfo() throws SchedulerException {
    List<SchedulerInfo> schedulerInfos = new ArrayList<SchedulerInfo>();
    Collection<Scheduler> allSchedulers = quartzManager.getSchedulers();

    for (Scheduler scheduler : allSchedulers) {
        // 获取Job数量
        List<JobDetail> allJobsOfScheduler = QuartzUtils.getAllJobsOfScheduler(scheduler);

        int triggerCount = 0;
        // 错误Trigger数量
        int triggerErrorCount = 0;
        // 堵塞Trigger数量
        int triggerBlockedCount = 0;
        // 暂停Trigger数量
        int triggerPausedCount = 0;
        for (JobDetail jobDetail : allJobsOfScheduler) {
            List<? extends Trigger> triggersOfJob = QuartzUtils.getTriggersOfJob(jobDetail, scheduler);
            for (Trigger trigger : triggersOfJob) {
                triggerCount++;
                boolean isError = QuartzUtils.isTriggerError(trigger, scheduler);
                if (isError) {
                    triggerErrorCount++;
                }
                boolean isBlocked = QuartzUtils.isTriggerBlocked(trigger, scheduler);
                if (isBlocked) {
                    triggerBlockedCount++;
                }
                boolean isPaused = QuartzUtils.isTriggerPaused(trigger, scheduler);
                if (isPaused) {
                    triggerPausedCount++;
                }
            }

        }

        // schedulerConext中参数Map
        List<Map<String, Object>> schedulerContextMapList = new ArrayList<Map<String, Object>>();
        SchedulerContext context = scheduler.getContext();
        Set<String> contextKeySet = context.keySet();
        for (String contextKey : contextKeySet) {
            Map<String, Object> contextMap = new LinkedHashMap<String, Object>();
            Object contextKeyObj = context.get(contextKey);
            // 是否支持json转换
            boolean support = JSONWriter.support(contextKeyObj);
            if (support) {
                contextMap.put("key", contextKey);
                contextMap.put("value", contextKeyObj);
            } else {
                contextMap.put("key", contextKey);
                contextMap.put("value", contextKeyObj.toString());
            }
            schedulerContextMapList.add(contextMap);
        }


        SchedulerInfo schedulerInfo = new SchedulerInfo();
        schedulerInfo.setSchedulerName(scheduler.getSchedulerName());
        schedulerInfo.setShutdown(scheduler.isShutdown());
        schedulerInfo.setStarted(scheduler.isStarted());
        schedulerInfo.setInStandbyMode(scheduler.isInStandbyMode());
        // 设置job数量
        schedulerInfo.setJobCount(allJobsOfScheduler.size());
        // 设置数量
        schedulerInfo.setTriggerCount(triggerCount);
        schedulerInfo.setTriggerErrorCount(triggerErrorCount);
        schedulerInfo.setTriggerBlockedCount(triggerBlockedCount);
        schedulerInfo.setTriggerPausedCount(triggerPausedCount);
        // 设置schedulerContext
        schedulerInfo.setSchedulerContext(schedulerContextMapList);

        schedulerInfos.add(schedulerInfo);
    }
    return schedulerInfos;
}