org.quartz.Scheduler.getTrigger()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.quartz.Scheduler.getTrigger()方法的一些代码示例,展示了Scheduler.getTrigger()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.getTrigger()方法的具体详情如下:
包路径:org.quartz.Scheduler
类名称:Scheduler
方法名:getTrigger

Scheduler.getTrigger介绍

[英]Get the Trigger instance with the given name and group.
[中]获取具有给定名称和组的Trigger实例。

代码示例

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

/**
 * 获取表达式触发器
 */
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) {
  try {
    return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
  } catch (SchedulerException e) {
    log.error("获取Cron表达式失败", e);
  }
  return null;
}

代码示例来源:origin: xuxueli/xxl-job

/**
 * fill job info
 *
 * @param jobInfo
 */
public static void fillJobInfo(XxlJobInfo jobInfo) {
  String group = String.valueOf(jobInfo.getJobGroup());
  String name = String.valueOf(jobInfo.getId());
  // trigger key
  TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
  try {
    // trigger cron
    Trigger trigger = scheduler.getTrigger(triggerKey);
    if (trigger!=null && trigger instanceof CronTriggerImpl) {
      String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
      jobInfo.setJobCron(cronExpression);
    }
    // trigger state
    TriggerState triggerState = scheduler.getTriggerState(triggerKey);
    if (triggerState!=null) {
      jobInfo.setJobStatus(triggerState.name());
    }
    //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
    //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
    //String jobClass = jobDetail.getJobClass().getName();
    
  } catch (SchedulerException e) {
    logger.error(e.getMessage(), e);
  }
}

代码示例来源:origin: quartz-scheduler/quartz

