ApplicationConfig.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.evps.comm.server.config;
  2. import com.its.common.network.tcp.server.NettyServerConfig;
  3. import com.its.common.utils.TimeUtils;
  4. import lombok.Getter;
  5. import lombok.Setter;
  6. import lombok.ToString;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.boot.context.properties.ConfigurationProperties;
  9. import org.springframework.stereotype.Component;
  10. import javax.annotation.PostConstruct;
  11. @Slf4j
  12. @Getter
  13. @Setter
  14. @ToString
  15. @Component
  16. @ConfigurationProperties(prefix = "application")
  17. public class ApplicationConfig extends NettyServerConfig {
  18. private boolean loggingThread = false;
  19. private String processId = "evps-comm-server";
  20. private double cpuLimits = 75;
  21. private boolean packetDebug = true;
  22. private int autoEndMinutes = 20;
  23. private int lastCommTimeoutSeconds = 60;
  24. private int maxConnection = 0;
  25. private int packetWorkers = 0;
  26. private int loggingWorkers = 0;
  27. private int dbmsWorkers = 0;
  28. private int queueSize = 0;
  29. private String bootingTime;
  30. private boolean startSchedule;
  31. @PostConstruct
  32. private void init() {
  33. this.startSchedule = false;
  34. this.bootingTime = TimeUtils.now();
  35. configure();
  36. if (this.packetWorkers == 0) {
  37. this.packetWorkers = Runtime.getRuntime().availableProcessors() / 2;
  38. if (this.packetWorkers == 0) this.packetWorkers = 1;
  39. }
  40. if (this.loggingWorkers == 0) {
  41. this.loggingWorkers = Runtime.getRuntime().availableProcessors() / 4;
  42. if (this.loggingWorkers == 0) this.loggingWorkers = 1;
  43. }
  44. if (this.dbmsWorkers == 0) {
  45. this.dbmsWorkers = Runtime.getRuntime().availableProcessors() / 4;
  46. if (this.dbmsWorkers == 0) this.dbmsWorkers = 1;
  47. }
  48. if (this.readerIdleTimeSeconds < 10) {
  49. this.readerIdleTimeSeconds = 12;
  50. }
  51. if (this.autoEndMinutes != 0) {
  52. if (this.autoEndMinutes < 10){
  53. this.autoEndMinutes = 10;
  54. }
  55. if (this.autoEndMinutes > 60){
  56. this.autoEndMinutes = 60;
  57. }
  58. }
  59. if (this.lastCommTimeoutSeconds < 20){
  60. this.lastCommTimeoutSeconds = 20;
  61. }
  62. if (this.lastCommTimeoutSeconds > 180){
  63. this.lastCommTimeoutSeconds = 180;
  64. }
  65. this.acceptThreads = 1;
  66. log.info("[{}] -------------------------", this.getClass().getSimpleName());
  67. log.info("[{}] maxConnection: {}", this.getClass().getSimpleName(), this.maxConnection);
  68. log.info("[{}] loggingThread: {}", this.getClass().getSimpleName(), this.loggingThread);
  69. log.info("[{}] packetWorkers: {}", this.getClass().getSimpleName(), this.packetWorkers);
  70. log.info("[{}] loggingWorkers: {}", this.getClass().getSimpleName(), this.loggingWorkers);
  71. log.info("[{}] readerIdleTimeSeconds: {}", this.getClass().getSimpleName(), this.readerIdleTimeSeconds);
  72. log.info("{}", super.toString());
  73. }
  74. public int getQueueSize() {
  75. int qSize;
  76. if (this.queueSize == 0)
  77. qSize = 1000;
  78. else
  79. qSize = this.queueSize;
  80. return qSize;
  81. }
  82. }