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

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

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

Scheduler.getTriggerKeys介绍

[英]Get the names of all the Triggers in the given group.
[中]获取给定组中所有Triggers的名称。

代码示例

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

for (String groupName : scheduler.getTriggerGroupNames()) {
  if (!triggerGroupsToNeverDelete.contains(groupName)) {
    for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))) {
      scheduler.unscheduleJob(key);
if(!triggerGroupsToNeverDelete.contains(group)) {
  log.info("Deleting all triggers in group: {}", group);
  for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group))) {
    scheduler.unscheduleJob(key);

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

for (String groupName : scheduler.getTriggerGroupNames()) {
  if (!triggerGroupsToNeverDelete.contains(groupName)) {
    for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))) {
      scheduler.unscheduleJob(key);
if(!triggerGroupsToNeverDelete.contains(group)) {
  log.info("Deleting all triggers in group: {}", group);
  for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group))) {
    scheduler.unscheduleJob(key);

代码示例来源:origin: org.codelibs/elasticsearch-quartz

public Set<TriggerKey> getTriggerKeys(final GroupMatcher<TriggerKey> matcher) {
  try {
    return scheduler.getTriggerKeys(matcher);
  } catch (final SchedulerException e) {
    throw new QuartzSchedulerException(e);
  }
}

代码示例来源:origin: myschedule/myschedule-quartz-extra

public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> groupMatcher) {
  try {
    return scheduler.getTriggerKeys(groupMatcher);
  } catch (SchedulerException e) {
    throw new QuartzRuntimeException(e);
  }
}

代码示例来源:origin: OpenWiseSolutions/openhub-framework

@Override
public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws SchedulerException {
  return getScheduler().getTriggerKeys(matcher);
}

代码示例来源:origin: com.blazebit/blaze-quartz-utils

public static List<Trigger> getTriggers() throws SchedulerException {
    Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
    List<String> triggerGroups = sched.getTriggerGroupNames();
    List<Trigger> triggers = new ArrayList<Trigger>();

    for (int i = 0; i < triggerGroups.size(); i++) {
      String name = triggerGroups.get(i);
      Set<TriggerKey> keys = sched.getTriggerKeys(GroupMatcher
          .triggerGroupEquals(name));
      Iterator<TriggerKey> iter = keys.iterator();

      while (iter.hasNext()) {
        triggers.add(sched.getTrigger(iter.next()));
      }
    }

    return triggers;
  }
}

代码示例来源:origin: org.motechproject/motech-scheduler

@Override
public void safeUnscheduleAllJobs(String jobIdPrefix) {
  try {
    if (logger.isDebugEnabled()) {
      logger.debug(format("Safe unscheduling the Jobs given jobIdPrefix: %s", jobIdPrefix));
    }
    List<TriggerKey> triggerKeys = new ArrayList<TriggerKey>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
    List<String> triggerNames = extractTriggerNames(triggerKeys);
    for (String triggerName : triggerNames) {
      if (StringUtils.isNotEmpty(jobIdPrefix) && triggerName.contains(jobIdPrefix)) {
        safeUnscheduleJob(triggerName);
      }
    }
  } catch (SchedulerException e) {
    logger.error(e.getMessage());
  }
}

代码示例来源:origin: org.eobjects.datacleaner/DataCleaner-monitor-services

private void logTriggers() {
  final List<RepositoryFolder> tenantFolders = _repository.getFolders();
  for (RepositoryFolder tenantFolder : tenantFolders) {
    final String tenantId = tenantFolder.getName();
    try {
      final Set<TriggerKey> triggerKeys = _scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(
          tenantId));
      if (triggerKeys == null || triggerKeys.isEmpty()) {
        logger.info("No triggers initialized for tenant: {}", tenantId);
      } else {
        for (TriggerKey triggerKey : triggerKeys) {
          logger.info("Trigger of tenant {}: {}", tenantId, triggerKey);
        }
      }
    } catch (SchedulerException e) {
      logger.warn("Failed to get triggers of tenant: " + tenantId, e);
    }
  }
}

代码示例来源:origin: org.ligoj.plugin/plugin-vm

/**
 * Remove all schedules matching the given predicate from the current scheduler, then from the data base.
 */
