Java Code Examples for org.quartz.SchedulerContext#get()
The following examples show how to use
org.quartz.SchedulerContext#get() .
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: ChannelStaticJob.java From Lottery with GNU General Public License v2.0 | 6 votes |
protected void executeInternal(JobExecutionContext context)throws JobExecutionException { try { SchedulerContext schCtx = context.getScheduler().getContext(); //获取Spring中的上下文 ApplicationContext appCtx = (ApplicationContext)schCtx.get("applicationContext"); this.staticPageSvc= (StaticPageSvc)appCtx.getBean("staticPageSvc"); JobDataMap jdm=context.getJobDetail().getJobDataMap(); //获取栏目 String channelIdStr=(String) jdm.get(CmsTask.TASK_PARAM_CHANNEL_ID); if(!StringUtils.isBlank(channelIdStr)){ this.channelId=Integer.parseInt(channelIdStr); if(channelId.equals(0)){ channelId=null; } } //获取站点 String siteIdStr=(String) jdm.get(CmsTask.TASK_PARAM_SITE_ID); if(!StringUtils.isBlank(siteIdStr)){ this.siteId=Integer.parseInt(siteIdStr); } } catch (SchedulerException e1) { // TODO 尚未处理异常 e1.printStackTrace(); } staitcChannel(); }
Example 2
Source File: IndexStaticJob.java From Lottery with GNU General Public License v2.0 | 6 votes |
protected void executeInternal(JobExecutionContext context)throws JobExecutionException { try { SchedulerContext schCtx = context.getScheduler().getContext(); JobDataMap jdm=context.getJobDetail().getJobDataMap(); //获取Spring中的上下文 ApplicationContext appCtx = (ApplicationContext)schCtx.get("applicationContext"); this.cmsSiteMng= (CmsSiteMng)appCtx.getBean("cmsSiteMng"); this.staticPageSvc= (StaticPageSvc)appCtx.getBean("staticPageSvc"); this.sessionFactory=(SessionFactory) appCtx.getBean("sessionFactory"); this.siteId=Integer.parseInt((String) jdm.get(CmsTask.TASK_PARAM_SITE_ID)); } catch (SchedulerException e1) { // TODO 尚未处理异常 e1.printStackTrace(); } staticIndex(); }
Example 3
Source File: SchedulerJob.java From datacollector with Apache License 2.0 | 6 votes |
@Override public void execute(JobExecutionContext jobExecutionContext) { try { SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext(); PushSource.Context pushSourceContext = (PushSource.Context) schedulerContext.get( SchedulerPushSource.PUSH_SOURCE_CONTEXT ); if (pushSourceContext != null) { BatchContext batchContext = pushSourceContext.startBatch(); Record record = pushSourceContext.createRecord("cronRecord"); LinkedHashMap<String, Field> linkedHashMap = new LinkedHashMap<>(); linkedHashMap.put("timestamp", Field.createDatetime(new Date())); record.set(Field.createListMap(linkedHashMap)); batchContext.getBatchMaker().addRecord(record); pushSourceContext.processBatch(batchContext); } } catch (SchedulerException ex) { LOG.error(ex.getMessage(), ex); } }
Example 4
Source File: SchedulerTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public void execute(JobExecutionContext context) throws JobExecutionException { try { SchedulerContext schedulerContext = context.getScheduler().getContext(); schedulerContext.put(JOB_THREAD, Thread.currentThread()); CyclicBarrier barrier = (CyclicBarrier) schedulerContext.get(BARRIER); barrier.await(TEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); } catch (Throwable e) { e.printStackTrace(); throw new AssertionError("Await on barrier was interrupted: " + e.toString()); } }
Example 5
Source File: AcquisiteJob.java From Lottery with GNU General Public License v2.0 | 5 votes |
protected void executeInternal(JobExecutionContext context)throws JobExecutionException { try { SchedulerContext schCtx = context.getScheduler().getContext(); JobDataMap jdm=context.getJobDetail().getJobDataMap(); //获取采集源 this.acquId=Integer.parseInt((String) jdm.get(CmsTask.TASK_PARAM_ACQU_ID)); // 获取Spring中的上下文 ApplicationContext appCtx = (ApplicationContext) schCtx.get("applicationContext"); this.acquisitionSvc = (AcquisitionSvc) appCtx.getBean("acquisitionSvc"); } catch (SchedulerException e1) { // TODO 尚未处理异常 e1.printStackTrace(); } acquStart(); }
Example 6
Source File: ContentStaticJob.java From Lottery with GNU General Public License v2.0 | 5 votes |
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { try { SchedulerContext schCtx = context.getScheduler().getContext(); // 获取Spring中的上下文 ApplicationContext appCtx = (ApplicationContext) schCtx.get("applicationContext"); this.staticPageSvc = (StaticPageSvc) appCtx.getBean("staticPageSvc"); JobDataMap jdm=context.getJobDetail().getJobDataMap(); //获取栏目 String channelIdStr=(String) jdm.get(CmsTask.TASK_PARAM_CHANNEL_ID); if(!StringUtils.isBlank(channelIdStr)){ this.channelId=Integer.parseInt(channelIdStr); if(channelId.equals(0)){ channelId=null; } } //获取站点 String siteIdStr=(String) jdm.get(CmsTask.TASK_PARAM_SITE_ID); if(!StringUtils.isBlank(siteIdStr)){ this.siteId=Integer.parseInt(siteIdStr); } } catch (SchedulerException e1) { // TODO 尚未处理异常 e1.printStackTrace(); } staticContent(); }
Example 7
Source File: RequestJob.java From ingestion with Apache License 2.0 | 5 votes |
/** * Initialize properties that are received in the {@code SchedulerContext}. * * @param context */ @SuppressWarnings("unchecked") public void initProperties(SchedulerContext context) { queue = (LinkedBlockingQueue<Event>) context.get("queue"); properties = (Map<String, String>) context.get("properties"); client = (Client) context.get("client"); restSourceHandler = (RestSourceHandler) context.get(HANDLER); urlHandler = (UrlHandler) context.get(URL_HANDLER); }
Example 8
Source File: AbstractJob.java From cia with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: SchedulerServiceJob.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void execute( JobExecutionContext context ) throws JobExecutionException { try { SchedulerContext schedulerContext = context.getScheduler().getContext(); SchedulerService service = (SchedulerService) schedulerContext.get( "schedulerService" ); Value toSend = Value.create(); toSend.getFirstChild( "jobName" ).setValue( context.getJobDetail().getKey().getName() ); toSend.getFirstChild( "groupName" ).setValue( context.getJobDetail().getKey().getGroup() ); service.sendMessage( CommMessage.createRequest( service.getOperationName(), "/", toSend ) ); } catch( SchedulerException ex ) { Interpreter.getInstance().logSevere( ex ); } }
Example 10
Source File: AppDailyJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); AppDailyDataCenter appDailyDataCenter = applicationContext.getBean("appDailyDataCenter", AppDailyDataCenter.class); appDailyDataCenter.sendAppDailyEmail(); } catch (SchedulerException e) { logger.error(e.getMessage(), e); } }
Example 11
Source File: InstanceAlertValueJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { long startTime = System.currentTimeMillis(); SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); InstanceAlertConfigService instanceAlertConfigService = applicationContext.getBean("instanceAlertConfigService", InstanceAlertConfigService.class); instanceAlertConfigService.monitorLastMinuteAllInstanceInfo(); logger.info("InstanceAlertValueJob cost time {} ms", (System.currentTimeMillis() - startTime)); } catch (SchedulerException e) { logger.error(e.getMessage(), e); } }
Example 12
Source File: ErrorStatisticsJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); SchedulerContext schedulerContext; try { schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); EmailComponent emailComponent = applicationContext.getBean("emailComponent", EmailComponent.class); ErrorLoggerWatcherMBean errorLoggerWatcher = applicationContext.getBean("errorLoggerWatcher", ErrorLoggerWatcherMBean.class); // if (errorLoggerWatcher.getTotalErrorCount() == 0L) { // logger.warn("errorLoggerWatcher.totalErrorCount == 0 -o-"); // return; // } String title = "CacheCloud异常统计, 日期:" + dateFormat.format(date) + ";服务器:" + System.getProperty("local.ip") + ";总数:" + errorLoggerWatcher.getTotalErrorCount(); StringBuilder buffer = new StringBuilder(); buffer.append(title + ":<br/>"); for (Map.Entry<String, Long> entry : errorLoggerWatcher.getErrorInfos().entrySet()) { Long num = entry.getValue(); if (num == 0L) { continue; } String key = entry.getKey(); buffer.append(key + "=" + num + "<br/>"); } emailComponent.sendMailToAdmin(title, buffer.toString()); //清理异常 errorLoggerWatcher.clear(); } catch (SchedulerException e) { logger.error(e.getMessage(), e); } }
Example 13
Source File: MachineMonitorJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { JobDataMap dataMap = context.getMergedJobDataMap(); String ip = dataMap.getString(ConstUtils.HOST_KEY); long hostId = dataMap.getLong(ConstUtils.HOST_ID_KEY); SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); MachineCenter machineCenter = applicationContext.getBean("machineCenter", MachineCenter.class); machineCenter.asyncMonitorMachineStats(hostId, ip); } catch (SchedulerException e) { logger.error(e.getMessage(), e); } }
Example 14
Source File: SystemConfigRefreshJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); ConfigService configService = applicationContext.getBean("configService", ConfigService.class); configService.reloadSystemConfig(); } catch (SchedulerException e) { logger.error(e.getMessage(), e); } }
Example 15
Source File: InspectorJob.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public void action(JobExecutionContext context) { try { long start = System.currentTimeMillis(); SchedulerContext schedulerContext = context.getScheduler().getContext(); ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY); // 应用相关 InspectHandler inspectHandler; JobDataMap jobDataMap = context.getMergedJobDataMap(); String inspectorType = MapUtils.getString(jobDataMap, "inspectorType"); if (StringUtils.isBlank(inspectorType)) { logger.error("=====================InspectorJob:inspectorType is null====================="); return; } else if (inspectorType.equals("host")) { inspectHandler = applicationContext.getBean("hostInspectHandler", InspectHandler.class); } else if (inspectorType.equals("app")) { inspectHandler = applicationContext.getBean("appInspectHandler", InspectHandler.class); } else { logger.error("=====================InspectorJob:inspectorType not match:{}=====================", inspectorType); return; } inspectHandler.handle(); long end = System.currentTimeMillis(); logger.info("=====================InspectorJob {} Done! cost={} ms=====================", inspectHandler.getClass().getSimpleName(), (end - start)); } catch (Exception e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
Example 16
Source File: MonitoringJob.java From lams with GNU General Public License v2.0 | 5 votes |
protected Object getService(JobExecutionContext context, String serviceName) throws JobExecutionException { try { SchedulerContext sc = context.getScheduler().getContext(); ApplicationContext cxt = (ApplicationContext) sc.get(MonitoringJob.CONTEXT_NAME); return cxt.getBean(serviceName); } catch (SchedulerException e) { throw new JobExecutionException("Failed look up the " + serviceName + " " + e.toString()); } }
Example 17
Source File: QuartzWebManager.java From quartz-web with Apache License 2.0 | 4 votes |
/** * 获取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; }
Example 18
Source File: FileScanJob.java From AsuraFramework with Apache License 2.0 | 4 votes |
/** * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) */ public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap mergedJobDataMap = context.getMergedJobDataMap(); SchedulerContext schedCtxt = null; try { schedCtxt = context.getScheduler().getContext(); } catch (SchedulerException e) { throw new JobExecutionException("Error obtaining scheduler context.", e, false); } String fileName = mergedJobDataMap.getString(FILE_NAME); String listenerName = mergedJobDataMap.getString(FILE_SCAN_LISTENER_NAME); if(fileName == null) { throw new JobExecutionException("Required parameter '" + FILE_NAME + "' not found in merged JobDataMap"); } if(listenerName == null) { throw new JobExecutionException("Required parameter '" + FILE_SCAN_LISTENER_NAME + "' not found in merged JobDataMap"); } FileScanListener listener = (FileScanListener)schedCtxt.get(listenerName); if(listener == null) { throw new JobExecutionException("FileScanListener named '" + listenerName + "' not found in SchedulerContext"); } long lastDate = -1; if(mergedJobDataMap.containsKey(LAST_MODIFIED_TIME)) { lastDate = mergedJobDataMap.getLong(LAST_MODIFIED_TIME); } long newDate = getLastModifiedDate(fileName); if(newDate < 0) { log.warn("File '"+fileName+"' does not exist."); return; } if(lastDate > 0 && (newDate != lastDate)) { // notify call back... log.info("File '"+fileName+"' updated, notifying listener."); listener.fileUpdated(fileName); } else if (log.isDebugEnabled()) { log.debug("File '"+fileName+"' unchanged."); } // It is the JobDataMap on the JobDetail which is actually stateful context.getJobDetail().getJobDataMap().put(LAST_MODIFIED_TIME, newDate); }