From 495f0e3029608828381a7000d7fe3d3f23564482 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Mon, 29 May 2023 05:45:36 +0200 Subject: [PATCH] Move BisqProcess Pid fetching to separate class --- network/tor/src/main/java/bisq/tor/Pid.java | 27 +++++++++++++++++++ .../src/main/java/bisq/tor/TorBootstrap.java | 11 ++------ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 network/tor/src/main/java/bisq/tor/Pid.java diff --git a/network/tor/src/main/java/bisq/tor/Pid.java b/network/tor/src/main/java/bisq/tor/Pid.java new file mode 100644 index 0000000000..dbda455b18 --- /dev/null +++ b/network/tor/src/main/java/bisq/tor/Pid.java @@ -0,0 +1,27 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.tor; + +import java.lang.management.ManagementFactory; + +public class Pid { + public static String getMyPid() { + String processName = ManagementFactory.getRuntimeMXBean().getName(); + return processName.split("@")[0]; + } +} diff --git a/network/tor/src/main/java/bisq/tor/TorBootstrap.java b/network/tor/src/main/java/bisq/tor/TorBootstrap.java index 4045b7e87e..d2798601a6 100644 --- a/network/tor/src/main/java/bisq/tor/TorBootstrap.java +++ b/network/tor/src/main/java/bisq/tor/TorBootstrap.java @@ -23,7 +23,6 @@ import java.io.File; import java.io.IOException; -import java.lang.management.ManagementFactory; import java.nio.file.Path; import java.util.Scanner; import java.util.concurrent.atomic.AtomicBoolean; @@ -75,7 +74,8 @@ void deleteVersionFile() { //////////////////////////////////////////////////////////////////////////////////////////////////// private Process startTorProcess() throws IOException { - String ownerPid = getBisqProcessPid(); + String ownerPid = Pid.getMyPid(); + log.debug("Owner pid {}", ownerPid); torInstallationFiles.writePidToDisk(ownerPid); TorProcessConfig torProcessConfig = TorProcessConfig.builder() @@ -90,13 +90,6 @@ private Process startTorProcess() throws IOException { return process; } - private String getBisqProcessPid() { - String processName = ManagementFactory.getRuntimeMXBean().getName(); - String ownerPid = processName.split("@")[0]; - log.debug("Owner pid {}", ownerPid); - return ownerPid; - } - private int waitForControlPort(Process torProcess) { AtomicInteger controlPort = new AtomicInteger(); AtomicInteger scannedLines = new AtomicInteger(0);