private void unscheduleAll(final Predicate<TriggerKey> predicate) throws SchedulerException {
  // Remove current schedules from the memory
  final Scheduler scheduler = vmSchedulerFactoryBean.getObject();
  for (final TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.groupEquals(SCHEDULE_TRIGGER_GROUP))) {
    if (predicate.test(triggerKey)) {
      // Match subscription and operation, unschedule this trigger
      scheduler.unscheduleJob(triggerKey);
    }
  }
}

代码示例来源:origin: org.motechproject/motech-scheduler

@Override
public void unscheduleAllJobs(String jobIdPrefix) {
  try {
    if (logger.isDebugEnabled()) {
      logger.debug(jobIdPrefix);
    }
    List<TriggerKey> triggerKeys = new ArrayList<>(scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)));
    List<String> triggerNames = extractTriggerNames(triggerKeys);
    for (String triggerName : triggerNames) {
      if (StringUtils.isNotEmpty(jobIdPrefix) && triggerName.contains(jobIdPrefix)) {
        unscheduleJob(triggerName);
      }
    }
  } catch (SchedulerException e) {
    handleException(String.format("Can not unschedule jobs given jobIdPrefix: %s %s", jobIdPrefix, e.getMessage()), e);
  }
}

代码示例来源:origin: metatron-app/metatron-discovery

/**
 * Find all scheduling Jobs
 *
 * @return
 */
@RequestMapping(value = "/jobs", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> findAll() throws SchedulerException {
 List<SchedulingJob> schedulingJobs = Lists.newArrayList();
 for (String groupName : scheduler.getTriggerGroupNames()) {
  for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))) {
   Trigger trigger = scheduler.getTrigger(key);
   schedulingJobs.add(new SchedulingJob(trigger, scheduler.getTriggerState(key)));
  }
 }
 return ResponseEntity.ok(schedulingJobs);
}

代码示例来源:origin: com.threewks.thundr/thundr-quartz

@Override
public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws QuartzException {
  try {
    return delegate.getTriggerKeys(matcher);
  } catch (SchedulerException e) {
    Logger.error(e.getMessage());
    throw new QuartzException(e);
  }
}

代码示例来源:origin: myschedule/myschedule-quartz-extra

public List<Trigger> getAllTriggers() {
  try {
    List<Trigger> triggers = new ArrayList<Trigger>();
    List<String> groups = scheduler.getTriggerGroupNames();
    for (String group : groups) {
      Set<TriggerKey> keys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group));
      for (TriggerKey key : keys) {
        Trigger trigger = scheduler.getTrigger(key);
        triggers.add(trigger);
      }
    }
    return triggers;
  } catch (SchedulerException e) {
    throw new QuartzRuntimeException(e);
  }
}

代码示例来源:origin: com.threewks.thundr/thundr-contrib-quartz

@Override
public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws QuartzException {
  try {
    return delegate.getTriggerKeys(matcher);
  } catch (SchedulerException e) {
    Logger.error(e.getMessage());
    throw new QuartzException(e);
  }
}

代码示例来源:origin: metatron-app/metatron-discovery

/**
 * Find by key
 *
 * @return
 */
@RequestMapping(value = "/jobs/search/key", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<?> findByKey(@RequestParam(name = "group") String group,
                  @RequestParam(name = "name", required = false) String name) throws SchedulerException {
 if (StringUtils.isNotEmpty(name)) {
  TriggerKey triggerKey = new TriggerKey(name, group);
  Trigger trigger = scheduler.getTrigger(triggerKey);
  if (trigger == null) {
   return ResponseEntity.ok(Lists.newArrayList());
  }
  return ResponseEntity.ok(Lists.newArrayList(new SchedulingJob(trigger, scheduler.getTriggerState(triggerKey))));
 }
 List<SchedulingJob> schedulingJobs = Lists.newArrayList();
 for (String groupName : scheduler.getTriggerGroupNames()) {
  if (group.equals(groupName)) {
   for (TriggerKey key : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(groupName))) {
    Trigger trigger = scheduler.getTrigger(key);
    schedulingJobs.add(new SchedulingJob(trigger, scheduler.getTriggerState(key)));
   }
   break;
  }
 }
 return ResponseEntity.ok(schedulingJobs);
}

代码示例来源:origin: myschedule/myschedule-quartz-extra

