From 1a1b76e6ec98eac0e56ccbba9908a80571858f60 Mon Sep 17 00:00:00 2001 From: Harrison Date: Thu, 2 Jun 2022 12:49:30 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-72831=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E6=A3=80=E6=B5=8B-=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E6=AD=A3=E5=B8=B8=E7=9A=84=EF=BC=8C=E4=BD=86=E6=98=AF?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=E4=BA=86=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BF=99=E9=83=A8=E5=88=86=E6=9C=89=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=20core.xml=20=E9=87=8C=E9=9D=A2=E7=9A=84=20l?= =?UTF-8?q?og=20=E5=8A=A0=E8=BD=BD=E5=90=8E=EF=BC=8C=E4=BC=9A=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E8=BF=99=E9=87=8C=E7=9A=84=20log=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E3=80=82=20=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=82=E6=8F=90=E4=BE=9B=E9=BB=98=E8=AE=A4=E7=9A=84?= =?UTF-8?q?=20appender?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/env/EnvPrepare.java | 2 +- .../com/fr/env/detect/EnvDetectorCenter.java | 121 +++++++++++------- .../detect/thowable/ThrowableLogAppender.java | 8 +- 3 files changed, 82 insertions(+), 49 deletions(-) diff --git a/designer-base/src/main/java/com/fr/env/EnvPrepare.java b/designer-base/src/main/java/com/fr/env/EnvPrepare.java index 999088e272..288d2f09c6 100644 --- a/designer-base/src/main/java/com/fr/env/EnvPrepare.java +++ b/designer-base/src/main/java/com/fr/env/EnvPrepare.java @@ -22,6 +22,6 @@ public class EnvPrepare extends Activator { @Override public void stop() { - + EnvDetectorCenter.getInstance().destroy(); } } diff --git a/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java index e9ed96cf8d..070d63d850 100644 --- a/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java +++ b/designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java @@ -37,6 +37,43 @@ import java.util.stream.Stream; **/ public class EnvDetectorCenter { + private final Listener AFTER_START_LISTENER = new Listener() { + @Override + public void on(Event event, Null param) { + if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) { + stop(); + } + } + }; + private final Listener BEFORE_START_LISTENER = new Listener() { + @Override + public void on(Event event, Null param) { + PROCESS.set(DetectorProcess.SERVER_LAUNCH); + start(); + } + }; + + + private final Listener START_UP_COMPLETE_LISTENER = new Listener() { + + @Override + public void on(Event event, Null param) { + if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { + stop(); + } + } + }; + private final Listener AFTER_SWITCH_LISTENER = new Listener() { + @Override + public void on(Event event, Workspace param) { + if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { + stop(); + } + } + }; + + private final AtomicReference PROCESS = new AtomicReference<>(); + public static EnvDetectorCenter getInstance() { return EnvDetectorCenterHolder.INSTANCE; } @@ -45,62 +82,36 @@ public class EnvDetectorCenter { private static final EnvDetectorCenter INSTANCE = new EnvDetectorCenter(); } - private final AtomicReference PROCESS = new AtomicReference<>(); - /** * 初始化 */ public void init() { - - // 重置逻辑 - DetectorBridge.getInstance().reset(); // 如果已经启动了,则不再启动 if (PROCESS.get() != null) { return; } - + + start(); // 默认是启动 PROCESS.set(DetectorProcess.DESIGN_LAUNCH); - start(); - - // 添加启动完成监听 - EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener() { - @Override - public void on(Event event, Null param) { - if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { - stop(); - } - } - }); - - // 切换完成后的监听 - EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener() { - @Override - public void on(Event event, Workspace param) { - if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { - stop(); - } - } - }); - - // 打开内置服务器 - EventDispatcher.listen(EmbedServerEvent.BeforeStart, new Listener() { - @Override - public void on(Event event, Null param) { - PROCESS.set(DetectorProcess.SERVER_LAUNCH); - start(); - } - }); - EventDispatcher.listen(EmbedServerEvent.AfterStart, new Listener() { - @Override - public void on(Event event, Null param) { - if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) { - stop(); - } - } - }); + + listen(); + } + + + /** + * 销毁,一般用在模块关闭中 + */ + public void destroy() { + + stopListen(); + // 重置内容 + DetectorBridge.getInstance().reset(); + // 关闭逻辑 + DetectorBridge.getInstance().stop(); + PROCESS.set(null); } /** @@ -175,6 +186,28 @@ public class EnvDetectorCenter { .collect(Collectors.toList()); } + + private void listen() { + + // 添加启动完成监听 + EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, START_UP_COMPLETE_LISTENER); + + // 切换完成后的监听 + EventDispatcher.listen(WorkspaceEvent.AfterSwitch, AFTER_SWITCH_LISTENER); + + // 内置服务器监听 + EventDispatcher.listen(EmbedServerEvent.BeforeStart, BEFORE_START_LISTENER); + EventDispatcher.listen(EmbedServerEvent.AfterStart, AFTER_START_LISTENER); + } + + private void stopListen() { + + EventDispatcher.stopListen(START_UP_COMPLETE_LISTENER); + EventDispatcher.stopListen(AFTER_SWITCH_LISTENER); + EventDispatcher.stopListen(BEFORE_START_LISTENER); + EventDispatcher.stopListen(AFTER_START_LISTENER); + } + private enum DetectorProcess { /** diff --git a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java index 14210b8fb2..5b471f337e 100644 --- a/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java +++ b/designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java @@ -1,6 +1,6 @@ package com.fr.env.detect.thowable; -import com.fr.log.FineLoggerFactory; +import com.fr.general.FRLogger; import com.fr.log.LogHandler; import com.fr.third.apache.logging.log4j.Level; import com.fr.third.apache.logging.log4j.core.Filter; @@ -57,11 +57,11 @@ public class ThrowableLogAppender extends AbstractAppender { public void enable() { - FineLoggerFactory.getLogger().addLogAppender(logHandler); + FRLogger.getLogger().addExtendLogAppender(logHandler); } public void disable() { - - FineLoggerFactory.getLogger().removeLogAppender(logHandler); + + FRLogger.getLogger().removeExtendLogAppender(logHandler); } }