Browse Source

feat: REPORT-70565 设计器环境监测(jar包异常、finedb、杀毒软件)

提交部分检测的核心接口和部分实现。
无 UI 部分
feature/x
Harrison 3 years ago
parent
commit
f88195d402
  1. 19
      designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java
  2. 44
      designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java
  3. 95
      designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java
  4. 40
      designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java
  5. 25
      designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java
  6. 21
      designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java
  7. 40
      designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java
  8. 4
      designer-base/src/main/java/com/fr/env/detect/base/package-info.java
  9. 102
      designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java
  10. 22
      designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java
  11. 88
      designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java
  12. 24
      designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java
  13. 24
      designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java
  14. 19
      designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java
  15. 70
      designer-base/src/main/java/com/fr/env/detect/bean/Message.java
  16. 11
      designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java
  17. 26
      designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java
  18. 18
      designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java
  19. 85
      designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java
  20. 43
      designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java
  21. 53
      designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java
  22. 33
      designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java
  23. 31
      designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java
  24. 33
      designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java
  25. 28
      designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java
  26. 58
      designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableLogAppender.java
  27. 36
      designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java

19
designer-base/src/main/java/com/fr/env/detect/base/AbstractExceptionDetector.java vendored

@ -0,0 +1,19 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorType;
/**
* created by Harrison on 2022/05/13
**/
public abstract class AbstractExceptionDetector implements ExceptionDetector {
private DetectorType key;
public AbstractExceptionDetector(DetectorType key) {
this.key = key;
}
public DetectorType type() {
return key;
}
}

44
designer-base/src/main/java/com/fr/env/detect/base/CatchExceptionDetector.java vendored

@ -0,0 +1,44 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.env.detect.thowable.ThrowableStore;
import java.util.List;
/**
* created by Harrison on 2022/05/13
**/
public abstract class CatchExceptionDetector extends AbstractExceptionDetector {
private ThrowableStore throwableStore;
private ThrowableConverter throwableConverter;
public CatchExceptionDetector(DetectorType key, ThrowableStore throwableStore, ThrowableConverter throwableConverter) {
super(key);
this.throwableStore = throwableStore;
this.throwableConverter = throwableConverter;
}
public ThrowableStore getThrowableStore() {
return throwableStore;
}
public ThrowableConverter getThrowableConverter() {
return throwableConverter;
}
@Override
public DetectorResult detect() {
List<Throwable> throwableList = throwableStore.getAll();
for (Throwable throwable : throwableList) {
if (throwableConverter.accept(throwable)) {
return throwableConverter.convert(throwable);
}
}
return null;
}
}

95
designer-base/src/main/java/com/fr/env/detect/base/DetectorBridge.java vendored

@ -0,0 +1,95 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.thowable.ThrowableLogAppender;
import com.fr.value.NotNullLazyValue;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
/**
* created by Harrison on 2022/05/13
**/
public class DetectorBridge {
public static DetectorBridge getInstance() {
return DetectorBridgeHolder.INSTANCE;
}
private static class DetectorBridgeHolder {
private static final DetectorBridge INSTANCE = new DetectorBridge();
}
private final NotNullLazyValue<ThrowableBridge> throwableBridge = new NotNullLazyValue<ThrowableBridge>() {
@Override
protected @NotNull ThrowableBridge compute() {
return new ThrowableBridge();
}
};
private final NotNullLazyValue<DetectorManager> detectorManager = new NotNullLazyValue<DetectorManager>() {
@Override
protected @NotNull DetectorManager compute() {
return new DetectorManager();
}
};
private final AtomicBoolean hasStarted = new AtomicBoolean(false);
public void start() {
if (ExceptionDetectorConfig.getInstance().isOpen()) {
// 开始注册异常处理
ThrowableLogAppender.getInstance().enable();
hasStarted.set(true);
}
}
public void stop() {
if (hasStarted.compareAndSet(true, false)) {
// 关闭异常处理
ThrowableLogAppender.getInstance().disable();
}
}
/**
* 执行-检测异常
*
* @return 能够检测出的异常情况
*/
public Stream<DetectorResult> detect() {
return detectorManager.getValue().detect();
}
/**
* 针对某一项进行检测
*
* @param type 检测类型
* @return 检测结果
*/
public Optional<DetectorResult> detect(DetectorType type) {
return detectorManager.getValue().detect(type);
}
/**
* 执行-捕获异常
*
* @param throwable 异常
* @return 检测结果
*/
public Optional<DetectorResult> convert(Throwable throwable) {
return throwableBridge.getValue().convert(throwable);
}
}

