From 540fbd65f8b815d118ba630082c8d5ffc4d463c7 Mon Sep 17 00:00:00 2001 From: garvey-wong Date: Fri, 10 Jun 2022 11:48:32 +0800 Subject: [PATCH] feat: enable ContractPrinter by isDebug --- .../java/org/bdware/sc/ContractClient.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bdware/sc/ContractClient.java b/src/main/java/org/bdware/sc/ContractClient.java index 42ee4e8..43954f2 100644 --- a/src/main/java/org/bdware/sc/ContractClient.java +++ b/src/main/java/org/bdware/sc/ContractClient.java @@ -22,6 +22,7 @@ import org.bdware.sc.util.JsonUtil; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.Field; import java.util.*; @@ -285,7 +286,8 @@ public class ContractClient { PrintStream printStream = new PrintStream(process.getOutputStream()); printStream.println("CP PID:" + pid); printStream.close(); - Scanner sc = new Scanner(process.getInputStream()); + InputStream processInputStream = process.getInputStream(); + Scanner sc = new Scanner(processInputStream); String status = null; while (sc.hasNext()) { status = sc.nextLine(); @@ -315,10 +317,16 @@ public class ContractClient { ContractManager.cPort.updateDb(port, true); get = new SocketGet("127.0.0.1", port); get.syncGet("", "setDBInfo", ContractManager.dbPath); - String tagA = (ps == System.out ? "[Contract_" + port + "_out] " : ""); - String tagB = (ps == System.out ? "[Contract_" + port + "_err] " : ""); - outputTracer.track(process, sc, tagA, ps); - errorTracer.track(process, new Scanner(process.getErrorStream()), tagB, ps); + if (isDebug) { + String tagA = (ps == System.out ? "[Contract_" + port + "_out] " : ""); + String tagB = (ps == System.out ? "[Contract_" + port + "_err] " : ""); + outputTracer.track(process, sc, tagA, ps); + errorTracer.track(process, new Scanner(process.getErrorStream()), tagB, ps); + } else { + // 关闭流,否则缓冲区打满会阻塞进程 + processInputStream.close(); + sc.close(); + } get.syncGet("", "registerMangerPort", String.valueOf(ContractManager.cPort.getCMPort())); if (isBundlePath(contractMeta.contract.getScriptStr())) {