From 4d01785829fe604bfa9828a1b0c8435a69536975 Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 13 Jun 2022 17:35:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-73396=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E3=80=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4fine-decision-11.0=EF=BC=8C=E8=A7=A6=E5=8F=91=E7=9A=84?= =?UTF-8?q?=E6=98=AF=E9=87=8D=E7=BD=AEfinedb=20=E9=80=9A=E8=BF=87=E5=AE=88?= =?UTF-8?q?=E6=8A=A4=E8=BF=9B=E7=A8=8B=EF=BC=8C=E5=A4=84=E7=90=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=E8=AE=BE=E8=AE=A1=E5=99=A8=E5=90=AF=E5=8A=A8=E4=B8=8D?= =?UTF-8?q?=E4=BA=86=E4=B8=94=E6=B2=A1=E6=9C=89=E7=9B=B4=E6=8E=A5=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E7=9A=84=E5=9C=BA=E6=99=AF=E3=80=82=20=EF=BC=88mac=20?= =?UTF-8?q?=E4=B8=8B=E8=BF=98=E6=98=AF=E6=9C=89=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=AE=88=E6=8A=A4=E8=BF=9B=E7=A8=8B=E4=B8=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20mac?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/env/detect/EnvDetectorCenter.java | 13 +++- .../main/java/com/fr/exit/DesignerExiter.java | 66 +++++++++++++++++-- .../com/fr/start/DesignerSubListener.java | 6 +- .../com/fr/start/DesignerSuperListener.java | 3 +- 4 files changed, 80 insertions(+), 8 deletions(-) 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 e73aa673b6..37e01f788a 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 @@ -54,7 +54,6 @@ public class EnvDetectorCenter { } }; - private final Listener START_UP_COMPLETE_LISTENER = new Listener() { @Override @@ -196,6 +195,18 @@ public class EnvDetectorCenter { .collect(Collectors.toList()); } + /** + * 预期外的终止 + * + * @return 检测结果 + */ + public List terminateUnexpectedly() { + + Stream resultStream = DetectorBridge.getInstance().detect(); + return resultStream + .filter((e) -> e.getStatus() == DetectorStatus.EXCEPTION) + .collect(Collectors.toList()); + } private void listen() { diff --git a/designer-base/src/main/java/com/fr/exit/DesignerExiter.java b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java index 3acb3cf8a9..babadc5fe8 100644 --- a/designer-base/src/main/java/com/fr/exit/DesignerExiter.java +++ b/designer-base/src/main/java/com/fr/exit/DesignerExiter.java @@ -17,7 +17,9 @@ import com.fr.log.FineLoggerFactory; import com.fr.process.engine.core.FineProcessContext; import com.fr.process.engine.core.FineProcessEngineEvent; +import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; /** * @author hades @@ -32,16 +34,43 @@ public class DesignerExiter { return INSTANCE; } + /** + * 预期外的退出 + * 首先检测是否有检测到的异常。如果没有,则运行默认行为 + * + * @param defaultAction 默认行为 + */ + public void exitUnexpectedly(Runnable defaultAction) { + + // 尝试进行检测 + List results = runAndGet(() -> EnvDetectorCenter.getInstance().terminateUnexpectedly(), ArrayList::new); + try { + if (!Collections.isEmpty(results)) { + showNewExitDialog(results); + } + } finally { + // 正常的话上面会直接退出, system.exit(0) + // 只有异常,或者不命中,才会走到这里 + defaultAction.run(); + } + } + public void exit(Throwable throwable) { - FineLoggerFactory.getLogger().error(throwable.getMessage(), throwable); + doThrowableAction(() -> { + FineLoggerFactory.getLogger().error(throwable.getMessage(), throwable); + }, () -> { + throwable.printStackTrace(System.err); + }); - StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), - DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), - throwable.getMessage()); + doThrowableAction(() -> { + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.UNEXCEPTED_START_FAILED.getId(), + DesignerErrorMessage.UNEXCEPTED_START_FAILED.getMessage(), + throwable.getMessage()); + }); // 尝试进行检测 - List results = EnvDetectorCenter.getInstance().terminate(throwable); + List results = runAndGet(() -> EnvDetectorCenter.getInstance().terminate(throwable), ArrayList::new); if (Collections.isEmpty(results)) { // 为空,则 @@ -89,4 +118,31 @@ public class DesignerExiter { private void beforeExit() { DesignerWorkspaceGenerator.stop(); } + + /* 忽视异常的调用方法 */ + + private void doThrowableAction(Runnable runnable) { + doThrowableAction(runnable, null); + } + + private void doThrowableAction(Runnable runnable, Runnable defaultRunnable) { + + try { + runnable.run(); + } catch (Throwable ignore) { + if (defaultRunnable != null) { + defaultRunnable.run(); + } + } + } + + private T runAndGet(Supplier supplier, Supplier defaultCallable) { + + try { + return supplier.get(); + } catch (Exception ignore) { + return defaultCallable.get(); + } + } + } diff --git a/designer-realize/src/main/java/com/fr/start/DesignerSubListener.java b/designer-realize/src/main/java/com/fr/start/DesignerSubListener.java index c76e6b0728..52d364f6cd 100644 --- a/designer-realize/src/main/java/com/fr/start/DesignerSubListener.java +++ b/designer-realize/src/main/java/com/fr/start/DesignerSubListener.java @@ -4,6 +4,7 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.event.Event; import com.fr.event.Listener; import com.fr.event.Null; +import com.fr.exit.DesignerExiter; import com.fr.process.engine.core.CarryMessageEvent; import com.fr.process.engine.core.FineProcessContext; import com.fr.process.engine.core.FineProcessEngineEvent; @@ -31,7 +32,10 @@ public class DesignerSubListener { @Override public void on(Event event, Null param) { if (DesignerContext.getDesignerFrame() == null || !DesignerContext.getDesignerFrame().isShowing()) { - FineProcessContext.getParentPipe().fire(new CarryMessageEvent(DesignerProcessType.INSTANCE.obtain())); + + DesignerExiter.getInstance().exitUnexpectedly(() -> { + FineProcessContext.getParentPipe().fire(new CarryMessageEvent(DesignerProcessType.INSTANCE.obtain())); + }); } } }); diff --git a/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java b/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java index f5c9174649..2f2530e599 100644 --- a/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java +++ b/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; public class DesignerSuperListener { private static final DesignerSuperListener INSTANCE = new DesignerSuperListener(); - private static final int ONCE_DELAY = 180; + private static final int ONCE_DELAY = 30; private static final int FIXED_DELAY = 0; private static final int FIXED_FREQ = 2; @@ -95,6 +95,7 @@ public class DesignerSuperListener { public void run() { cancel = true; ProcessEventPipe pipe = process.getPipe(); + // 确认设计器是否启动完成 pipe.fire(FineProcessEngineEvent.READY); if (StringUtils.isNotEmpty(pipe.info())) { frameReport(); From 5398db8af809b7aaaba73621a0c6052cc3efabdd Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 13 Jun 2022 17:36:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-73396=E3=80=90=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E7=8E=AF=E5=A2=83=E7=9B=91=E6=B5=8B=E3=80=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4fine-decision-11.0=EF=BC=8C=E8=A7=A6=E5=8F=91=E7=9A=84?= =?UTF-8?q?=E6=98=AF=E9=87=8D=E7=BD=AEfinedb=20=E6=81=A2=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/start/DesignerSuperListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java b/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java index 2f2530e599..ee4b265022 100644 --- a/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java +++ b/designer-realize/src/main/java/com/fr/start/DesignerSuperListener.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; public class DesignerSuperListener { private static final DesignerSuperListener INSTANCE = new DesignerSuperListener(); - private static final int ONCE_DELAY = 30; + private static final int ONCE_DELAY = 180; private static final int FIXED_DELAY = 0; private static final int FIXED_FREQ = 2;