Java 类org.quartz.SchedulerContext 实例源码

项目:Camel    文件:ScheduledJob.java   
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    LOG.debug("Running ScheduledJob: jobExecutionContext={}", jobExecutionContext);

    SchedulerContext schedulerContext = getSchedulerContext(jobExecutionContext);
    ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getKey().toString());
    Action storedAction = state.getAction(); 
    Route storedRoute = state.getRoute();

    List<RoutePolicy> policyList = storedRoute.getRouteContext().getRoutePolicyList();
    for (RoutePolicy policy : policyList) {
        try {
            if (policy instanceof ScheduledRoutePolicy) {
                ((ScheduledRoutePolicy)policy).onJobExecute(storedAction, storedRoute);
            }
        } catch (Exception e) {
            throw new JobExecutionException("Failed to execute Scheduled Job for route " + storedRoute.getId()
                    + " with trigger name: " + jobExecutionContext.getTrigger().getKey(), e);
        }
    }
}
项目:Camel    文件:CamelJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
    String camelContextName = (String) context.getJobDetail().getJobDataMap().get(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME);
    String endpointUri = (String) context.getJobDetail().getJobDataMap().get(QuartzConstants.QUARTZ_ENDPOINT_URI);

    SchedulerContext schedulerContext;
    try {
        schedulerContext = context.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + context.getJobDetail().getName());
    }

    CamelContext camelContext = (CamelContext) schedulerContext.get(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName);
    if (camelContext == null) {
        throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
    }

    Trigger trigger = context.getTrigger();
    QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, endpointUri, trigger);
    if (endpoint == null) {
        throw new JobExecutionException("No QuartzEndpoint could be found with endpointUri: " + endpointUri);
    }
    endpoint.onJobExecute(context);
}
项目:jeecms6    文件:IndexStaticJob.java   
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();
}
项目:jeecms6    文件:ChannelStaticJob.java   
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();
}
项目:carbon-transports    文件:PollingJob.java   
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    SchedulerContext schedulerContext = null;
    try {
        schedulerContext = jobExecutionContext.getScheduler().getContext();
    } catch (SchedulerException e1) {
        log.debug("Exception occurred while getting scheduler context", e1);
    }
    if (schedulerContext == null) {
        log.error("Scheduler context is null");
        return;
    }
    PollingServerConnector connector = (PollingServerConnector) schedulerContext.get("connector");

    // Run the poll cycles
    log.debug("Executing the polling task for server connector ID: " + connector.getId());
    try {
        connector.poll();
    } catch (Exception e) {
        log.error("Error executing the polling cycle for server connector ID: " + connector.getId(), e);
    }
    log.debug("Exit the polling task running loop for server connector ID: " + connector.getId());
}
项目:superfly    文件:BaseJob.java   
/**
 * Obtains Spring's application context.
 *
 * @param context    job execution context
 * @return application context
 * @throws SchedulerException
 */
