|
|
@@ -2,8 +2,13 @@ package com.evps.comm.server.config;
|
|
|
|
|
|
import com.evps.comm.server.EvpsCommServerApplication;
|
|
|
import com.evps.comm.server.repository.ApplicationRepository;
|
|
|
+import com.evps.comm.server.xnet.server.handler.MdcLoggingHandler;
|
|
|
import com.evps.common.dto.EvpsCenter;
|
|
|
+import com.evps.common.dto.NET;
|
|
|
import com.its.common.utils.StringUtils;
|
|
|
+import io.netty.channel.Channel;
|
|
|
+import io.netty.channel.ChannelPipeline;
|
|
|
+import io.netty.handler.logging.LogLevel;
|
|
|
import lombok.Getter;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.Setter;
|
|
|
@@ -64,8 +69,59 @@ public class TraceConfig {
|
|
|
});
|
|
|
}
|
|
|
catch(Exception e) {
|
|
|
- log.error("{}.loadTraceInfo Exception: {}", this.getClass().getSimpleName(), e.toString());
|
|
|
+ log.error("{}.loadTraceInfo(DUMP) Exception: {}", this.getClass().getSimpleName(), e.toString());
|
|
|
}
|
|
|
+
|
|
|
+ try {
|
|
|
+ this.repo.getCenterMap().forEach((key, center) -> center.setTcpDump(false));
|
|
|
+
|
|
|
+ Properties props = getProperties();
|
|
|
+ String dumps = props.getProperty("TCP-DUMP", "").trim();
|
|
|
+ if (dumps.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> regionCds = StringUtils.split(dumps, ",");
|
|
|
+ regionCds.forEach(id -> {
|
|
|
+ EvpsCenter center = this.repo.getCenterMap().get(id.trim());
|
|
|
+ if (center != null) {
|
|
|
+ center.setTcpDump(true);
|
|
|
+// log.info("TraceConfig.loadTraceInfo: Center Dump: {}", center.getCenterId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ log.error("{}.loadTraceInfo(TCP-DUMP) Exception: {}", this.getClass().getSimpleName(), e.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ updateLoggingChannel();
|
|
|
}
|
|
|
|
|
|
+ private void updateLoggingChannel() {
|
|
|
+
|
|
|
+ try {
|
|
|
+ this.repo.getCenterMap().forEach((key, center) -> {
|
|
|
+ if (center.getNetState().getChannel() != null &¢er.getNetState().getState() != NET.CLOSED) {
|
|
|
+ Channel channel = center.getNetState().getChannel();
|
|
|
+ channel.eventLoop().execute(() -> {
|
|
|
+ ChannelPipeline pipeline = channel.pipeline();
|
|
|
+ boolean shouldHaveHandler = center.isTcpDump();
|
|
|
+ boolean hasHandler = pipeline.get(ApplicationRepository.MDC_LOGGING_HANDLER_NAME) != null;
|
|
|
+
|
|
|
+ if (shouldHaveHandler && !hasHandler) {
|
|
|
+ log.info("Adding TCP dump handler to channel for center: {}", center.getCenterId());
|
|
|
+ pipeline.addFirst(ApplicationRepository.MDC_LOGGING_HANDLER_NAME, new MdcLoggingHandler(LogLevel.INFO));
|
|
|
+ } else if (!shouldHaveHandler && hasHandler) {
|
|
|
+ log.info("Removing TCP dump handler from channel for center: {}", center.getCenterId());
|
|
|
+ pipeline.remove(ApplicationRepository.MDC_LOGGING_HANDLER_NAME);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ log.error("{}.updateLoggingChannel Exception: {}", this.getClass().getSimpleName(), e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|