Skip to content

Commit

Permalink
Updated properties to extract scheduler name from property name
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen committed Aug 23, 2023
1 parent 06c9c21 commit 39488f8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.box.l10n.mojito.quartz.multi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("l10n.org.multi-quartz")
@ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true")
public class QuartzMultiSchedulerConfigProperties {

Map<String, String> scheduler;

List<SchedulerConfig> schedulerConfigs = new ArrayList<>();

public Map<String, String> getScheduler() {
return scheduler;
}

public void setScheduler(Map<String, String> scheduler) {
this.scheduler = scheduler;
}

public List<SchedulerConfig> getSchedulerConfigs() {
return schedulerConfigs;
}

@PostConstruct
public void init() {
schedulerConfigs.addAll(extractSchedulerConfigs());
}

private Collection<SchedulerConfig> extractSchedulerConfigs() {
Map<String, SchedulerConfig> configs = new HashMap<>();

for (Map.Entry<String, String> entry : scheduler.entrySet()) {
String schedulerName = entry.getKey().substring(0, entry.getKey().indexOf("."));
SchedulerConfig schedulerConfig = configs.getOrDefault(schedulerName, new SchedulerConfig());
schedulerConfig.setName(schedulerName);
if (schedulerConfig.getQuartz() == null) {
schedulerConfig.setQuartz(new HashMap<>());
}
String propertyName = entry.getKey().substring(entry.getKey().indexOf(".") + 1);
schedulerConfig
.getQuartz()
.put(
propertyName.startsWith("quartz.")
? propertyName.substring(propertyName.indexOf(".") + 1)
: propertyName,
entry.getValue());
configs.put(schedulerName, schedulerConfig);
}
return configs.values();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class QuartzMultiSchedulerFactory {

@Autowired ApplicationContext applicationContext;

@Autowired QuartzMultiSchedulerConfig quartzMultiSchedulerConfig;
@Autowired QuartzMultiSchedulerConfigProperties quartzMultiSchedulerConfigProperties;

@Autowired(required = false)
QuartzMetricsReportingJobListener quartzMetricsReportingJobListener;
Expand All @@ -39,7 +39,7 @@ public class QuartzMultiSchedulerFactory {
@PostConstruct
public void createSchedulers() {

for (SchedulerConfig config : quartzMultiSchedulerConfig.getSchedulerConfigs()) {
for (SchedulerConfig config : quartzMultiSchedulerConfigProperties.getSchedulerConfigs()) {
Map<String, String> quartzProps = config.getQuartz();
Properties properties = new Properties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "l10n.org.multi-quartz.enabled", havingValue = "true")
public class SchedulerConfig {

Logger logger = LoggerFactory.getLogger(SchedulerConfig.class);

private String name;

private Map<String, String> quartz = new HashMap<>();
Expand Down

0 comments on commit 39488f8

Please sign in to comment.