mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-08-31 05:49:05 +00:00
fix(parser): harden runtime resource handling
This commit is contained in:
@@ -7,12 +7,15 @@ import org.slf4j.LoggerFactory;
|
||||
import cn.qaiu.parser.custom.CustomParserRegistry;
|
||||
|
||||
public class WebClientVertxInit {
|
||||
private Vertx vertx = null;
|
||||
private volatile Vertx vertx = null;
|
||||
private static final WebClientVertxInit INSTANCE = new WebClientVertxInit();
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WebClientVertxInit.class);
|
||||
|
||||
public static void init(Vertx vx) {
|
||||
public static synchronized void init(Vertx vx) {
|
||||
if (vx == null) {
|
||||
throw new IllegalArgumentException("Vertx instance must not be null");
|
||||
}
|
||||
INSTANCE.vertx = vx;
|
||||
|
||||
// 自动加载JavaScript解析器脚本
|
||||
@@ -23,18 +26,10 @@ public class WebClientVertxInit {
|
||||
}
|
||||
}
|
||||
|
||||
public static Vertx get() {
|
||||
public static synchronized Vertx get() {
|
||||
if (INSTANCE.vertx == null) {
|
||||
log.info("getVertx: Vertx实例不存在, 创建Vertx实例.");
|
||||
INSTANCE.vertx = Vertx.vertx();
|
||||
|
||||
// 如果Vertx实例是新创建的,也尝试加载JavaScript脚本
|
||||
try {
|
||||
CustomParserRegistry.autoLoadJsScripts();
|
||||
} catch (Exception e) {
|
||||
log.warn("自动加载JavaScript解析器脚本失败", e);
|
||||
}
|
||||
throw new IllegalStateException("Vertx实例未初始化,请先调用 WebClientVertxInit.init(vertx)");
|
||||
}
|
||||
return INSTANCE.vertx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user