更新配置文件

This commit is contained in:
Administrator
2017-07-29 10:18:35 +08:00
committed by wangkang
parent c0a000e88f
commit 7e840176f6
3 changed files with 206 additions and 189 deletions
@@ -10,6 +10,7 @@ import java.io.IOException;
import java.util.Properties;
import javax.sql.DataSource;
import javax.validation.constraints.NotNull;
import org.quartz.JobDetail;
import org.quartz.JobListener;
@@ -20,6 +21,7 @@ import org.quartz.spi.JobFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -27,6 +29,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.validation.annotation.Validated;
import com.egridcloud.udf.scheduler.job.ClearScheduledLog;
import com.egridcloud.udf.scheduler.job.ClearScheduledTriggerLog;
@@ -41,6 +44,8 @@ import com.egridcloud.udf.scheduler.listener.TriggerDetailListener;
*
*/
@Configuration
@ConfigurationProperties(prefix = "com.egridcloud.scheduler.config")
@Validated
public class SchedulerConfig {
/**
@@ -48,6 +53,48 @@ public class SchedulerConfig {
*/
private static final String DEF_GROUP_NAME = "SystemAutoRun";
/**
* 描述 : 是否记录日志
*/
@NotNull
private Boolean logFlag = true;
/**
* 描述 : 是否记录详细日志
*/
@NotNull
private Boolean logDetailFlag = false;
/**
* 描述 : 是否自动启动
*/
@NotNull
private Boolean autoStartup = true;
/**
* 描述 : 是否覆盖已经存在的jobs
*/
@NotNull
private Boolean overwriteExistingJobs = true;
/**
* 描述 : 延迟启动秒数
*/
@NotNull
private Integer startupDelay = 0;
/**
* 描述 : Job接受applicationContext的成员变量名
*/
@NotNull
private String applicationContextSchedulerContextKey = "applicationContext";
/**
* 描述 : quartz配置文件地址
*/
@NotNull
private String quartzPropertiesPath = "def_quartz.properties";
/**
* 描述 : schedulerProperties
*/
@@ -94,11 +141,10 @@ public class SchedulerConfig {
factory.setJobFactory(jobFactory);
//属性设置
factory.setQuartzProperties(quartzProperties);
factory.setOverwriteExistingJobs(schedulerProperties.getOverwriteExistingJobs());
factory.setAutoStartup(schedulerProperties.getAutoStartup());
factory.setStartupDelay(schedulerProperties.getStartupDelay());
factory.setApplicationContextSchedulerContextKey(
schedulerProperties.getApplicationContextSchedulerContextKey());
factory.setOverwriteExistingJobs(getOverwriteExistingJobs());
factory.setAutoStartup(getAutoStartup());
factory.setStartupDelay(getStartupDelay());
factory.setApplicationContextSchedulerContextKey(getApplicationContextSchedulerContextKey());
//添加监听器
factory.setSchedulerListeners(schListener);
factory.setGlobalJobListeners(jobDetailListener);
@@ -118,8 +164,7 @@ public class SchedulerConfig {
@Bean
public Properties quartzProperties() throws IOException {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean
.setLocation(new ClassPathResource(schedulerProperties.getQuartzPropertiesPath()));
propertiesFactoryBean.setLocation(new ClassPathResource(getQuartzPropertiesPath()));
propertiesFactoryBean.afterPropertiesSet();
return propertiesFactoryBean.getObject();
}
@@ -222,4 +267,149 @@ public class SchedulerConfig {
return factoryBean;
}
/**
* 描述 : 获取logFlag
*
* @return the logFlag
*/
public Boolean getLogFlag() {
return logFlag;
}
/**
* 描述 : 设置logFlag
*
* @param logFlag the logFlag to set
*/
public void setLogFlag(Boolean logFlag) {
this.logFlag = logFlag;
}
/**
* 描述 : 获取logDetailFlag
*
* @return the logDetailFlag
*/
public Boolean getLogDetailFlag() {
return logDetailFlag;
}
/**
* 描述 : 设置logDetailFlag
*
* @param logDetailFlag the logDetailFlag to set
*/
public void setLogDetailFlag(Boolean logDetailFlag) {
this.logDetailFlag = logDetailFlag;
}
/**
* 描述 : 获取autoStartup
*
* @return the autoStartup
*/
public Boolean getAutoStartup() {
return autoStartup;
}
/**
* 描述 : 设置autoStartup
*
* @param autoStartup the autoStartup to set
*/
public void setAutoStartup(Boolean autoStartup) {
this.autoStartup = autoStartup;
}
/**
* 描述 : 获取overwriteExistingJobs
*
* @return the overwriteExistingJobs
*/
public Boolean getOverwriteExistingJobs() {
return overwriteExistingJobs;
}
/**
* 描述 : 设置overwriteExistingJobs
*
* @param overwriteExistingJobs the overwriteExistingJobs to set
*/
public void setOverwriteExistingJobs(Boolean overwriteExistingJobs) {
this.overwriteExistingJobs = overwriteExistingJobs;
}
/**
* 描述 : 获取startupDelay
*
* @return the startupDelay
*/
public Integer getStartupDelay() {
return startupDelay;
}
/**
* 描述 : 设置startupDelay
*
* @param startupDelay the startupDelay to set
*/
public void setStartupDelay(Integer startupDelay) {
this.startupDelay = startupDelay;
}
/**
* 描述 : 获取applicationContextSchedulerContextKey
*
* @return the applicationContextSchedulerContextKey
*/
public String getApplicationContextSchedulerContextKey() {
return applicationContextSchedulerContextKey;
}
/**
* 描述 : 设置applicationContextSchedulerContextKey
*
* @param applicationContextSchedulerContextKey the applicationContextSchedulerContextKey to set
*/
public void setApplicationContextSchedulerContextKey(
String applicationContextSchedulerContextKey) {
this.applicationContextSchedulerContextKey = applicationContextSchedulerContextKey;
}
/**
* 描述 : 获取quartzPropertiesPath
*
* @return the quartzPropertiesPath
*/
public String getQuartzPropertiesPath() {
return quartzPropertiesPath;
}
/**
* 描述 : 设置quartzPropertiesPath
*
* @param quartzPropertiesPath the quartzPropertiesPath to set
*/
public void setQuartzPropertiesPath(String quartzPropertiesPath) {
this.quartzPropertiesPath = quartzPropertiesPath;
}
/**
* 描述 : 获取schedulerProperties
*
* @return the schedulerProperties
*/
public SchedulerProperties getSchedulerProperties() {
return schedulerProperties;
}
/**
* 描述 : 设置schedulerProperties
*
* @param schedulerProperties the schedulerProperties to set
*/
public void setSchedulerProperties(SchedulerProperties schedulerProperties) {
this.schedulerProperties = schedulerProperties;
}
}
@@ -6,11 +6,8 @@
*/
package com.egridcloud.udf.scheduler;
import javax.validation.constraints.NotNull;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
/**
* 描述 : SchedulerProperties
@@ -19,177 +16,7 @@ import org.springframework.validation.annotation.Validated;
*
*/
@Component
@ConfigurationProperties(prefix = "com.egridcloud.scheduler")
@Validated
@ConfigurationProperties(prefix = "com.egridcloud.scheduler.properties")
public class SchedulerProperties {
/**
* 描述 : 是否记录日志
*/
@NotNull
private Boolean logFlag = true;
/**
* 描述 : 是否记录详细日志
*/
@NotNull
private Boolean logDetailFlag = false;
/**
* 描述 : 是否自动启动
*/
@NotNull
private Boolean autoStartup = true;
/**
* 描述 : 是否覆盖已经存在的jobs
*/
@NotNull
private Boolean overwriteExistingJobs = true;
/**
* 描述 : 延迟启动秒数
*/
@NotNull
private Integer startupDelay = 0;
/**
* 描述 : Job接受applicationContext的成员变量名
*/
@NotNull
private String applicationContextSchedulerContextKey = "applicationContext";
/**
* 描述 : quartz配置文件地址
*/
@NotNull
private String quartzPropertiesPath = "def_quartz.properties";
/**
* 描述 : 获取autoStartup
*
* @return the autoStartup
*/
public Boolean getAutoStartup() {
return autoStartup;
}
/**
* 描述 : 设置autoStartup
*
* @param autoStartup the autoStartup to set
*/
public void setAutoStartup(Boolean autoStartup) {
this.autoStartup = autoStartup;
}
/**
* 描述 : 获取overwriteExistingJobs
*
* @return the overwriteExistingJobs
*/
public Boolean getOverwriteExistingJobs() {
return overwriteExistingJobs;
}
/**
* 描述 : 设置overwriteExistingJobs
*
* @param overwriteExistingJobs the overwriteExistingJobs to set
*/
public void setOverwriteExistingJobs(Boolean overwriteExistingJobs) {
this.overwriteExistingJobs = overwriteExistingJobs;
}
/**
* 描述 : 获取startupDelay
*
* @return the startupDelay
*/
public Integer getStartupDelay() {
return startupDelay;
}
/**
* 描述 : 设置startupDelay
*
* @param startupDelay the startupDelay to set
*/
public void setStartupDelay(Integer startupDelay) {
this.startupDelay = startupDelay;
}
/**
* 描述 : 获取applicationContextSchedulerContextKey
*
* @return the applicationContextSchedulerContextKey
*/
public String getApplicationContextSchedulerContextKey() {
return applicationContextSchedulerContextKey;
}
/**
* 描述 : 设置applicationContextSchedulerContextKey
*
* @param applicationContextSchedulerContextKey the applicationContextSchedulerContextKey to set
*/
public void setApplicationContextSchedulerContextKey(
String applicationContextSchedulerContextKey) {
this.applicationContextSchedulerContextKey = applicationContextSchedulerContextKey;
}
/**
* 描述 : 获取quartzPropertiesPath
*
* @return the quartzPropertiesPath
*/
public String getQuartzPropertiesPath() {
return quartzPropertiesPath;
}
/**
* 描述 : 设置quartzPropertiesPath
*
* @param quartzPropertiesPath the quartzPropertiesPath to set
*/
public void setQuartzPropertiesPath(String quartzPropertiesPath) {
this.quartzPropertiesPath = quartzPropertiesPath;
}
/**
* 描述 : 获取logFlag
*
* @return the logFlag
*/
public Boolean getLogFlag() {
return logFlag;
}
/**
* 描述 : 设置logFlag
*
* @param logFlag the logFlag to set
*/
public void setLogFlag(Boolean logFlag) {
this.logFlag = logFlag;
}
/**
* 描述 : 获取logDetailFlag
*
* @return the logDetailFlag
*/
public Boolean getLogDetailFlag() {
return logDetailFlag;
}
/**
* 描述 : 设置logDetailFlag
*
* @param logDetailFlag the logDetailFlag to set
*/
public void setLogDetailFlag(Boolean logDetailFlag) {
this.logDetailFlag = logDetailFlag;
}
}
@@ -23,7 +23,7 @@ import org.springframework.stereotype.Service;
import com.egridcloud.udf.core.exception.SystemException;
import com.egridcloud.udf.scheduler.ITriggerLog;
import com.egridcloud.udf.scheduler.SchedulerProperties;
import com.egridcloud.udf.scheduler.SchedulerConfig;
import com.egridcloud.udf.scheduler.domain.ScheduledTriggerLog;
/**
@@ -36,10 +36,10 @@ import com.egridcloud.udf.scheduler.domain.ScheduledTriggerLog;
public class TriggerListenerService {
/**
* 描述 : schedulerProperties
* 描述 : schedulerConfig
*/
@Autowired
private SchedulerProperties schedulerProperties;
private SchedulerConfig schedulerConfig;
/**
* 描述 : triggerLog
@@ -92,7 +92,7 @@ public class TriggerListenerService {
public void saveTriggerFired(JobExecutionContext context) throws SchedulerException {
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
if (!this.schedulerProperties.getLogFlag() || !this.schedulerProperties.getLogDetailFlag()) {
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
return;
}
@@ -146,7 +146,7 @@ public class TriggerListenerService {
boolean vetoed = false;
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
if (!this.schedulerProperties.getLogFlag() || !this.schedulerProperties.getLogDetailFlag()) {
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
return vetoed;
}
@@ -197,7 +197,7 @@ public class TriggerListenerService {
public void saveJobToBeExecuted(JobExecutionContext context) throws SchedulerException {
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
if (!this.schedulerProperties.getLogFlag() || !this.schedulerProperties.getLogDetailFlag()) {
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
return;
}
@@ -308,7 +308,7 @@ public class TriggerListenerService {
}
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
if (!this.schedulerProperties.getLogFlag() || !this.schedulerProperties.getLogDetailFlag()) {
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
return;
}
@@ -377,7 +377,7 @@ public class TriggerListenerService {
}
// 是否记录执行历史(true记录,false不记录)
if (!this.schedulerProperties.getLogFlag()) {
if (!this.schedulerConfig.getLogFlag()) {
return;
}