|
|
|
@ -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<DetectorResult> 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<DetectorResult> results = EnvDetectorCenter.getInstance().terminate(throwable); |
|
|
|
|
List<DetectorResult> 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> T runAndGet(Supplier<T> supplier, Supplier<T> defaultCallable) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
return supplier.get(); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
return defaultCallable.get(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|