40
designer-base/src/main/java/com/fr/env/detect/base/DetectorManager.java vendored

@ -0,0 +1,40 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.bean.DetectorResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
/**
* created by Harrison on 2022/05/24
**/
class DetectorManager {
private List<ExceptionDetector> detectors = new ArrayList<>();
public void register(ExceptionDetector detector) {
if (detector != null) {
detectors.add(detector);
}
}
public Stream<DetectorResult> detect() {
return detectors.stream()
.map(ExceptionDetector::detect)
.filter(Objects::nonNull);
}
public Optional<DetectorResult> detect(DetectorType type) {
return detectors.stream()
.filter((detector -> type == detector.type()))
.findFirst()
.map(ExceptionDetector::detect);
}
}

25
designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetector.java vendored

@ -0,0 +1,25 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.bean.DetectorResult;
/**
* created by Harrison on 2022/05/13
**/
public interface ExceptionDetector {
/**
* 检测类型
*
* @return TYPE
*/
DetectorType type();
/**
* 检测结果
*
* @return 结果
*/
DetectorResult detect();
}

21
designer-base/src/main/java/com/fr/env/detect/base/ExceptionDetectorConfig.java vendored

@ -0,0 +1,21 @@
package com.fr.env.detect.base;
/**
* created by Harrison on 2022/05/13
**/
public class ExceptionDetectorConfig {
public static ExceptionDetectorConfig getInstance() {
return ExceptionDetectorConfigHolder.INSTANCE;
}
private static class ExceptionDetectorConfigHolder {
private static final ExceptionDetectorConfig INSTANCE = new ExceptionDetectorConfig();
}
public boolean isOpen() {
return true;
}
}

40
designer-base/src/main/java/com/fr/env/detect/base/ThrowableBridge.java vendored

@ -0,0 +1,40 @@
package com.fr.env.detect.base;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.thowable.ThrowableConverter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* created by Harrison on 2022/05/13
**/
class ThrowableBridge {
private List<ThrowableConverter> throwableConverters = new ArrayList<>();
public void register(ThrowableConverter throwableConverter) {
if (throwableConverter != null) {
throwableConverters.add(throwableConverter);
}
}
/**
* throwable 转化成检测的结果
*
* @param throwable 异常
* @return 结果
*/
public Optional<DetectorResult> convert(Throwable throwable) {
return throwableConverters
.stream()
.filter((e) -> e.accept(throwable))
.map((e) -> e.convert(throwable))
.filter(Objects::nonNull)
.findFirst();
}
}

4
designer-base/src/main/java/com/fr/env/detect/base/package-info.java vendored

@ -0,0 +1,4 @@
/**
* 设计器环境检测 {@see https://kms.fineres.com/pages/viewpage.action?pageId=388333688}
*/
package com.fr.env.detect.base;

102
designer-base/src/main/java/com/fr/env/detect/bean/DetectorResult.java vendored

@ -0,0 +1,102 @@
package com.fr.env.detect.bean;
import org.jetbrains.annotations.Nullable;
/**
* 检测结果
*
* created by Harrison on 2022/05/13
**/
public class DetectorResult {
private DetectorType type;
private DetectorStatus status;
private ExceptionTips tips;
private ExceptionSolution solution;
private ExceptionLog exceptionLog;
public DetectorResult(DetectorType type, ExceptionTips tips, ExceptionSolution solution, ExceptionLog exceptionLog) {
this.type = type;
this.tips = tips;
this.solution = solution;
this.exceptionLog = exceptionLog;
}
public DetectorType getType() {
return type;
}
public DetectorStatus getStatus() {
return status;
}
@Nullable
public ExceptionTips getTips() {
return tips;
}
@Nullable
public ExceptionSolution getSolution() {
return solution;
}
@Nullable
public ExceptionLog getExceptionLog() {
return exceptionLog;
}
public static DetectorResultBuilder builder() {
return new DetectorResultBuilder();
}
public static final class DetectorResultBuilder {
private DetectorType type;
private DetectorStatus status;
private ExceptionTips tips;
private ExceptionSolution solution;
private ExceptionLog exceptionLog;
private DetectorResultBuilder() {
}
public DetectorResultBuilder withType(DetectorType type) {
this.type = type;
return this;
}
public DetectorResultBuilder withStatus(DetectorStatus status) {
this.status = status;
return this;
}
public DetectorResultBuilder withTips(ExceptionTips tips) {
this.tips = tips;
return this;
}
public DetectorResultBuilder withSolution(ExceptionSolution solution) {
this.solution = solution;
return this;
}
public DetectorResultBuilder withExceptionLog(ExceptionLog exceptionLog) {
this.exceptionLog = exceptionLog;
return this;
}
public DetectorResult build() {
DetectorResult detectorResult = new DetectorResult(type, tips, solution, exceptionLog);
detectorResult.status = this.status;
return detectorResult;
}
}
}

