public static SchedulerStatus getByValue(final String value) { final SchedulerStatus schedulerStatus; if (INITIALIZED.getValue().equals(value)) { schedulerStatus = INITIALIZED; } else if (RUNNING.getValue().equals(value)) { schedulerStatus = RUNNING; } else if (STOPPED.getValue().equals(value)) { schedulerStatus = STOPPED; } else if (IN_TERMINATION.getValue().equals(value)) { schedulerStatus = IN_TERMINATION; } else { throw new SpringBatchLightminApplicationException("Unknown SchedulerStatus : " + value); } return schedulerStatus; } }
@Override public void schedule(final String beanName, final Boolean forceScheduling) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.RUNNING) && Boolean.FALSE.equals(forceScheduling)) { log.info("Scheduler: " + beanName + " already running"); } else { scheduler.schedule(); } } else { throw new SpringBatchLightminConfigurationException("Could not schedule bean with name: " + beanName); } }
public static JobSchedulerConfiguration map(final Map<String, Object> values) { final JobSchedulerConfiguration jobSchedulerConfiguration = new JobSchedulerConfiguration(); jobSchedulerConfiguration.setBeanName(getValueOrNull(values, JobSchedulerConfigurationKey.BEAN_NAME, String.class)); final JobSchedulerType jobSchedulerType = JobSchedulerType.getById(getValueOrNull(values, JobSchedulerConfigurationKey.SCHEDULER_TYPE, Long.class)); if (JobSchedulerType.CRON == jobSchedulerType) { jobSchedulerConfiguration.setCronExpression(getValueOrNull(values, JobSchedulerConfigurationKey.CRON_EXPRESSION, String.class)); } else if (JobSchedulerType.PERIOD == jobSchedulerType) { jobSchedulerConfiguration.setFixedDelay(getValueOrNull(values, JobSchedulerConfigurationKey.FIXED_DELAY, Long.class)); jobSchedulerConfiguration.setInitialDelay(getValueOrNull(values, JobSchedulerConfigurationKey.INITIAL_DELAY, Long.class)); } jobSchedulerConfiguration.setJobSchedulerType(jobSchedulerType); final SchedulerStatus schedulerStatus = SchedulerStatus.getByValue(getValueOrNull(values, JobSchedulerConfigurationKey.STATUS, String.class)); jobSchedulerConfiguration.setSchedulerStatus(schedulerStatus); final TaskExecutorType taskExecutorType = TaskExecutorType.getById(getValueOrNull(values, JobSchedulerConfigurationKey.TASK_EXECUTOR_TYPE, Long.class)); jobSchedulerConfiguration.setTaskExecutorType(taskExecutorType); return jobSchedulerConfiguration; }
@Override public void schedule(final String beanName, final Boolean forceScheduling) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.RUNNING) && Boolean.FALSE.equals(forceScheduling)) { log.info("Scheduler: " + beanName + " already running"); } else { scheduler.schedule(); } } else { throw new SpringBatchLightminConfigurationException("Could not schedule bean with name: " + beanName); } }
public static List<ValueRecord> map(final JobSchedulerConfiguration jobSchedulerConfiguration, final Long jobConfigurationId) { final List<ValueRecord> valueRecords = new ArrayList<>(); final ValueRecord beanName = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.BEAN_NAME, jobSchedulerConfiguration.getBeanName()); final ValueRecord cronExpression = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.CRON_EXPRESSION, jobSchedulerConfiguration.getCronExpression()); final ValueRecord fixedDelay = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.FIXED_DELAY, jobSchedulerConfiguration.getFixedDelay()); final ValueRecord initialDelay = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.INITIAL_DELAY, jobSchedulerConfiguration.getInitialDelay()); final ValueRecord schedulerStatus = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.STATUS, jobSchedulerConfiguration.getSchedulerStatus().getValue()); final ValueRecord schedulerType = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.SCHEDULER_TYPE, jobSchedulerConfiguration.getJobSchedulerType().getId()); final ValueRecord executorType = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.TASK_EXECUTOR_TYPE, jobSchedulerConfiguration.getTaskExecutorType().getId()); valueRecords.add(beanName); valueRecords.add(cronExpression); valueRecords.add(fixedDelay); valueRecords.add(initialDelay); valueRecords.add(schedulerStatus); valueRecords.add(schedulerType); valueRecords.add(executorType); return valueRecords; } }
@Override public void terminate(final String beanName) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.STOPPED)) { log.info("Scheduler: " + beanName + " already terminated"); } else { scheduler.terminate(); } } else { throw new SpringBatchLightminConfigurationException("Could not terminate bean with name: " + beanName); } }
@Override public void terminate(final String beanName) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.STOPPED)) { log.info("Scheduler: " + beanName + " already terminated"); } else { scheduler.terminate(); } } else { throw new SpringBatchLightminConfigurationException("Could not terminate bean with name: " + beanName); } }
for (final Map.Entry<String, Scheduler> schedulerEntry : schedulerMap.entrySet()) { final Scheduler scheduler = schedulerEntry.getValue(); if (SchedulerStatus.RUNNING.equals(scheduler.getSchedulerStatus())) { log.debug("scheduling bean: " + schedulerEntry.getKey()); scheduler.schedule();
for (final Map.Entry<String, Scheduler> schedulerEntry : schedulerMap.entrySet()) { final Scheduler scheduler = schedulerEntry.getValue(); if (SchedulerStatus.RUNNING.equals(scheduler.getSchedulerStatus())) { log.debug("scheduling bean: " + schedulerEntry.getKey()); scheduler.schedule();
@Override public void updateJobConfiguration(final JobConfiguration jobConfiguration) { jobConfiguration.validateForUpdate(); try { final JobConfiguration existingJobConfiguration = this.jobConfigurationRepository.getJobConfiguration(jobConfiguration.getJobConfigurationId(), this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (existingJobConfiguration.getJobSchedulerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobSchedulerConfiguration().getBeanName(); jobConfiguration.getJobSchedulerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.schedulerService.refreshSchedulerForJob(jobConfiguration); if (SchedulerStatus.RUNNING.equals(jobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(jobConfiguration.getJobSchedulerConfiguration().getBeanName(), Boolean.TRUE); } else { log.info("Scheduler not started, no scheduling triggered!"); } } else if (existingJobConfiguration.getJobListenerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobListenerConfiguration().getBeanName(); jobConfiguration.getJobListenerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.listenerService.refreshListenerForJob(jobConfiguration); } } catch (final NoSuchJobConfigurationException e) { log.error(e.getMessage()); throw new SpringBatchLightminApplicationException(e, e.getMessage()); } }
@Override public void updateJobConfiguration(final JobConfiguration jobConfiguration) { jobConfiguration.validateForUpdate(); try { final JobConfiguration existingJobConfiguration = this.jobConfigurationRepository.getJobConfiguration(jobConfiguration.getJobConfigurationId(), this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (existingJobConfiguration.getJobSchedulerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobSchedulerConfiguration().getBeanName(); jobConfiguration.getJobSchedulerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.schedulerService.refreshSchedulerForJob(jobConfiguration); if (SchedulerStatus.RUNNING.equals(jobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(jobConfiguration.getJobSchedulerConfiguration().getBeanName(), Boolean.TRUE); } else { log.info("Scheduler not started, no scheduling triggered!"); } } else if (existingJobConfiguration.getJobListenerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobListenerConfiguration().getBeanName(); jobConfiguration.getJobListenerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.listenerService.refreshListenerForJob(jobConfiguration); } } catch (final NoSuchJobConfigurationException e) { log.error(e.getMessage()); throw new SpringBatchLightminApplicationException(e, e.getMessage()); } }
this.jobConfigurationRepository.update(addedJobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (SchedulerStatus.RUNNING.equals(addedJobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(beanName, Boolean.TRUE); } else {
this.jobConfigurationRepository.update(addedJobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (SchedulerStatus.RUNNING.equals(addedJobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(beanName, Boolean.TRUE); } else {