Java 类org.quartz.Scheduler 实例源码

项目:MonitorPlatform    文件:JobConfigService.java   
/**
 * 所有正在运行的job
 * 
 * @return
 * @throws SchedulerException
 */
public List<ScheduleJob> getRunningJob() throws SchedulerException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs();
    List<ScheduleJob> jobList = new ArrayList<ScheduleJob>(executingJobs.size());
    for (JobExecutionContext executingJob : executingJobs) {
        ScheduleJob job = new ScheduleJob();
        JobDetail jobDetail = executingJob.getJobDetail();
        JobKey jobKey = jobDetail.getKey();
        Trigger trigger = executingJob.getTrigger();
        job.setName(jobKey.getName());
        job.setGroup(jobKey.getGroup());
        job.setDescription("触发器:" + trigger.getKey());
        Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
        job.setStatus(triggerState.name());
        if (trigger instanceof CronTrigger) {
            CronTrigger cronTrigger = (CronTrigger) trigger;
            String cronExpression = cronTrigger.getCronExpression();
            job.setCron(cronExpression);
        }
        jobList.add(job);
    }
    return jobList;
}
项目:MonitorPlatform    文件:JobConfigService.java   
/**
 * 获取所有计划中的任务列表
 * 
 * @return
 * @throws SchedulerException
 */
public List<ScheduleJob> getAllJob() throws SchedulerException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
    Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
    List<ScheduleJob> jobList = new ArrayList<ScheduleJob>();
    for (JobKey jobKey : jobKeys) {
        List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
        for (Trigger trigger : triggers) {
            ScheduleJob job = new ScheduleJob();
            job.setName(jobKey.getName());
            job.setGroup(jobKey.getGroup());
            job.setDescription("触发器:" + trigger.getKey());
            Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
            job.setStatus(triggerState.name());
            if (trigger instanceof CronTrigger) {
                CronTrigger cronTrigger = (CronTrigger) trigger;
                String cronExpression = cronTrigger.getCronExpression();
                job.setCron(cronExpression);
            }
            jobList.add(job);
        }
    }
    return jobList;
}
项目:lams    文件:ShutdownHookPlugin.java   
/**
 * <p>
 * Called during creation of the <code>Scheduler</code> in order to give
 * the <code>SchedulerPlugin</code> a chance to initialize.
 * </p>
 * 
 * @throws SchedulerConfigException
 *           if there is an error initializing.
 */
