Browse Source

REPORT-72831 设计器环境检测-设计器正常的,但是抛出异常了

日志这部分有些问题。
core.xml 里面的 log 加载后,会覆盖这里的 log 配置。
添加一个接口。提供默认的 appender
feature/x
Harrison 3 years ago
parent
commit
1a1b76e6ec
  1. 2
      designer-base/src/main/java/com/fr/env/EnvPrepare.java
  2. 121
      designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java
  3. 8
      designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java

2
designer-base/src/main/java/com/fr/env/EnvPrepare.java vendored

@ -22,6 +22,6 @@ public class EnvPrepare extends Activator {
@Override
public void stop() {
EnvDetectorCenter.getInstance().destroy();
}
}

121
designer-base/src/main/java/com/fr/env/detect/EnvDetectorCenter.java vendored

@ -37,6 +37,43 @@ import java.util.stream.Stream;
**/
public class EnvDetectorCenter {
private final Listener<Null> AFTER_START_LISTENER = new Listener<Null>() {
@Override
public void on(Event event, Null param) {
if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) {
stop();
}
}
};
private final Listener<Null> BEFORE_START_LISTENER = new Listener<Null>() {
@Override
public void on(Event event, Null param) {
PROCESS.set(DetectorProcess.SERVER_LAUNCH);
start();
}
};
private final Listener<Null> START_UP_COMPLETE_LISTENER = new Listener<Null>() {
@Override
public void on(Event event, Null param) {
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) {
stop();
}
}
};
private final Listener<Workspace> AFTER_SWITCH_LISTENER = new Listener<Workspace>() {
@Override
public void on(Event event, Workspace param) {
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) {
stop();
}
}
};
private final AtomicReference<DetectorProcess> 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<DetectorProcess> 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<Null>() {
@Override
public void on(Event event, Null param) {
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) {
stop();
}
}
});
// 切换完成后的监听
EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener<Workspace>() {
@Override
public void on(Event event, Workspace param) {
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) {
stop();
}
}
});
// 打开内置服务器
EventDispatcher.listen(EmbedServerEvent.BeforeStart, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
PROCESS.set(DetectorProcess.SERVER_LAUNCH);
start();
}
});
EventDispatcher.listen(EmbedServerEvent.AfterStart, new Listener<Null>() {
@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 {
/**

8
designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java vendored

@ -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);
}
}

Loading…
Cancel
Save