protected ApplicationContext getApplicationContext(JobExecutionContext context)
        throws SchedulerException {

    final SchedulerContext schedulerContext = context.getScheduler().getContext();
    ApplicationContext applicationContext =  (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);

    // show keys in context
    if(applicationContext==null) {
        logger.error(APPLICATION_CONTEXT_KEY+" is empty in "+ schedulerContext+":");
        if(schedulerContext.getKeys()!=null) {
            for (String key : schedulerContext.getKeys()) {
                Object value = schedulerContext.get(key);
                String valueText = value!=null ? value.toString() : "<NULL>";
                logger.info("    {} = {}", key, valueText);
            }
        }
    }

    return applicationContext;
}
项目:concourseconnect-community    文件:CleanupTempFilesJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
  SchedulerContext schedulerContext = null;
  Connection db = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    ApplicationPrefs prefs = (ApplicationPrefs) schedulerContext.get(
        "ApplicationPrefs");
    String fs = System.getProperty("file.separator");
    db = SchedulerUtils.getConnection(schedulerContext);
    LOG.debug("Checking temporary files...");
    FileItemList tempFiles = new FileItemList();
    tempFiles.setLinkModuleId(Constants.TEMP_FILES);
    tempFiles.setAlertRangeEnd(new Timestamp(System.currentTimeMillis() - (60L * 60L * 1000L)));
    tempFiles.buildList(db);
    tempFiles.delete(db,
        prefs.get("FILELIBRARY") + "1" + fs + "projects" + fs);
  } catch (Exception e) {
    LOG.error("CleanupTempFilesJob Exception", e);
    throw new JobExecutionException(e.getMessage());
  } finally {
    SchedulerUtils.freeConnection(schedulerContext, db);
  }
}
项目:ingestion    文件:RequestJob.java   
/**
 * {@inheritDoc}
 *
 * @param context
 */
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    this.context = context;
    SchedulerContext schedulerContext = null;
    try {
        log.debug("Executing quartz job");
        schedulerContext = context.getScheduler().getContext();
        initProperties(schedulerContext);

        WebResource.Builder resourceBuilder = getBuilder();
        ClientResponse response = getResponse(resourceBuilder);

        if (response != null) {
            String responseAsString = response.getEntity(String.class);
            final List<Event> events = restSourceHandler
                    .getEvents(responseAsString, responseToHeaders(response.getHeaders()));
            queue.addAll(events);
            urlHandler.updateFilterParameters(getLastEvent(events));
        }

    } catch (Exception e) {
        log.error("Error getting Response: " + e.getMessage());
    }
}
项目:Lottery    文件:IndexStaticJob.java   
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();
}
项目:Lottery    文件:ChannelStaticJob.java   
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();
}
项目:lams    文件:MonitoringJob.java   
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());
}
   }
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Returns the <code>SchedulerContext</code> of the <code>Scheduler</code>.
 * </p>
 */
