From 9f22fe2450c8ad10e98b47db6e8b4e7f6e7af21a Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 19 Jul 2016 16:27:59 +0200 Subject: [PATCH] Add missing master thread --- .../io/bitsquare/headless/HeadlessMain.java | 15 ++++++++++++--- .../java/io/bitsquare/monitor/MonitorMain.java | 15 ++++++++++++--- .../io/bitsquare/seednode/SeedNodeMain.java | 17 +++++++++++++---- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java b/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java index f033d4374a..933b310b50 100644 --- a/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java +++ b/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java @@ -17,8 +17,10 @@ package io.bitsquare.headless; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.bitsquare.app.BitsquareEnvironment; import io.bitsquare.app.BitsquareExecutable; +import io.bitsquare.common.UserThread; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -26,6 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Scanner; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import static io.bitsquare.app.BitsquareEnvironment.*; @@ -35,9 +39,14 @@ public class HeadlessMain extends BitsquareExecutable { private boolean isStopped; public static void main(String[] args) throws Exception { + final ThreadFactory threadFactory = new ThreadFactoryBuilder() + .setNameFormat("HeadlessMain") + .setDaemon(true) + .build(); + UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory)); + // We don't want to do the full argument parsing here as that might easily change in update versions // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR - BitsquareEnvironment.setDefaultAppName("Bitsquare_headless"); OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -71,7 +80,7 @@ public class HeadlessMain extends BitsquareExecutable { @Override protected void doExecute(OptionSet options) { Headless.setEnvironment(new BitsquareEnvironment(options)); - headless = new Headless(); + UserThread.execute(() -> headless = new Headless()); while (!isStopped) { try { @@ -79,7 +88,7 @@ public class HeadlessMain extends BitsquareExecutable { while (scanner.hasNextLine()) { String inputString = scanner.nextLine(); if (inputString.equals("q")) { - headless.shutDown(); + UserThread.execute(headless::shutDown); isStopped = true; } } diff --git a/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java b/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java index 10c8c7623b..486eec575b 100644 --- a/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java +++ b/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java @@ -17,8 +17,10 @@ package io.bitsquare.monitor; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.bitsquare.app.BitsquareEnvironment; import io.bitsquare.app.BitsquareExecutable; +import io.bitsquare.common.UserThread; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -26,6 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Scanner; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import static io.bitsquare.app.BitsquareEnvironment.*; @@ -35,9 +39,14 @@ public class MonitorMain extends BitsquareExecutable { private boolean isStopped; public static void main(String[] args) throws Exception { + final ThreadFactory threadFactory = new ThreadFactoryBuilder() + .setNameFormat("MonitorMain") + .setDaemon(true) + .build(); + UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory)); + // We don't want to do the full argument parsing here as that might easily change in update versions // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR - BitsquareEnvironment.setDefaultAppName("Bitsquare_monitor"); OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); @@ -71,7 +80,7 @@ public class MonitorMain extends BitsquareExecutable { @Override protected void doExecute(OptionSet options) { Monitor.setEnvironment(new BitsquareEnvironment(options)); - monitor = new Monitor(); + UserThread.execute(() -> monitor = new Monitor()); while (!isStopped) { try { @@ -79,7 +88,7 @@ public class MonitorMain extends BitsquareExecutable { while (scanner.hasNextLine()) { String inputString = scanner.nextLine(); if (inputString.equals("q")) { - monitor.shutDown(); + UserThread.execute(monitor::shutDown); isStopped = true; } } diff --git a/seednode/src/main/java/io/bitsquare/seednode/SeedNodeMain.java b/seednode/src/main/java/io/bitsquare/seednode/SeedNodeMain.java index 0cce7dfbc6..cafdf448d8 100644 --- a/seednode/src/main/java/io/bitsquare/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/io/bitsquare/seednode/SeedNodeMain.java @@ -17,8 +17,10 @@ package io.bitsquare.seednode; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import io.bitsquare.app.BitsquareEnvironment; import io.bitsquare.app.BitsquareExecutable; +import io.bitsquare.common.UserThread; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -26,6 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Scanner; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; import static io.bitsquare.app.BitsquareEnvironment.*; @@ -35,10 +39,15 @@ public class SeedNodeMain extends BitsquareExecutable { private boolean isStopped; public static void main(String[] args) throws Exception { + final ThreadFactory threadFactory = new ThreadFactoryBuilder() + .setNameFormat("SeedNodeMain") + .setDaemon(true) + .build(); + UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory)); + // We don't want to do the full argument parsing here as that might easily change in update versions // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR - - BitsquareEnvironment.setDefaultAppName("Bitsquare_bootstrap"); + BitsquareEnvironment.setDefaultAppName("Bitsquare_seednode"); OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); parser.accepts(USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) @@ -71,7 +80,7 @@ public class SeedNodeMain extends BitsquareExecutable { @Override protected void doExecute(OptionSet options) { SeedNode.setEnvironment(new BitsquareEnvironment(options)); - seedNode = new SeedNode(); + UserThread.execute(() -> seedNode = new SeedNode()); while (!isStopped) { try { @@ -79,7 +88,7 @@ public class SeedNodeMain extends BitsquareExecutable { while (scanner.hasNextLine()) { String inputString = scanner.nextLine(); if (inputString.equals("q")) { - seedNode.shutDown(); + UserThread.execute(seedNode::shutDown); isStopped = true; } }