public void initialize(String name, final Scheduler scheduler, ClassLoadHelper classLoadHelper)
    throws SchedulerException {

    getLog().info("Registering Quartz shutdown hook.");

    Thread t = new Thread("Quartz Shutdown-Hook "
            + scheduler.getSchedulerName()) {
        @Override
        public void run() {
            getLog().info("Shutting down Quartz...");
            try {
                scheduler.shutdown(isCleanShutdown());
            } catch (SchedulerException e) {
                getLog().info(
                        "Error shutting down Quartz: " + e.getMessage(), e);
            }
        }
    };

    Runtime.getRuntime().addShutdownHook(t);
}
项目:springboot-quartz    文件:ScheduleJobService.java   
private void wrapScheduleJob(ScheduleJob scheduleJob,Scheduler scheduler,JobKey jobKey,Trigger trigger){  
    try {  
        scheduleJob.setJobName(jobKey.getName());  
        scheduleJob.setJobGroup(jobKey.getGroup()); 

        JobDetail jobDetail = scheduler.getJobDetail(jobKey);  
        ScheduleJob job = (ScheduleJob)jobDetail.getJobDataMap().get("scheduleJob");  
        scheduleJob.setDesc(job.getDesc());  
        scheduleJob.setJobId(job.getJobId());

        Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());  
        scheduleJob.setJobStatus(triggerState.name());  
        if(trigger instanceof CronTrigger){  
            CronTrigger cronTrigger = (CronTrigger)trigger;  
            String cronExpression = cronTrigger.getCronExpression();  
            scheduleJob.setCronExpression(cronExpression);  
        }  
    } catch (SchedulerException e) {  
        e.printStackTrace(); 
    }  
}
项目:lams    文件:QuartzService.java   
@Override
public void stopService() throws Exception {
    log.info("Stop QuartzService(" + jndiName + ")...");

    try {
        Scheduler scheduler = schedulerFactory.getScheduler();

        scheduler.shutdown();
    } catch (Exception e) {
        log.error("Failed to shutdown Scheduler", e);

        throw new SchedulerConfigException(
                "Failed to shutdown Scheduler - ", e);
    }

    unbind(jndiName);

    log.info("QuartzService(" + jndiName + ") stopped.");
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Store and schedule the identified <code>{@link org.quartz.spi.OperableTrigger}</code>
 * </p>
 */
public void triggerJob(OperableTrigger trig) throws SchedulerException {
    validateState();

    trig.computeFirstFireTime(null);

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
 * now) - with a non-volatile trigger.
 * </p>
 */
@SuppressWarnings("deprecation")
public void triggerJob(JobKey jobKey, JobDataMap data) throws SchedulerException {
    validateState();

    OperableTrigger trig = (OperableTrigger) newTrigger().withIdentity(newTriggerId(), Scheduler.DEFAULT_GROUP).forJob(jobKey).build();
    trig.computeFirstFireTime(null);
    if(data != null) {
        trig.setJobDataMap(data);
    }

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
项目:bdf2    文件:DaemonDetectionJob.java   
public void execute(JobExecutionContext context) throws JobExecutionException {
    DetectionJobDetail jobDetail=(DetectionJobDetail)context.getJobDetail();
    try {
        ISchedulerService service=jobDetail.getSchedulerService();
        if(!service.isRunJobInCurrentInstance()){
            log.warn("Current instance not allowed run scheduler!");
            return;
        }
        Scheduler scheduler=service.getCurrentScheduler();
        if(scheduler==null || scheduler.isShutdown()){
            System.out.println("Current instance scheduler was shutdown,start reset...");
            service.resetScheduer();
            System.out.println("Reset successful...");
        }
    } catch (Exception e) {
        throw new JobExecutionException(e);
    }
}
项目:webside    文件:ScheduleJobServiceImpl.java   
/**
 * 封装ScheduleJob对象
 * 
 * @param scheduleJob
 * @param scheduler
 * @param jobKey
 * @param trigger
 */
private void wrapScheduleJob(ScheduleJobEntity scheduleJob,
        Scheduler scheduler, JobKey jobKey, Trigger trigger) {
    try {
        scheduleJob.setJobName(jobKey.getName());
        scheduleJob.setJobGroup(jobKey.getGroup());

        JobDetail jobDetail = scheduler.getJobDetail(jobKey);
        scheduleJob.setJobClass(jobDetail.getJobClass());
        scheduleJob.setJobDesc(jobDetail.getDescription());

        Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
        scheduleJob.setTriggerStatus(triggerState.name());

        if (trigger instanceof CronTrigger) {
            CronTrigger cronTrigger = (CronTrigger) trigger;
            TriggerKey triggerKey = cronTrigger.getKey();
            scheduleJob.setTriggerName(triggerKey.getName());
            scheduleJob.setTriggerGroup(triggerKey.getGroup());
            scheduleJob.setNextFireTime(cronTrigger.getNextFireTime());
            scheduleJob.setCronExpression(cronTrigger.getCronExpression());
            scheduleJob.setStartDate(cronTrigger.getStartTime());
            scheduleJob.setEndDate(cronTrigger.getEndTime());
        }
    } catch (SchedulerException e) {
        logger.error("获取触发器状态失败", e);
        throw new ServiceException(e);
    }
}
项目:nh-micro    文件:MicroQuartzManager.java   
/** 
 * @Description 移除一个任务(使用默认的任务组名,触发器名,触发器组名) 
 * @param jobName 
 *  
 *  
 */  
public static void removeJob(String jobName) {   
    TriggerKey triggerKey = TriggerKey.triggerKey(  
            jobName, TRIGGER_GROUP_NAME);  
    JobKey jobKey = JobKey.jobKey(jobName, JOB_GROUP_NAME);  
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();  
        Trigger trigger = (Trigger) sched.getTrigger(triggerKey);    
        if (trigger == null) {    
            return;    
        }  
        sched.pauseTrigger(triggerKey);;// 停止触发器    
        sched.unscheduleJob(triggerKey);// 移除触发器    
        sched.deleteJob(jobKey);// 删除任务    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
项目:asura    文件:ShutdownHookPlugin.java   
/**
 * <p>
 * Called during creation of the <code>Scheduler</code> in order to give
 * the <code>SchedulerPlugin</code> a chance to initialize.
 * </p>
 * 
 * @throws SchedulerConfigException
 *           if there is an error initializing.
 */
public void initialize(String name, final Scheduler scheduler)
    throws SchedulerException {
    this.name = name;
    this.scheduler = scheduler;

    getLog().info("Registering Quartz shutdown hook.");

    Thread t = new Thread("Quartz Shutdown-Hook "
            + scheduler.getSchedulerName()) {
        public void run() {
            getLog().info("Shutting down Quartz...");
            try {
                scheduler.shutdown(isCleanShutdown());
            } catch (SchedulerException e) {
                getLog().info(
                        "Error shutting down Quartz: " + e.getMessage(), e);
            }
        }
    };

    Runtime.getRuntime().addShutdownHook(t);
}
项目:asura    文件:QuartzScheduler.java   
/**
 * <p>
 * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
 * now) - with a volatile trigger.
 * </p>
 */
public void triggerJobWithVolatileTrigger(SchedulingContext ctxt,
        String jobName, String groupName, JobDataMap data) throws SchedulerException {
    validateState();

    if(groupName == null) {
        groupName = Scheduler.DEFAULT_GROUP;
    }

    Trigger trig = new org.quartz.SimpleTrigger(newTriggerId(),
            Scheduler.DEFAULT_MANUAL_TRIGGERS, jobName, groupName,
            new Date(), null, 0, 0);
    trig.setVolatility(true);
    trig.computeFirstFireTime(null);
    if(data != null) {
        trig.setJobDataMap(data);
    }

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(ctxt, trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setName(newTriggerId());
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
项目:spring-boot-quartz-demo    文件:JobServiceImpl.java   
/**
 * Check job exist with given name
 */
@Override
public boolean isJobWithNamePresent(String jobName) {
    try {
        String groupKey = "SampleGroup";
        JobKey jobKey = new JobKey(jobName, groupKey);
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        if (scheduler.checkExists(jobKey)){
            return true;
        }
    } catch (SchedulerException e) {
        System.out.println("SchedulerException while checking job with name and group exist:"+e.getMessage());
        e.printStackTrace();
    }
    return false;
}
项目:asura    文件:XMLSchedulingDataProcessor.java   
/**
 * Process the xmlfile named <code>fileName</code> with the given system
 * ID.
 * 
 * @param stream
 *          an input stream containing the xml content.
 * @param systemId
 *          system ID.
 */
public void processStreamAndScheduleJobs(InputStream stream, String systemId, Scheduler sched)
    throws ValidationException, ParserConfigurationException,
        SAXException, XPathException, IOException, SchedulerException,
        ClassNotFoundException, ParseException {

    prepForProcessing();

    log.info("Parsing XML from stream with systemId: " + systemId);

    InputSource is = new InputSource(stream);
    is.setSystemId(systemId);

    process(is);
    executePreProcessCommands(sched);
    scheduleJobs(sched);

    maybeThrowValidationException();
}
项目:springboot-shiro-cas-mybatis    文件:AutowiringSchedulerFactoryBeanTests.java   
@Before
public void setUp() throws Exception {
    context = new ClassPathXmlApplicationContext(
    "core-context.xml",
    "applicationContext.xml");

    this.scheduler = (Scheduler) context.getBean("autowiringSchedulerFactoryBean");
    this.scheduler.start();

}
项目:nh-micro    文件:MicroQuartzManager.java   
/** 
 * @Description 关闭所有定时任务  
 *   
 *  
 */  
public static void shutdownJobs() {    
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();    
        if (!sched.isShutdown()) {    
            sched.shutdown();    
        }    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
项目:lams    文件:JobDetailImpl.java   
/**
 * <p>
 * Set the group of this <code>Job</code>.
 * </p>
 * 
 * @param group if <code>null</code>, Scheduler.DEFAULT_GROUP will be used.
 * 
 * @exception IllegalArgumentException
 *              if the group is an empty string.
 */
public void setGroup(String group) {
    if (group != null && group.trim().length() == 0) {
        throw new IllegalArgumentException(
                "Group name cannot be empty.");
    }

    if (group == null) {
        group = Scheduler.DEFAULT_GROUP;
    }

    this.group = group;
    this.key = null;
}
项目:renren-msg    文件:ScheduleUtils.java   
/**
 * 恢复任务
 */
public static void resumeJob(Scheduler scheduler, Long jobId) {
    try {
        scheduler.resumeJob(getJobKey(jobId));
    } catch (SchedulerException e) {
        throw new RRException("暂停定时任务失败", e);
    }
}
项目:flow-platform    文件:SchedulerConfig.java   
/**
 * Setup quartz scheduler
 */
@Bean
public Scheduler quartzScheduler() {
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(new ClassPathResource("quartz.properties").getInputStream());
        return factory.getScheduler();
    } catch (SchedulerException | IOException e) {
        throw new IllegalStatusException("Unable to init quartz: " + e.getMessage());
    }
}
项目:lams    文件:QuartzService.java   
@Override
public void startService() throws Exception {
    log.info("Start QuartzService(" + jndiName + ")...");

    try {
        rebind();
    } catch (NamingException ne) {
        log.error("Failed to rebind Scheduler", ne);

        throw new SchedulerConfigException("Failed to rebind Scheduler - ",
                ne);
    }

    try {
        Scheduler scheduler = schedulerFactory.getScheduler();

        if (startScheduler) {
            scheduler.start();
        } else {
            log.info("Skipping starting the scheduler (will not run jobs).");
        }
    } catch (Exception e) {
        log.error("Failed to start Scheduler", e);

        throw new SchedulerConfigException("Failed to start Scheduler - ",
                e);
    }

    log.info("QuartzService(" + jndiName + ") started.");
}
项目:quartz-web    文件:QuartzManager.java   
/**
 * 获取全部trigger
 * @return
 * @throws SchedulerException
 */
public List<? extends Trigger> getAllTriggers() throws SchedulerException {
    List<Trigger> triggers = new ArrayList<Trigger>();
    List<Scheduler> schedulers = this.getSchedulers();
    for (Scheduler scheduler : schedulers) {
        List<JobDetail> jobDetails = getAllJobsOfScheduler(scheduler.getSchedulerName());
        List<Trigger> triggersOfScheduler = new ArrayList<Trigger>();
        for (JobDetail jobDetail : jobDetails) {
            List<? extends Trigger> triggersOfJob = QuartzUtils.getTriggersOfJob(jobDetail, scheduler);
            triggersOfScheduler.addAll(triggersOfJob);
        }
        triggers.addAll(triggersOfScheduler);
    }
    return triggers;
}
项目:quartz-web    文件:QuartzManager.java   
/**
 * 启动全部
 * @throws SchedulerException
 */
public void schedulerStart() throws SchedulerException {
    List<Scheduler> schedulers = this.getSchedulers();
    for (Scheduler scheduler : schedulers) {
        scheduler.start();
    }
}
项目:lams    文件:PropertySettingJobFactory.java   
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {

    Job job = super.newJob(bundle, scheduler);

    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.putAll(scheduler.getContext());
    jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
    jobDataMap.putAll(bundle.getTrigger().getJobDataMap());

    setBeanProps(job, jobDataMap);

    return job;
}
项目:quartz-web    文件:QuartzManager.java   
public void pauseJob(String schedulerName, String jobName, String jobGroup) throws SchedulerException {
    Assert.notEmpty(jobName, "jobName can not be empty");
    Assert.notEmpty(jobGroup, "jobGroup can not be empty");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    if (!existJob(schedulerName, jobName, jobGroup)) {
        throw new IllegalArgumentException("job [" + jobName + ":" + jobGroup + "] not exist");
    }
    QuartzUtils.pauseJob(jobName, jobGroup, scheduler);

}
项目:quartz-web    文件:QuartzManager.java   
public void resumeJob(String schedulerName, String jobName, String jobGroup) throws SchedulerException {
    Assert.notEmpty(jobName, "jobName can not be empty");
    Assert.notEmpty(jobGroup, "jobGroup can not be empty");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    if (!existJob(schedulerName, jobName, jobGroup)) {
        throw new IllegalArgumentException("job [" + jobName + ":" + jobGroup + "] not exist");
    }
    QuartzUtils.resumeJob(jobName, jobGroup, scheduler);
}
项目:renren-msg    文件:ScheduleUtils.java   
/**
 * 删除定时任务
 */
public static void deleteScheduleJob(Scheduler scheduler, Long jobId) {
    try {
        scheduler.deleteJob(getJobKey(jobId));
    } catch (SchedulerException e) {
        throw new RRException("删除定时任务失败", e);
    }
}
项目:lams    文件:EmailProgressAction.java   
/**
    * Gets learners or monitors of the lesson and organisation containing it.
    * 
    * @throws SchedulerException
    */
   public ActionForward getEmailProgressDates(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException, JSONException, SchedulerException {
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "get class members", false)) {
    response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson");
    return null;
}

HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);

JSONObject responseJSON = new JSONObject();
JSONArray datesJSON = new JSONArray();

// find all the current dates set up to send the emails
Scheduler scheduler = getScheduler();
String triggerPrefix = getTriggerPrefix(lessonId);
SortedSet<Date> currentDatesSet = new TreeSet<Date>();
Set<TriggerKey> triggerKeys = scheduler
    .getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
    String triggerName = triggerKey.getName();
    if (triggerName.startsWith(triggerPrefix)) {
    Trigger trigger = scheduler.getTrigger(triggerKey);
    JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
    JobDataMap jobDataMap = jobDetail.getJobDataMap();

    // get only the trigger for the current lesson

    Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
    if (lessonId.equals(jobLessonId)) {

        Date triggerDate = trigger.getNextFireTime();
        currentDatesSet.add(triggerDate);
    }
    }
}

for (Date date : currentDatesSet) {
    datesJSON.put(createDateJSON(request.getLocale(), user, date, null));
}
responseJSON.put("dates", datesJSON);

response.setContentType("application/json;charset=utf-8");
response.getWriter().write(responseJSON.toString());
return null;
   }
项目:quartz-web    文件:QuartzManager.java   
public void resumeTrigger(String schedulerName, String triggerName, String triggerGroup) throws SchedulerException {
    Assert.notEmpty(triggerName, "triggerName can not be empty");
    Assert.notEmpty(triggerGroup, "triggerGroup can not be empty");
    if (!existTrigger(schedulerName, triggerName, triggerGroup)) {
        throw new IllegalArgumentException("trigger [" + triggerName + ":" + triggerGroup + "] not exist");
    }
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    QuartzUtils.resumeTrigger(triggerName, triggerGroup, scheduler);
}
项目:alfresco-repository    文件:CronScheduledQueryBasedTemplateActionDefinitionTest.java   
/**
 * Initializes target {@link CronScheduledQueryBasedTemplateActionDefinition} instance for testing. <b>Default query template is not set!</b> It must be set in test method. No
 * need to register for every test for scheduling. Hence, {@link CronScheduledQueryBasedTemplateActionDefinition#afterPropertiesSet()} is omitted here and must be invoked for
 * test which requires scheduling
 */
private void initializeScheduler()
{
    Scheduler factory = (Scheduler) applicationContext.getBean(SCHEDULER_FACTORY_BEAN_NAME);

    FreeMarkerWithLuceneExtensionsModelFactory templateActionModelFactory = new FreeMarkerWithLuceneExtensionsModelFactory();
    templateActionModelFactory.setServiceRegistry(registry);

    SimpleTemplateActionDefinition templateActionDefinition = new SimpleTemplateActionDefinition();
    templateActionDefinition.setApplicationContext(applicationContext);
    templateActionDefinition.setActionService(registry.getActionService());
    templateActionDefinition.setTemplateService(registry.getTemplateService());
    templateActionDefinition.setDictionaryService(registry.getDictionaryService());
    templateActionDefinition.setTemplateActionModelFactory(templateActionModelFactory);

    templateActionDefinition.setActionName(SCRIPT_TEST_ACTION_NAME);

    scheduler = new CronScheduledQueryBasedTemplateActionDefinition();
    scheduler.setScheduler(factory);
    scheduler.setTransactionService(registry.getTransactionService());
    scheduler.setActionService(registry.getActionService());
    scheduler.setSearchService(registry.getSearchService());
    scheduler.setTemplateService(registry.getTemplateService());
    scheduler.setRunAsUser(AuthenticationUtil.getSystemUserName());
    scheduler.setTemplateActionDefinition(templateActionDefinition);
    scheduler.setTemplateActionModelFactory(templateActionModelFactory);
    scheduler.setStores(Collections.singletonList(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString()));

    scheduler.setQueryLanguage(SCHEDULER_QUERY_LANGUAGE);
    scheduler.setCronExpression(SCHEDULER_CRON_EXPRESSION);
    scheduler.setCompensatingActionMode(SCHEDULER_COMPENSATING_ACTION_MODE);
    scheduler.setTransactionMode(SCHEDULER_TRANSACTION_MODE);
    scheduler.setJobName(SCHEDULER_JOB_NAME);
    scheduler.setJobGroup(SCHEDULER_JOB_GROUP);
    scheduler.setTriggerName(SCHEDULER_TRIGGER_NAME);
    scheduler.setTriggerGroup(SCHEDULER_TRIGGER_GROUP);
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the
 * matching groups - by pausing all of their <code>Trigger</code>s.
 * </p>
 *  
 */
public void pauseJobs(GroupMatcher<JobKey> groupMatcher)
    throws SchedulerException {
    validateState();

    if(groupMatcher == null) {
        groupMatcher = GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP);
    }

    Collection<String> pausedGroups = resources.getJobStore().pauseJobs(groupMatcher);
    notifySchedulerThread(0L);
    for (String pausedGroup : pausedGroups) {
        notifySchedulerListenersPausedJobs(pausedGroup);
    }
}
项目:taboola-cronyx    文件:QuartzSchedulerServiceImpl.java   
public QuartzSchedulerServiceImpl(Scheduler scheduler, JobsService jobsService, CronyxToQuartzSelector cronyxToQuartzSelector, QuartzToCronyxSelector quartzToCronyxSelector, AfterDAO afterDAO, NameAndGroupGraphValidator graphValidator) {
    this.scheduler = scheduler;
    this.jobsService = jobsService;
    this.cronyxToQuartzSelector = cronyxToQuartzSelector;
    this.quartzToCronyxSelector = quartzToCronyxSelector;
    this.afterDAO = afterDAO;
    this.graphValidator = graphValidator;
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@Override
public List<ScheduleJobEntity> getPlanJobList() {
    List<ScheduleJobEntity> jobList = new ArrayList<>();
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    try {
        GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup();
        Set<JobKey> jobKeySet = scheduler.getJobKeys(matcher);
        for (JobKey jobKey : jobKeySet) {
            /*
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for (Trigger trigger : triggers) {
                ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
                this.wrapScheduleJob(scheduleJob, scheduler, jobKey, trigger);
                jobList.add(scheduleJob);
            }
            */
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            ScheduleJobEntity scheduleJob = new ScheduleJobEntity();
            scheduleJob.setJobName(jobKey.getName());
            scheduleJob.setJobGroup(jobKey.getGroup());
            scheduleJob.setJobClassName(jobDetail.getJobClass().getName());
            scheduleJob.setJobDesc(jobDetail.getDescription());
            jobList.add(scheduleJob);
        }
    } catch (SchedulerException e) {
        logger.error("获取计划任务列表失败", e);
        throw new ServiceException("获取计划任务列表失败", e);
    }
    return jobList;
}
项目:webside    文件:ScheduleJobServiceImpl.java   
@Transactional
@Override
public boolean deleteJobTrigger(TriggerKey triggerKey) {
    try {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        return scheduler.unscheduleJob(triggerKey);
    } catch (SchedulerException e) {
        throw new ServiceException(e);
    }
}
项目:asura    文件:QuartzScheduler.java   
/**
 * <p>
 * Get the <code>{@link Trigger}</code> instance with the given name and
 * group.
 * </p>
 */
public Trigger getTrigger(SchedulingContext ctxt, String triggerName,
        String triggerGroup) throws SchedulerException {
    validateState();

    if(triggerGroup == null) {
        triggerGroup = Scheduler.DEFAULT_GROUP;
    }

    return resources.getJobStore().retrieveTrigger(ctxt, triggerName,
            triggerGroup);
}
项目:lams    文件:DefaultClusteredJobStore.java   
private void scheduleRecoveryIfNeeded(TriggerWrapper tw, FiredTrigger recovering) {
  JobWrapper jobWrapper = jobFacade.get(tw.getJobKey());

  if (jobWrapper == null) {
    getLog().error("No job found for orphaned trigger: " + tw);
    return;
  }

  if (jobWrapper.requestsRecovery()) {
    OperableTrigger recoveryTrigger = createRecoveryTrigger(tw, jobWrapper, "recover_" + terracottaClientId + "_"
                                                                        + ftrCtr++, recovering);

    JobDataMap jd = tw.getTriggerClone().getJobDataMap();
    jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_NAME, tw.getKey().getName());
    jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_GROUP, tw.getKey().getGroup());
    jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_FIRETIME_IN_MILLISECONDS, String.valueOf(recovering.getFireTime()));
    jd.put(Scheduler.FAILED_JOB_ORIGINAL_TRIGGER_SCHEDULED_FIRETIME_IN_MILLISECONDS, String.valueOf(recovering.getScheduledFireTime()));

    recoveryTrigger.setJobDataMap(jd);
    recoveryTrigger.computeFirstFireTime(null);

    try {
      storeTrigger(recoveryTrigger, false);
      if (!tw.mayFireAgain()) {
        removeTrigger(tw.getKey());
      }
      getLog().info("Recovered job " + jobWrapper + " for trigger " + tw);
    } catch (JobPersistenceException e) {
      getLog().error("Can't recover job " + jobWrapper + " for trigger " + tw, e);
    }
  }
}
项目:lams    文件:DefaultClusteredJobStore.java   
protected OperableTrigger createRecoveryTrigger(TriggerWrapper tw, JobWrapper jw,
                                                String name, FiredTrigger recovering) {
  final SimpleTriggerImpl recoveryTrigger = new SimpleTriggerImpl(name, Scheduler.DEFAULT_RECOVERY_GROUP, new Date(recovering.getScheduledFireTime()));
  recoveryTrigger.setJobName(jw.getKey().getName());
  recoveryTrigger.setJobGroup(jw.getKey().getGroup());
  recoveryTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY);
  recoveryTrigger.setPriority(tw.getPriority());
  return recoveryTrigger;
}
项目:asura    文件:QuartzScheduler.java   
/**
 * <p>
 * Get all <code>{@link Trigger}</code> s that are associated with the
 * identified <code>{@link org.quartz.JobDetail}</code>.
 * </p>
 */
