From eff8d37278e3e502e8691127b2e3a7f7171f52dd Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Mon, 23 Dec 2024 16:16:07 +0800 Subject: [PATCH] update docker files --- build.gradle | 2 +- .../base/org/bdware/sc/conn/SyncResult.java | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c17136f..db627bd 100644 --- a/build.gradle +++ b/build.gradle @@ -51,7 +51,7 @@ dependencies { //api 'org.apache.velocity:velocity-engine-core:2.3' api 'org.rocksdb:rocksdbjni:7.3.1' testImplementation 'junit:junit:4.13.2' - implementation 'org.bdware.doip:doip-sdk:1.5.5' + implementation 'org.bdware.doip:doip-sdk:1.5.6' } group = "org.bdware.sc" diff --git a/src/main/base/org/bdware/sc/conn/SyncResult.java b/src/main/base/org/bdware/sc/conn/SyncResult.java index 9083104..836c9b0 100644 --- a/src/main/base/org/bdware/sc/conn/SyncResult.java +++ b/src/main/base/org/bdware/sc/conn/SyncResult.java @@ -4,6 +4,8 @@ import com.google.gson.JsonPrimitive; import io.netty.util.HashedWheelTimer; import io.netty.util.Timeout; import io.netty.util.TimerTask; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.bdware.sc.ContractResult; import org.bdware.sc.ContractResult.Status; import org.bdware.sc.util.JsonUtil; @@ -18,6 +20,27 @@ public class SyncResult { new HashedWheelTimer(Executors.defaultThreadFactory(), 5, TimeUnit.MILLISECONDS, 2); static final String TimeoutStr = JsonUtil.toJson(new ContractResult(Status.Error, new JsonPrimitive("Timeout!"))); + static long syncTime = getSyncTime(); + static Logger LOGGER = LogManager.getLogger(SyncResult.class); + + private static long getSyncTime() { + long retVal; + String timeout = System.getenv("BDW_SOCKET_TIMEOUT"); + if (timeout == null || timeout.isEmpty()) { + retVal = 10 * 1000; // 10秒转换为毫秒 + } else { + try { + retVal = Long.parseLong(timeout); // 将秒转换为毫秒 + } catch (NumberFormatException e) { + // 如果环境变量不是有效的数字,返回默认值 + e.printStackTrace(); + retVal = 10 * 1000; + } + } + LOGGER.info("SocketGet Timeout=" + retVal); + return retVal; + } + // private static final org.apache.logging.log4j.Logger LOGGER = // org.apache.logging.log4j.LogManager.getLogger(SyncResult.class); Map waitObj = new ConcurrentHashMap<>(); @@ -56,7 +79,7 @@ public class SyncResult { synchronized (cb) { try { if (waitObj.containsKey(requestID)) - cb.wait(10000L); + cb.wait(syncTime); } catch (InterruptedException e) { e.printStackTrace(); }