Trigger dupeT = sched.getTrigger(trigger.getKey());
    if (dupeT != null) {
      if (isOverWriteExistingData()) {
Trigger dupeT = sched.getTrigger(trigger.getKey());
if (dupeT != null) {
  if(isOverWriteExistingData()) {

代码示例来源:origin: xuxueli/xxl-job

CronTrigger oldTrigger = (CronTrigger) scheduler.getTrigger(triggerKey);

代码示例来源:origin: quartz-scheduler/quartz

Trigger dupeT = sched.getTrigger(trigger.getKey());
    if (dupeT != null) {
      if (isOverWriteExistingData()) {
Trigger dupeT = sched.getTrigger(trigger.getKey());
if (dupeT != null) {
  if(isOverWriteExistingData()) {

代码示例来源:origin: spring-projects/spring-framework

boolean triggerExists = (getScheduler().getTrigger(trigger.getKey()) != null);
if (triggerExists && !this.overwriteExistingJobs) {
  return false;

代码示例来源:origin: elasticjob/elastic-job-lite

/**
 * 重新调度作业.
 * 
 * @param cron CRON表达式
 */
public synchronized void rescheduleJob(final String cron) {
  try {
    CronTrigger trigger = (CronTrigger) scheduler.getTrigger(TriggerKey.triggerKey(triggerIdentity));
    if (!scheduler.isShutdown() && null != trigger && !cron.equals(trigger.getCronExpression())) {
      scheduler.rescheduleJob(TriggerKey.triggerKey(triggerIdentity), createTrigger(cron));
    }
  } catch (final SchedulerException ex) {
    throw new JobSystemException(ex);
  }
}

代码示例来源:origin: org.springframework/spring-context-support

boolean triggerExists = (getScheduler().getTrigger(trigger.getKey()) != null);
if (triggerExists && !this.overwriteExistingJobs) {
  return false;

代码示例来源:origin: Dreampie/Resty

/**
 * 暂停任务
 */
public void pause() {
 long id = quartzKey.getId();
 String name = quartzKey.getName();
 String group = quartzKey.getGroup();
 SchedulerFactory factory = Quartzer.getSchedulerFactory();
 try {
  if (factory != null) {
   Scheduler scheduler = factory.getScheduler();
   TriggerKey triggerKey = TriggerKey.triggerKey(TRIGGER_MARK + SEPARATOR + name + SEPARATOR + id, GROUP_MARK + SEPARATOR + group + SEPARATOR + id);
   Trigger trigger = scheduler.getTrigger(triggerKey);
   if (trigger != null) {
    scheduler.pauseTrigger(triggerKey);
   }
  }
 } catch (Exception e) {
  throw new QuartzException("Can't pause job.", e);
 }
}

代码示例来源:origin: Dreampie/Resty

/**
 * 恢复任务
 */
public void resume() {
 long id = quartzKey.getId();
 String name = quartzKey.getName();
 String group = quartzKey.getGroup();
 SchedulerFactory factory = Quartzer.getSchedulerFactory();
 try {
  if (factory != null) {
   Scheduler scheduler = factory.getScheduler();
   TriggerKey triggerKey = TriggerKey.triggerKey(TRIGGER_MARK + SEPARATOR + name + SEPARATOR + id, GROUP_MARK + SEPARATOR + group + SEPARATOR + id);
   Trigger trigger = scheduler.getTrigger(triggerKey);
   if (trigger != null) {
    scheduler.resumeJob(trigger.getJobKey());
   }
  }
 } catch (Exception e) {
  throw new QuartzException("Can't resume job.", e);
 }
}

代码示例来源:origin: apache/incubator-gobblin

QuartzJobSchedule qjss1 = (QuartzJobSchedule)jss1;
Assert.assertNotNull(scheduler._scheduler.getScheduler().getJobDetail(qjss1.getQuartzTrigger().getJobKey()));
Assert.assertNotNull(scheduler._scheduler.getScheduler().getTrigger(qjss1.getQuartzTrigger().getKey()));
Assert.assertTrue(qjss1.getQuartzTrigger().mayFireAgain());

代码示例来源:origin: Dreampie/Resty

/**
 * 停止任务
 */
public void stop() {
 long id = quartzKey.getId();
 String name = quartzKey.getName();
 String group = quartzKey.getGroup();
 SchedulerFactory factory = Quartzer.getSchedulerFactory();
 try {
  if (factory != null) {
   Scheduler scheduler = factory.getScheduler();
   TriggerKey triggerKey = TriggerKey.triggerKey(TRIGGER_MARK + SEPARATOR + name + SEPARATOR + id, GROUP_MARK + SEPARATOR + group + SEPARATOR + id);
   Trigger trigger = scheduler.getTrigger(triggerKey);
   if (trigger != null) {
    scheduler.pauseTrigger(triggerKey);
    scheduler.unscheduleJob(triggerKey);
    scheduler.deleteJob(trigger.getJobKey());
    Quartzer.removeQuartzJob(this);
   }
  }
 } catch (Exception e) {
  throw new QuartzException("Can't stop job.", e);
 }
}

代码示例来源:origin: bill1012/AdminEAP

/**
 * 新增单个任务 Cron
 */
public void scheduleCronNewJob(ScheduleJob scheduleJob) throws SchedulerException, ClassNotFoundException {
  Scheduler scheduler = schedulerFactoryBean.getScheduler();
  TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
  // 获取trigger,即在spring配置文件中定义的bean id="myTrigger"
  CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
  // 不存在,创建一个
  JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(scheduleJob.getJobClass()))
      .withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withDescription(
          scheduleJob.getDesc()).build();
  // 表达式调度构建器
  CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
  // 按新的cronExpression表达式构建一个新的trigger
  trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
  scheduler.scheduleJob(jobDetail, trigger);
}

代码示例来源:origin: bill1012/AdminEAP

/**
 * 更新时间表达式
 */
public void rescheduleJob(ScheduleJob scheduleJob) throws SchedulerException {
  Scheduler scheduler = schedulerFactoryBean.getScheduler();
  TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
  // 获取trigger
  CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
  // 表达式调度构建器
  CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
  // 按新的cronExpression表达式重新构建trigger
  trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
  // 按照新的trigger重新设置job执行
  scheduler.rescheduleJob(triggerKey, trigger);
}

代码示例来源:origin: bill1012/AdminEAP

public void scheduleCronJobs() throws SchedulerException {
  Scheduler scheduler = schedulerFactoryBean.getScheduler();
  List<ScheduleJob> jobList = getAllJobs(null, null);
  for (ScheduleJob job : jobList) {
    TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobName(), job.getJobGroup());
    // 获取trigger,即在spring配置文件中定义的bean id="myTrigger"
    CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
    // 不存在,创建一个
    // if (null == trigger) {
    if (!scheduler.checkExists(triggerKey)) {
      JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class).withIdentity(job.getJobName(),
          job.getJobGroup()).build();
      // 表达式调度构建器
      CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
      // 按新的cronExpression表达式构建一个新的trigger
      trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
      scheduler.scheduleJob(jobDetail, trigger);
    } else {
      // trigger已经存在,那么更细相应的定时设置
      // 表达式调度构建器
      CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
      // 按新的cronExpression表达式重新构建trigger
      trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
      // 按新的trigger重新设置job执行
      scheduler.rescheduleJob(triggerKey, trigger);
    }
  }
}

代码示例来源:origin: sanluan/PublicCMS

TriggerKey triggerKey = TriggerKey.triggerKey(taskName);
try {
  CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
  CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
      .cronSchedule(site.getId() % 60 + CommonConstants.BLANK_SPACE + cronExpression);

代码示例来源:origin: sanluan/PublicCMS

TriggerKey triggerKey = TriggerKey.triggerKey(taskName);
try {
  CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
  CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
      .cronSchedule(site.getId() % 60 + CommonConstants.BLANK_SPACE + cronExpression);

代码示例来源:origin: bill1012/AdminEAP

CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);

代码示例来源:origin: bill1012/AdminEAP

/**
 * 调度单个任务 SimpleTrigger 和 CronTrigger
 */
public void scheduleSingleJob(ScheduleJob job) throws SchedulerException, ClassNotFoundException {
  Scheduler scheduler = schedulerFactoryBean.getScheduler();
  // List<ScheduleJob> jobList = getAllJobs();
  TriggerKey triggerKey = TriggerKey.triggerKey(job.getTriggerName(), job.getTriggerGroup());
  // 获取trigger
  Trigger trigger = scheduler.getTrigger(triggerKey);
  // 不存在,创建一个
  // if (null == trigger) {
  if (!scheduler.checkExists(triggerKey)) {
    JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(job.getJobClass()))
        .withIdentity(job.getJobName(), job.getJobGroup()).withDescription(job.getDesc()).build();
    TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
    trigger = setTriggerParam(job, triggerKey, triggerBuilder, trigger);
    scheduler.scheduleJob(jobDetail, trigger);
  } else {
    // trigger已经存在,更新相应的定时设置
    TriggerBuilder triggerBuilder = trigger.getTriggerBuilder();
    trigger = setTriggerParam(job, triggerKey, triggerBuilder, trigger);
    // 按新的trigger重新设置job执行
    scheduler.rescheduleJob(triggerKey, trigger);
  }
}

代码示例来源:origin: ihaolin/antares

private void createZkJob(JobDetail jobDetail) {
  try {
    Scheduler scheduler = schedulers.getScheduler();
    Trigger trigger = scheduler.getTrigger(buildTriggerKey(jobDetail));
    ZkJob zkJob = new ZkJob(jobSupport, jobDetail, serverHost.get(), buildJobFireTime(trigger));
    zkJob.start();
  } catch (Exception e){
    Logs.error("failed to create zk job({}), cause: {}.",
        jobDetail, Throwables.getStackTraceAsString(e));
  }
}

相关文章