コード例 #1
0
 /**
  * Checks if a given persistence configuration entry has a certain strategy for the given service
  *
  * @param serviceName the service to check the configuration for
  * @param config the persistence configuration entry
  * @param strategy the strategy to check for
  * @return true, if it has the given strategy
  */
 protected boolean hasStrategy(
     String serviceName, PersistenceConfiguration config, Strategy strategy) {
   if (defaultStrategies.get(serviceName).contains(strategy) && config.getStrategies().isEmpty()) {
     return true;
   } else {
     for (Strategy s : config.getStrategies()) {
       if (s.equals(strategy)) {
         return true;
       }
     }
     return false;
   }
 }
コード例 #2
0
  /**
   * 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);
          }
        }
      }
    }
  }