public List<Trigger> getPausedTriggers() {
  try {
    List<Trigger> result = new ArrayList<Trigger>();
    List<String> groups = scheduler.getTriggerGroupNames();
    for (String group : groups) {
      Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group));
      for (TriggerKey key : triggerKeys) {
        if (scheduler.getTriggerState(key) == TriggerState.PAUSED) {
          result.add(scheduler.getTrigger(key));
        }
      }
    }
    return result;
  } catch (SchedulerException e) {
    throw new QuartzRuntimeException(e);
  }
}

代码示例来源:origin: net.roboconf/roboconf-dm-scheduler

@Override
  public void application( Application application, EventType eventType ) {

    if( eventType == EventType.DELETED ) {
      this.logger.fine( "Application " + application + " was deleted. Associated jobs are about to be deleted." );
      try {
        Set<TriggerKey> tks = this.scheduler.scheduler.getTriggerKeys( GroupMatcher.triggerGroupEquals( application.getName()));
        for( TriggerKey tk : tks ) {
          try {
            this.scheduler.deleteJob( tk.getName());

          } catch( Exception e ) {
            this.logger.warning( "An error occurred while unscheduling job " + tk.getName() + ". " + e.getMessage());
            Utils.logException( this.logger, e );
          }
        }

      } catch( Exception e ) {
        this.logger.warning( "An error occurred while listing jobs for application " + application + ". " + e.getMessage());
        Utils.logException( this.logger, e );
      }
    }
  }
}

代码示例来源:origin: OpenNMS/opennms

private void printCurrentSchedule() {
    
    try {
      LOG.info("calendarNames: {}", String.join(", ", getScheduler().getCalendarNames().toArray(new String[0])));
      LOG.info("current executing jobs: {}", StringUtils.arrayToCommaDelimitedString(getScheduler().getCurrentlyExecutingJobs().toArray()));
      LOG.info("current job names: {}", getScheduler().getJobKeys(GroupMatcher.<JobKey>groupEquals(JOB_GROUP)).stream().map(JobKey::getName).collect(Collectors.joining(", ")));
      LOG.info("scheduler metadata: {}", getScheduler().getMetaData());
      LOG.info("trigger names: {}", getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP)).stream().map(TriggerKey::getName).collect(Collectors.joining(", ")));
      
      for (TriggerKey key : getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP))) {
        String triggerName = key.getName();
        CronTrigger t = (CronTrigger) getScheduler().getTrigger(key);
        LOG.info("trigger: {}, calendar name: {}, cron expression: {}, URL: {}, rescanExisting: {}, next fire time: {}, previous fire time: {}, time zone: {}, priority: {}",
             triggerName,
             t.getCalendarName(),
             t.getCronExpression(),
             t.getJobDataMap().get(ImportJob.URL),
             t.getJobDataMap().get(ImportJob.RESCAN_EXISTING),
             t.getNextFireTime(),
             t.getPreviousFireTime(),
             t.getTimeZone(),
             t.getPriority());
      }
      
    } catch (Throwable e) {
      LOG.error("printCurrentSchedule: {}", e.getLocalizedMessage(), e);
    }
    
  }
}

代码示例来源:origin: bonitasoft/bonita-engine

@Override
public void rescheduleErroneousTriggers() throws SSchedulerException {
  checkSchedulerState();
  try {
    final List<String> triggerGroupNames = scheduler.getTriggerGroupNames();
    for (final String triggerGroupName : triggerGroupNames) {
      for (final TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(triggerGroupName))) {
        if (TriggerState.ERROR.equals(scheduler.getTriggerState(triggerKey))) {
          scheduler.pauseTrigger(triggerKey);
          scheduler.resumeTrigger(triggerKey);
        }
      }
    }
  } catch (final SchedulerException e) {
    throw new SSchedulerException(e);
  }
}

代码示例来源:origin: bonitasoft/bonita-engine

@Override
public void rescheduleErroneousTriggers() throws SSchedulerException {
  checkSchedulerState();
  try {
    final List<String> triggerGroupNames = scheduler.getTriggerGroupNames();
    for (final String triggerGroupName : triggerGroupNames) {
      for (final TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(triggerGroupName))) {
        if (TriggerState.ERROR.equals(scheduler.getTriggerState(triggerKey))) {
          scheduler.pauseTrigger(triggerKey);
          scheduler.resumeTrigger(triggerKey);
        }
      }
    }
  } catch (final SchedulerException e) {
    throw new SSchedulerException(e);
  }
}

相关文章