22
designer-base/src/main/java/com/fr/env/detect/bean/DetectorStatus.java vendored

@ -0,0 +1,22 @@
package com.fr.env.detect.bean;
/**
* created by Harrison on 2022/05/25
**/
public enum DetectorStatus {
/**
* 成功
*/
SUCCESS,
/**
* 失败
*/
FAILED,
/**
* 异常
*/
UNKNOWN
}

88
designer-base/src/main/java/com/fr/env/detect/bean/DetectorType.java vendored

@ -0,0 +1,88 @@
package com.fr.env.detect.bean;
/**
* 检测的原生数据
*
* created by Harrison on 2022/05/13
**/
public enum DetectorType {
/**
* 缺少 JAR
*/
LACK_OF_JAR(Kind.JAR, WorkType.LOCAL),
/**
* JAR 包版本不一致
*/
JAR_IN_CONSISTENCE(Kind.JAR, WorkType.SIMPLE),
/**
* JAR 包冲突
*/
JAR_CONFLICT(Kind.JAR, WorkType.REMOTE),
/**
* FineDB 权限问题
*/
FINE_DB_PERMISSION(Kind.FINE_DB, WorkType.LOCAL),
/**
* FineDB
*/
FINE_DB_LOCKED(Kind.FINE_DB, WorkType.LOCAL),
/**
* FineDB 脏数据
*/
FINE_DB_DIRTY(Kind.FINE_DB, WorkType.SIMPLE)
;
private final Kind kind;
private final WorkType workType;
DetectorType(Kind kind, WorkType workType) {
this.kind = kind;
this.workType = workType;
}
public Kind getKind() {
return kind;
}
public WorkType getWorkType() {
return workType;
}
public enum Kind {
/**
* JAR 类型
*/
JAR,
/**
* FineDB 类型
*/
FINE_DB
}
public enum WorkType {
/**
* 本地
*/
LOCAL,
/**
* 远程
*/
REMOTE,
/**
* 全部
*/
SIMPLE
}
}

24
designer-base/src/main/java/com/fr/env/detect/bean/ExceptionLog.java vendored

@ -0,0 +1,24 @@
package com.fr.env.detect.bean;
/**
* created by Harrison on 2022/05/13
**/
public class ExceptionLog {
private final String errorCode;
private final String locale;
public ExceptionLog(String errorCode, String locale) {
this.errorCode = errorCode;
this.locale = locale;
}
public String getErrorCode() {
return errorCode;
}
public String getLocale() {
return locale;
}
}

24
designer-base/src/main/java/com/fr/env/detect/bean/ExceptionSolution.java vendored

@ -0,0 +1,24 @@
package com.fr.env.detect.bean;
/**
* created by Harrison on 2022/05/13
**/
public class ExceptionSolution {
private Message message;
private SolutionAction action;
public ExceptionSolution(Message message, SolutionAction action) {
this.message = message;
this.action = action;
}
public Message getMessage() {
return message;
}
public SolutionAction getAction() {
return action;
}
}

19
designer-base/src/main/java/com/fr/env/detect/bean/ExceptionTips.java vendored

@ -0,0 +1,19 @@
package com.fr.env.detect.bean;
/**
* 异常提示
*
* created by Harrison on 2022/05/13
**/
public class ExceptionTips {
private Message message;
public ExceptionTips(Message message) {
this.message = message;
}
public Message getMessage() {
return message;
}
}

