d527fa13df9ab50c1709ebc111d8f8eb767c7a76.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.xxl.job.admin.core.conf;
  2. import com.xxl.job.admin.core.alarm.JobAlarmer;
  3. import com.xxl.job.admin.core.scheduler.XxlJobScheduler;
  4. import com.xxl.job.admin.dao.*;
  5. import org.springframework.beans.factory.DisposableBean;
  6. import org.springframework.beans.factory.InitializingBean;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.mail.javamail.JavaMailSender;
  9. import org.springframework.stereotype.Component;
  10. import javax.annotation.Resource;
  11. import javax.sql.DataSource;
  12. import java.util.Arrays;
  13. /**
  14. * xxl-job config
  15. *
  16. * @author xuxueli 2017-04-28
  17. */
  18. @Component
  19. public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
  20. private static XxlJobAdminConfig adminConfig = null;
  21. public static XxlJobAdminConfig getAdminConfig() {
  22. return adminConfig;
  23. }
  24. // ---------------------- XxlJobScheduler ----------------------
  25. private XxlJobScheduler xxlJobScheduler;
  26. @Override
  27. public void afterPropertiesSet() throws Exception {
  28. adminConfig = this;
  29. xxlJobScheduler = new XxlJobScheduler();
  30. xxlJobScheduler.init();
  31. }
  32. @Override
  33. public void destroy() throws Exception {
  34. xxlJobScheduler.destroy();
  35. }
  36. // ---------------------- XxlJobScheduler ----------------------
  37. // conf
  38. @Value("${xxl.job.i18n}")
  39. private String i18n;
  40. @Value("${xxl.job.accessToken}")
  41. private String accessToken;
  42. @Value("${spring.mail.username}")
  43. private String emailUserName;
  44. @Value("${xxl.job.triggerpool.fast.max}")
  45. private int triggerPoolFastMax;
  46. @Value("${xxl.job.triggerpool.slow.max}")
  47. private int triggerPoolSlowMax;
  48. @Value("${xxl.job.logretentiondays}")
  49. private int logretentiondays;
  50. // dao, service
  51. @Resource
  52. private XxlJobLogDao xxlJobLogDao;
  53. @Resource
  54. private XxlJobInfoDao xxlJobInfoDao;
  55. @Resource
  56. private XxlJobRegistryDao xxlJobRegistryDao;
  57. @Resource
  58. private XxlJobGroupDao xxlJobGroupDao;
  59. @Resource
  60. private XxlJobLogReportDao xxlJobLogReportDao;
  61. @Resource
  62. private JavaMailSender mailSender;
  63. @Resource
  64. private DataSource dataSource;
  65. @Resource
  66. private JobAlarmer jobAlarmer;
  67. public String getI18n() {
  68. if (!Arrays.asList("zh_CN", "zh_TC", "en").contains(i18n)) {
  69. return "zh_CN";
  70. }
  71. return i18n;
  72. }
  73. public String getAccessToken() {
  74. return accessToken;
  75. }
  76. public String getEmailUserName() {
  77. return emailUserName;
  78. }
  79. public int getTriggerPoolFastMax() {
  80. if (triggerPoolFastMax < 200) {
  81. return 200;
  82. }
  83. return triggerPoolFastMax;
  84. }
  85. public int getTriggerPoolSlowMax() {
  86. if (triggerPoolSlowMax < 100) {
  87. return 100;
  88. }
  89. return triggerPoolSlowMax;
  90. }
  91. public int getLogretentiondays() {
  92. if (logretentiondays < 7) {
  93. return -1; // Limit greater than or equal to 7, otherwise close
  94. }
  95. return logretentiondays;
  96. }
  97. public XxlJobLogDao getXxlJobLogDao() {
  98. return xxlJobLogDao;
  99. }
  100. public XxlJobInfoDao getXxlJobInfoDao() {
  101. return xxlJobInfoDao;
  102. }
  103. public XxlJobRegistryDao getXxlJobRegistryDao() {
  104. return xxlJobRegistryDao;
  105. }
  106. public XxlJobGroupDao getXxlJobGroupDao() {
  107. return xxlJobGroupDao;
  108. }
  109. public XxlJobLogReportDao getXxlJobLogReportDao() {
  110. return xxlJobLogReportDao;
  111. }
  112. public JavaMailSender getMailSender() {
  113. return mailSender;
  114. }
  115. public DataSource getDataSource() {
  116. return dataSource;
  117. }
  118. public JobAlarmer getJobAlarmer() {
  119. return jobAlarmer;
  120. }
  121. }