public SchedulerContext getContext() throws SchedulerException {
    try {
        return getRemoteScheduler().getSchedulerContext();
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:asura    文件:RemoteScheduler.java   
/**
 * <p>
 * Returns the <code>SchedulerContext</code> of the <code>Scheduler</code>.
 * </p>
 */
public SchedulerContext getContext() throws SchedulerException {
    try {
        return getRemoteScheduler().getSchedulerContext();
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:niubi-job    文件:JobDataMapManager.java   
/**
 * 初始化自动的调度器数据
 *
 * @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);
    }
}
项目:niubi-job    文件:JobDataMapManager.java   
/**
 * 初始化手动的调度器数据
 *
 * @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);
    }
}
项目:spring4-understanding    文件:QuartzSupportTests.java   
@Test
public void schedulerFactoryBeanWithApplicationContext() throws Exception {
    TestBean tb = new TestBean("tb", 99);
    StaticApplicationContext ac = new StaticApplicationContext();

    final Scheduler scheduler = mock(Scheduler.class);
    SchedulerContext schedulerContext = new SchedulerContext();
    given(scheduler.getContext()).willReturn(schedulerContext);

    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean() {
        @Override
        protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String schedulerName) {
            return scheduler;
        }
    };
    schedulerFactoryBean.setJobFactory(null);
    Map<String, Object> schedulerContextMap = new HashMap<String, Object>();
    schedulerContextMap.put("testBean", tb);
    schedulerFactoryBean.setSchedulerContextAsMap(schedulerContextMap);
    schedulerFactoryBean.setApplicationContext(ac);
    schedulerFactoryBean.setApplicationContextSchedulerContextKey("appCtx");
    try {
        schedulerFactoryBean.afterPropertiesSet();
        schedulerFactoryBean.start();
        Scheduler returnedScheduler = schedulerFactoryBean.getObject();
        assertEquals(tb, returnedScheduler.getContext().get("testBean"));
        assertEquals(ac, returnedScheduler.getContext().get("appCtx"));
    }
    finally {
        schedulerFactoryBean.destroy();
    }

    verify(scheduler).start();
    verify(scheduler).shutdown(false);
}
项目:cachecloud    文件:InspectorJob.java   
@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);
    }
}
项目:cachecloud    文件:SystemConfigRefreshJob.java   
@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);
    }

}
项目:cachecloud    文件:MachineMonitorJob.java   
@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);
    }
}
项目:cachecloud    文件:ErrorStatisticsJob.java   
@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);
        }

    }
项目:cachecloud    文件:InstanceAlertValueJob.java   
@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);
    }

}
项目:cachecloud    文件:AppDailyJob.java   
@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);
    }

}
项目:Camel    文件:ScheduledJob.java   
private SchedulerContext getSchedulerContext(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    try {
        return jobExecutionContext.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + jobExecutionContext.getJobDetail().getKey());
    }
}
项目:Camel    文件:CamelJob.java   
protected CamelContext getCamelContext(JobExecutionContext context) throws JobExecutionException {
    SchedulerContext schedulerContext = getSchedulerContext(context);
    String camelContextName = context.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME);
    CamelContext result = (CamelContext)schedulerContext.get(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName);
    if (result == null) {
        throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
    }
    return result;
}
项目:Camel    文件:CamelJob.java   
protected SchedulerContext getSchedulerContext(JobExecutionContext context) throws JobExecutionException {
    try {
        return context.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + context.getJobDetail().getKey());
    }
}
项目:Camel    文件:QuartzComponent.java   
private void createAndInitScheduler() throws SchedulerException {
    LOG.info("Create and initializing scheduler.");
    scheduler = createScheduler();

    SchedulerContext quartzContext = storeCamelContextInQuartzContext();

    // Set camel job counts to zero. We needed this to prevent shutdown in case there are multiple Camel contexts
    // that has not completed yet, and the last one with job counts to zero will eventually shutdown.
    AtomicInteger number = (AtomicInteger) quartzContext.get(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT);
    if (number == null) {
        number = new AtomicInteger(0);
        quartzContext.put(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT, number);
    }
}
项目:Camel    文件:QuartzComponent.java   
private SchedulerContext storeCamelContextInQuartzContext() throws SchedulerException {
    // Store CamelContext into QuartzContext space
    SchedulerContext quartzContext = scheduler.getContext();
    String camelContextName = QuartzHelper.getQuartzContextName(getCamelContext());
    LOG.debug("Storing camelContextName={} into Quartz Context space.", camelContextName);
    quartzContext.put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName, getCamelContext());
    return quartzContext;
}
项目:nexus-public    文件:SchedulerTest.java   
@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());
  }
}
项目:jeecms6    文件:ContentStaticJob.java   
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();
}
项目:jeecms6    文件:AcquisiteJob.java   
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();
}
项目:cia    文件:AbstractJob.java   
/**
 * 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 {
            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;
}
项目:spring-integration-quartz-bridge    文件:ApplicationContextAwareQuartzJobBean.java   
protected ApplicationContext getApplicationContext(JobExecutionContext context) throws JobExecutionException {
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        return (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
    }
    catch (SchedulerException e) {
        throw new JobExecutionException(e);
    }
}
项目:quartz-scheduler-hazelcast-jobstore    文件:QuartzTest.java   
@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());
  }
}
项目:concourseconnect-community    文件:ReportsJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
  SchedulerContext schedulerContext = null;
  Connection db = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    ServletContext servletContext = (ServletContext) schedulerContext.get(
        "ServletContext");
    ApplicationPrefs prefs = (ApplicationPrefs) schedulerContext.get(
        "ApplicationPrefs");
    String fs = System.getProperty("file.separator");
    db = SchedulerUtils.getConnection(schedulerContext);
    LOG.debug("Checking reports...");
    // Process the unprocessed first...
    ReportQueueList queue = new ReportQueueList();
    queue.setSortAscending(true);
    queue.setUnprocessedOnly(true);
    queue.buildList(db);
    runReports(queue, db, schedulerContext, servletContext, prefs, fs);
    // Process the scheduled reports next...
    ReportQueueList scheduled = new ReportQueueList();
    scheduled.setSortAscending(true);
    scheduled.setScheduledTodayOnly(true);
    scheduled.buildList(db);
    runReports(scheduled, db, schedulerContext, servletContext, prefs, fs);
  } catch (Exception e) {
    throw new JobExecutionException(e.getMessage());
  } finally {
    SchedulerUtils.freeConnection(schedulerContext, db);
  }
}
项目:concourseconnect-community    文件:CleanupReportsJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
  SchedulerContext schedulerContext = null;
  Connection db = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    ServletContext servletContext = (ServletContext) schedulerContext.get(
        "ServletContext");
    ApplicationPrefs prefs = (ApplicationPrefs) schedulerContext.get(
        "ApplicationPrefs");
    String fs = System.getProperty("file.separator");
    db = SchedulerUtils.getConnection(schedulerContext);
    LOG.debug("Checking reports...");
    // Load the report queue for this site, processed only, whether successful or not
    ReportQueueList queue = new ReportQueueList();
    queue.setSortAscending(true);
    queue.setProcessedOnly(true);
    queue.setExpiredOnly(true);
    queue.buildList(db);
    // Iterate the list
    Iterator list = queue.iterator();
    while (list.hasNext()) {
      ReportQueue thisQueue = (ReportQueue) list.next();
      User user = UserUtils.loadUser(thisQueue.getEnteredBy());
      thisQueue.delete(
          db,
          prefs.get("FILELIBRARY") + user.getGroupId() + fs + "projects" + fs +
              DateUtils.getDatePath(thisQueue.getEntered()));
    }
  } catch (Exception e) {
    LOG.error("CleanupReportsJob Exception", e);
    throw new JobExecutionException(e.getMessage());
  } finally {
    SchedulerUtils.freeConnection(schedulerContext, db);
  }
}
项目:concourseconnect-community    文件:UpdateTranslationPercentageJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
  SchedulerContext schedulerContext = null;
  Connection db = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    db = SchedulerUtils.getConnection(schedulerContext);
    if (System.getProperty("DEBUG") != null) {
      System.out.println(
          "UpdateTranslationPercentageJob-> Updating translations...");
    }
    // Get a list of all language packs
    LanguagePackList packList = new LanguagePackList();
    packList.buildList(db);
    // For each one, build the statistics
    PreparedStatement pst = db.prepareStatement(
        "UPDATE language_pack " +
            "SET percent_complete = ? " +
            "WHERE id = ? ");
    Iterator i = packList.iterator();
    while (i.hasNext()) {
      LanguagePack thisPack = (LanguagePack) i.next();
      if (thisPack.getLanguageLocale() != LanguagePack.DEFAULT_LOCALE) {
        // Update the percent_complete field
        thisPack.buildStatistics(db);
        String percentComplete = thisPack.getPercentageComplete();
        pst.setInt(
            1, Integer.parseInt(
                percentComplete.substring(0, percentComplete.length() - 1)));
        pst.setInt(2, thisPack.getId());
        pst.executeUpdate();
      }
    }
    pst.close();
  } catch (Exception e) {
    throw new JobExecutionException(e.getMessage());
  } finally {
    SchedulerUtils.freeConnection(schedulerContext, db);
  }
}
项目:concourseconnect-community    文件:UserContributionJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
  LOG.debug("Starting job...");
  SchedulerContext schedulerContext = null;
  Connection db = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    ApplicationPrefs prefs = (ApplicationPrefs) schedulerContext.get(
        "ApplicationPrefs");
    db = SchedulerUtils.getConnection(schedulerContext);

    // Get the list of contribution criteria
    LookupContributionList lookupContributionList = new LookupContributionList();
    lookupContributionList.setEnabled(Constants.TRUE);
    lookupContributionList.buildList(db);

    HashMap<String, HashMap<Integer, Integer>> completeUserMap = new HashMap<String, HashMap<Integer, Integer>>();
    for (LookupContribution lookupContribution : lookupContributionList) {
      Object classRef = null;
      classRef = Class.forName(lookupContribution.getConstant()).newInstance();

      //passing lookup contribution as that could have rules to determine the points
      Method method = classRef.getClass().getMethod("process", new Class[]{Connection.class, LookupContribution.class});
      HashMap<Integer, Integer> userMap = (HashMap<Integer, Integer>) method.invoke(classRef, new Object[]{db, lookupContribution});
      completeUserMap.put(lookupContribution.getConstant(), userMap);
    }

  } catch (Exception e) {
    LOG.error("UserContributionJob Exception", e);
    throw new JobExecutionException(e.getMessage());
  } finally {
    SchedulerUtils.freeConnection(schedulerContext, db);
  }
}
项目:concourseconnect-community    文件:SchedulerUtils.java   
/**
 * Returns a database connection to the pool
 *
 * @param context Description of the Parameter
 * @param db      Description of the Parameter
 */
public static void freeConnection(SchedulerContext context, Connection db) {
  if (db != null) {
    ConnectionPool sqlDriver = (ConnectionPool) context.get(
        "ConnectionPool");
    sqlDriver.free(db);
  }
  db = null;
}
项目:thoth-monitor    文件:MonitorJob.java   
private void monitorThothPredictor(SchedulerContext schedulerContext){
  try {
    if (isPredictorMonitoringEnabled){
      predictorMonitorUrl = (String) schedulerContext.get("predictorMonitorUrl");
      predictorMonitorHealthScoreThreshold = (String) schedulerContext.get("predictorMonitorHealthScoreThreshold");

      if (!"".equals(predictorMonitorUrl) && !"".equals(predictorMonitorHealthScoreThreshold)){
        new PredictorModelHealthMonitor(predictorMonitorUrl, Float.parseFloat(predictorMonitorHealthScoreThreshold)).execute();
      }
    }
  } catch (Exception e){
    System.out.println("Error while trying to monitor thoth predictor, exception: " + e );
  }
}
项目:thoth-monitor    文件:MonitorJob.java   
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
  SchedulerContext schedulerContext = null;
  try {
    schedulerContext = context.getScheduler().getContext();
    realTimeThoth = new HttpSolrServer(schedulerContext.get("thothIndexURI") + realTimeThothCore);
    historicalDataThoth = new HttpSolrServer(schedulerContext.get("thothIndexURI") + shrankThothCore);
    serverCache = (ServerCache) schedulerContext.get("serverCache");
    ignoredServerDetails = (ArrayList<ServerDetail>) schedulerContext.get("ignoredServers");
    isPredictorMonitoringEnabled = (Boolean) schedulerContext.get("isPredictorMonitoringEnabled");
    availableMonitors = (AvailableMonitors) schedulerContext.get("availableMonitors");
    mailer = (Mailer) schedulerContext.get("mailer");
    //TODO remove?
    monitorThothPredictor(schedulerContext);

    // Get the list of servers to Monitor from Thoth
    List<ServerDetail> serversToMonitor = new ThothServers().getList(realTimeThoth);
    System.out.println("Fetching information about the servers done. Start the monitoring");
    for (ServerDetail serverDetail: serversToMonitor){
      if (isIgnored(serverDetail)) continue;  // Skip server if ignored
      System.out.println("Start monitoring server (" + serverDetail.getName()+") port(" + serverDetail.getPort()+") coreName("+ serverDetail.getCore()+ ")");
      executeMonitorsConcurrently(serverDetail);
    }

    if (serversToMonitor.size() == 0) System.out.println("No suitable thoth documents found for monitoring. Skipping...");
    System.out.println("Done with monitoring.");

    realTimeThoth.shutdown();
    historicalDataThoth.shutdown();

  } catch (Exception e){
    e.printStackTrace();
  }

}