70
designer-base/src/main/java/com/fr/env/detect/bean/Message.java vendored

@ -0,0 +1,70 @@
package com.fr.env.detect.bean;
/**
* created by Harrison on 2022/05/24
**/
public interface Message {
/**
* 消息类型
*
* @return 类型
*/
Type getType();
enum Type {
/**
* 简单
*/
SIMPLE,
/**
* 链接
*/
LINK
}
class Simple implements Message {
private String message;
public Simple(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
@Override
public Type getType() {
return Type.SIMPLE;
}
}
class Link implements Message {
private String text;
private String link;
public Link(String text, String link) {
this.text = text;
this.link = link;
}
public String getText() {
return text;
}
public String getLink() {
return link;
}
@Override
public Type getType() {
return Type.LINK;
}
}
}

11
designer-base/src/main/java/com/fr/env/detect/bean/SolutionAction.java vendored

@ -0,0 +1,11 @@
package com.fr.env.detect.bean;
/**
* created by Harrison on 2022/05/24
**/
public interface SolutionAction {
String name();
void run();
}

26
designer-base/src/main/java/com/fr/env/detect/exception/DetectorException.java vendored

@ -0,0 +1,26 @@
package com.fr.env.detect.exception;
/**
* created by Harrison on 2022/05/25
**/
public class DetectorException extends RuntimeException {
public DetectorException() {
}
public DetectorException(String message) {
super(message);
}
public DetectorException(String message, Throwable cause) {
super(message, cause);
}
public DetectorException(Throwable cause) {
super(cause);
}
public DetectorException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

18
designer-base/src/main/java/com/fr/env/detect/impl/HsqlDirtyDetector.java vendored

@ -0,0 +1,18 @@
package com.fr.env.detect.impl;
import com.fr.env.detect.base.CatchExceptionDetector;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.thowable.ThrowableStore;
import com.fr.env.detect.impl.converter.FineDbDirtyConverter;
/**
* created by Harrison on 2022/05/25
**/
public class HsqlDirtyDetector extends CatchExceptionDetector {
public HsqlDirtyDetector(ThrowableStore throwableStore) {
super(DetectorType.FINE_DB_DIRTY, throwableStore, new FineDbDirtyConverter());
}
}

85
designer-base/src/main/java/com/fr/env/detect/impl/JarInconsistentDetector.java vendored

@ -0,0 +1,85 @@
package com.fr.env.detect.impl;
import com.fr.env.detect.base.AbstractExceptionDetector;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.env.detect.exception.DetectorException;
import com.fr.general.build.BuildInfo;
import com.fr.general.build.BuildInfoOperator;
import com.fr.general.build.BuildInfoManager;
import com.fr.stable.StringUtils;
import com.fr.third.guava.collect.MapDifference;
import com.fr.third.guava.collect.Maps;
import com.fr.workspace.WorkContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* created by Harrison on 2022/05/25
**/
public class JarInconsistentDetector extends AbstractExceptionDetector {
public JarInconsistentDetector() {
super(DetectorType.JAR_IN_CONSISTENCE);
}
@Override
public DetectorResult detect() {
DetectorResult.DetectorResultBuilder builder = DetectorResult.builder();
// 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包
BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class);
List<BuildInfo> buildInfos = buildInfoOperator.getBuildInfos();
if (WorkContext.getCurrent().isLocal()) {
String designerBuild = buildInfos.stream()
.filter(this::isDesignerJar)
.map(BuildInfo::getGroupBuild)
.filter(StringUtils::isNotEmpty)
.findFirst()
.orElseThrow(DetectorException::new);
List<BuildInfo> inConsistentInfos = buildInfos.stream()
.filter((e) -> !StringUtils.equals(designerBuild, e.getGroupBuild()))
.collect(Collectors.toList());
} else {
// 远程情况
List<BuildInfo> localInfos = BuildInfoManager.getInstance().getInfos();
Map<String, String> localMap = groupBy(localInfos);
List<BuildInfo> remoteInfos = buildInfos;
Map<String, String> remoteMap = groupBy(remoteInfos);
MapDifference<String, String> difference = Maps.difference(localMap, remoteMap);
// 两边都有的 JAR 的不同之处
Map<String, String> diffInCommon = difference.entriesInCommon();
}
return builder.build();
}
private boolean isDesignerJar(BuildInfo info) {
return StringUtils.contains(info.getJar(), "fine-report-designer");
}
private Map<String, String> groupBy(List<BuildInfo> localInfos) {
Map<String, String> localMap = new HashMap<>();
for (BuildInfo localInfo : localInfos) {
String jar = localInfo.getJar();
String groupContent = localInfo.getGroupBuild();
localMap.put(jar, groupContent);
}
return localMap;
}
}

43
designer-base/src/main/java/com/fr/env/detect/impl/JarLackDetector.java vendored

@ -0,0 +1,43 @@
package com.fr.env.detect.impl;
import com.fr.env.detect.base.AbstractExceptionDetector;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.bean.DetectorType;
import com.fr.general.build.BuildInfo;
import com.fr.general.build.BuildInfoOperator;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import java.util.List;
/**
* created by Harrison on 2022/05/24
**/
public class JarLackDetector extends AbstractExceptionDetector {
public JarLackDetector() {
super(DetectorType.LACK_OF_JAR);
}
@Override
public DetectorResult detect() {
DetectorResult.DetectorResultBuilder builder = DetectorResult.builder();
// 检测有哪些 JAR 包, 当前是否缺少对应的 JAR 包
BuildInfoOperator buildInfoOperator = WorkContext.getCurrent().get(BuildInfoOperator.class);
List<BuildInfo> buildInfos = buildInfoOperator.getBuildInfos();
for (BuildInfo buildInfo : buildInfos) {
String jar = buildInfo.getJar();
String buildContent = buildInfo.getGroupBuild();
boolean isLack = StringUtils.isEmpty(buildContent);
if (isLack) {
// 处理信息
}
}
return builder.build();
}
}

53
designer-base/src/main/java/com/fr/env/detect/impl/converter/ClassThrowableConvertor.java vendored

@ -0,0 +1,53 @@
package com.fr.env.detect.impl.converter;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.thowable.ThrowableConverter;
import javax.el.MethodNotFoundException;
import java.util.HashSet;
import java.util.Set;
/**
* 类抛出异常的转换
* created by Harrison on 2022/05/24
**/
public class ClassThrowableConvertor implements ThrowableConverter {
private Set<Class<?>> throwableClassSet = new HashSet<>();
private Set<Class<?>> throwableMethodSet = new HashSet<>();
public ClassThrowableConvertor() {
// 类异常
this.throwableClassSet.add(ClassNotFoundException.class);
this.throwableClassSet.add(NoClassDefFoundError.class);
this.throwableClassSet.add(ClassCastException.class);
this.throwableClassSet.add(IncompatibleClassChangeError.class);
// 方法异常
this.throwableMethodSet.add(MethodNotFoundException.class);
this.throwableMethodSet.add(NoSuchMethodException.class);
this.throwableMethodSet.add(NoSuchMethodError.class);
}
@Override
public boolean accept(Throwable throwable) {
Throwable sign = throwable;
while (sign != null) {
if (throwableClassSet.contains(sign.getClass()) || throwableMethodSet.contains(sign.getClass())) {
return true;
}
sign = sign.getCause();
}
return false;
}
@Override
public DetectorResult convert(Throwable throwable) {
// todo
return null;
}
}

33
designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbDirtyConverter.java vendored

@ -0,0 +1,33 @@
package com.fr.env.detect.impl.converter;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.third.org.hibernate.exception.GenericJDBCException;
import org.jetbrains.annotations.Nullable;
/**
* created by Harrison on 2022/05/25
**/
public class FineDbDirtyConverter implements ThrowableConverter {
@Override
public boolean accept(Throwable throwable) {
Throwable sign = throwable;
while (sign != null) {
if (sign instanceof GenericJDBCException) {
return true;
}
sign = sign.getCause();
}
return false;
}
@Override
public @Nullable DetectorResult convert(Throwable throwable) {
// 检测 Config
// todo
return null;
}
}

31
designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbLockedConverter.java vendored

@ -0,0 +1,31 @@
package com.fr.env.detect.impl.converter;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.third.org.hsqldb.HsqlException;
/**
* created by Harrison on 2022/05/24
**/
public class FineDbLockedConverter implements ThrowableConverter {
@Override
public boolean accept(Throwable throwable) {
Throwable sign = throwable;
while (sign != null) {
if (sign instanceof HsqlException) {
return true;
}
sign = sign.getCause();
}
return false;
}
@Override
public DetectorResult convert(Throwable throwable) {
// todo
return null;
}
}

33
designer-base/src/main/java/com/fr/env/detect/impl/converter/FineDbPermissionConverter.java vendored

@ -0,0 +1,33 @@
package com.fr.env.detect.impl.converter;
import com.fr.env.detect.bean.DetectorResult;
import com.fr.env.detect.thowable.ThrowableConverter;
import com.fr.third.org.hsqldb.HsqlException;
/**
* HSQL 下的权限检测
*
* created by Harrison on 2022/05/24
**/
public class FineDbPermissionConverter implements ThrowableConverter {
@Override
public boolean accept(Throwable throwable) {
Throwable sign = throwable;
while (sign != null) {
if (sign instanceof HsqlException) {
return true;
}
sign = sign.getCause();
}
return false;
}
@Override
public DetectorResult convert(Throwable throwable) {
// todo
return null;
}
}

28
designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableConverter.java vendored

@ -0,0 +1,28 @@
package com.fr.env.detect.thowable;
import com.fr.env.detect.bean.DetectorResult;
import org.jetbrains.annotations.Nullable;
/**
* created by Harrison on 2022/05/13
**/
public interface ThrowableConverter {
/**
* 是否支持该异常
*
* @param throwable 异常
* @return /
*/
boolean accept(Throwable throwable);
/**
* 将异常转化为结果
*
* @param throwable 异常
* @return 转化结果
*/
@Nullable
DetectorResult convert(Throwable throwable);
}

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

@ -0,0 +1,58 @@
package com.fr.env.detect.thowable;
import com.fr.log.FineLoggerFactory;
import com.fr.log.LogHandler;
import com.fr.third.apache.logging.log4j.Level;
import com.fr.third.apache.logging.log4j.core.Filter;
import com.fr.third.apache.logging.log4j.core.Layout;
import com.fr.third.apache.logging.log4j.core.LogEvent;
import com.fr.third.apache.logging.log4j.core.appender.AbstractAppender;
import com.fr.third.apache.logging.log4j.core.config.Property;
import java.io.Serializable;
/**
* created by Harrison on 2022/05/13
**/
public class ThrowableLogAppender extends AbstractAppender {
public ThrowableLogAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) {
super(name, filter, layout, ignoreExceptions, properties);
}
public static ThrowableLogAppender getInstance() {
return ExceptionLogAppenderHolder.INSTANCE;
}
private static class ExceptionLogAppenderHolder {
private static final ThrowableLogAppender INSTANCE = new ThrowableLogAppender("exception-detect", null, null, false, null);
}
private LogHandler<ThrowableLogAppender> logHandler = toHandler();
@Override
public void append(LogEvent logEvent) {
if (logEvent.getLevel() == Level.ERROR) {
Throwable thrown = logEvent.getThrown();
ThrowableStore.getInstance().add(thrown);
}
}
private LogHandler<ThrowableLogAppender> toHandler() {
final ThrowableLogAppender appender = this;
return () -> appender;
}
public void enable() {
FineLoggerFactory.getLogger().addLogAppender(logHandler);
}
public void disable() {
FineLoggerFactory.getLogger().removeLogAppender(logHandler);
}
}

36
designer-base/src/main/java/com/fr/env/detect/thowable/ThrowableStore.java vendored

@ -0,0 +1,36 @@
package com.fr.env.detect.thowable;
import java.util.ArrayList;
import java.util.List;
/**
* 异常存储中心
*
* created by Harrison on 2022/05/13
**/
public class ThrowableStore {
public static ThrowableStore getInstance() {
return ThrowableStoreHolder.INSTANCE;
}
private static class ThrowableStoreHolder {
private static final ThrowableStore INSTANCE = new ThrowableStore();
}
private List<Throwable> exceptions = new ArrayList<>();
public void add(Throwable throwable) {
if (throwable != null) {
exceptions.add(throwable);
}
}
public List<Throwable> getAll() {
return exceptions;
}
public void reset() {
exceptions.clear();
}
}
Loading…
Cancel
Save