|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
listen(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 切换完成后的监听
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 销毁,一般用在模块关闭中 |
|
|
|
|
*/ |
|
|
|
|
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 { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|