Skip to content

Commit

Permalink
Merge pull request #914 from alvasw/move_bisq_process_pid_fetching_to…
Browse files Browse the repository at this point in the history
…_separate_class

Move BisqProcess Pid fetching to separate class
  • Loading branch information
alvasw committed Jun 6, 2023
2 parents 1dc6544 + 495f0e3 commit 5d6fe5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
27 changes: 27 additions & 0 deletions network/tor/src/main/java/bisq/tor/Pid.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

package bisq.tor;

import java.lang.management.ManagementFactory;

public class Pid {
public static String getMyPid() {
String processName = ManagementFactory.getRuntimeMXBean().getName();
return processName.split("@")[0];
}
}
11 changes: 2 additions & 9 deletions network/tor/src/main/java/bisq/tor/TorBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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;
Expand Down Expand Up @@ -79,7 +78,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()
Expand All @@ -94,13 +94,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);
Expand Down

0 comments on commit 5d6fe5a

Please sign in to comment.