public Trigger[] getTriggersOfJob(SchedulingContext ctxt, String jobName,
        String groupName) throws SchedulerException {
    validateState();

    if(groupName == null) {
        groupName = Scheduler.DEFAULT_GROUP;
    }

    return resources.getJobStore().getTriggersForJob(ctxt, jobName,
            groupName);
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Resume (un-pause) all of the <code>{@link Trigger}s</code> in the
 * matching groups.
 * </p>
 * 
 * <p>
 * If any <code>Trigger</code> missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 *  
 */
public void resumeTriggers(GroupMatcher<TriggerKey> matcher)
    throws SchedulerException {
    validateState();

    if(matcher == null) {
        matcher = GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP);
    }

    Collection<String> pausedGroups = resources.getJobStore().resumeTriggers(matcher);
    notifySchedulerThread(0L);
    for (String pausedGroup : pausedGroups) {
        notifySchedulerListenersResumedTriggers(pausedGroup);
    }
}
项目:Limitart    文件:SchedulerUtil.java   
/**
 * 是否有这个任务
 * 
 * @param name
 * @return
 * @throws SchedulerException
 */
public boolean hasSchedule(String name) throws SchedulerException {
    Scheduler scheduler = SF.getScheduler();
    if (scheduler == null) {
        return false;
    }
    return scheduler.checkExists(new JobKey(name, Scheduler.DEFAULT_GROUP));
}
项目:MonitorPlatform    文件:JobConfigService.java   
/**
 * 删除一个job
 * 
 * @param scheduleJob
 * @throws SchedulerException
 */
public void deleteJob(ScheduleJob scheduleJob) throws SchedulerException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    JobKey jobKey = JobKey.jobKey(scheduleJob.getName(), scheduleJob.getGroup());
    scheduler.deleteJob(jobKey);

}