/**
   * Creates and schedules a new quartz-job and trigger with model and rule name as jobData.
   *
   * @param rule the rule to schedule
   * @param trigger the defined trigger
   * @throws SchedulerException if there is an internal Scheduler error.
   */
  private void createTimers(String modelName) {
    PersistenceModel persistModel =
        (PersistenceModel) modelRepository.getModel(modelName + ".persist");
    if (persistModel != null) {
      for (Strategy strategy : persistModel.getStrategies()) {
        if (strategy instanceof CronStrategy) {
          CronStrategy cronStrategy = (CronStrategy) strategy;
          String cronExpression = cronStrategy.getCronExpression();
          JobKey jobKey = new JobKey(strategy.getName(), modelName);
          try {
            JobDetail job =
                newJob(PersistItemsJob.class)
                    .usingJobData(
                        PersistItemsJob.JOB_DATA_PERSISTMODEL,
                        cronStrategy.eResource().getURI().trimFileExtension().path())
                    .usingJobData(PersistItemsJob.JOB_DATA_STRATEGYNAME, cronStrategy.getName())
                    .withIdentity(jobKey)
                    .build();

            Trigger quartzTrigger =
                newTrigger().withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();

            scheduler.scheduleJob(job, quartzTrigger);

            logger.debug(
                "Scheduled strategy {} with cron expression {}",
                new Object[] {jobKey.toString(), cronExpression});
          } catch (SchedulerException e) {
            logger.error(
                "Failed to schedule job for strategy {} with cron expression {}",
                new String[] {jobKey.toString(), cronExpression},
                e);
          }
        }
      }
    }
  }
 /**
  * Delete all {@link Job}s of the group <code>persistModelName</code>
  *
  * @throws SchedulerException if there is an internal Scheduler error.
  */
 private void removeTimers(String persistModelName) {
   try {
     Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(persistModelName));
     for (JobKey jobKey : jobKeys) {
       try {
         boolean success = scheduler.deleteJob(jobKey);
         if (success) {
           logger.debug("Removed scheduled cron job for strategy '{}'", jobKey.toString());
         } else {
           logger.warn("Failed to delete cron jobs '{}'", jobKey.getName());
         }
       } catch (SchedulerException e) {
         logger.warn("Failed to delete cron jobs '{}'", jobKey.getName());
       }
     }
   } catch (SchedulerException e) {
     logger.warn("Failed to delete cron jobs of group '{}'", persistModelName);
   }
 }