From 0a546978b34c473a734fb04e35cf67cbb34cd720 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 22 Mar 2017 16:01:47 -0500 Subject: [PATCH] Remove monitor and headless modules --- headless/pom.xml | 85 ---------- .../java/io/bitsquare/headless/Headless.java | 157 ----------------- .../io/bitsquare/headless/HeadlessMain.java | 101 ----------- .../io/bitsquare/headless/HeadlessModule.java | 110 ------------ monitor/pom.xml | 93 ---------- .../java/io/bitsquare/monitor/Gateway.java | 26 --- .../java/io/bitsquare/monitor/Monitor.java | 160 ------------------ .../io/bitsquare/monitor/MonitorMain.java | 101 ----------- .../io/bitsquare/monitor/MonitorModule.java | 110 ------------ 9 files changed, 943 deletions(-) delete mode 100644 headless/pom.xml delete mode 100644 headless/src/main/java/io/bitsquare/headless/Headless.java delete mode 100644 headless/src/main/java/io/bitsquare/headless/HeadlessMain.java delete mode 100644 headless/src/main/java/io/bitsquare/headless/HeadlessModule.java delete mode 100644 monitor/pom.xml delete mode 100644 monitor/src/main/java/io/bitsquare/monitor/Gateway.java delete mode 100644 monitor/src/main/java/io/bitsquare/monitor/Monitor.java delete mode 100644 monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java delete mode 100644 monitor/src/main/java/io/bitsquare/monitor/MonitorModule.java diff --git a/headless/pom.xml b/headless/pom.xml deleted file mode 100644 index 6f237eda432..00000000000 --- a/headless/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - parent - io.bitsquare - 0.4.9.9 - - 4.0.0 - - headless - - - - - - false - ${basedir}/src/main/java - - **/*.fxml - **/*.css - - - - false - ${basedir}/src/main/resources - - **/*.* - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - - false - - - io.bitsquare.headless.HeadlessMain - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - package - - shade - - - true - bundled - Headless - - - - - - - - - - - io.bitsquare - core - ${project.parent.version} - - - \ No newline at end of file diff --git a/headless/src/main/java/io/bitsquare/headless/Headless.java b/headless/src/main/java/io/bitsquare/headless/Headless.java deleted file mode 100644 index a77f11d2aac..00000000000 --- a/headless/src/main/java/io/bitsquare/headless/Headless.java +++ /dev/null @@ -1,157 +0,0 @@ -package io.bitsquare.headless; - -import ch.qos.logback.classic.Level; -import com.google.inject.Guice; -import com.google.inject.Injector; -import io.bitsquare.app.AppOptionKeys; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.app.Log; -import io.bitsquare.app.Version; -import io.bitsquare.arbitration.ArbitratorManager; -import io.bitsquare.btc.WalletService; -import io.bitsquare.common.CommonOptionKeys; -import io.bitsquare.common.UserThread; -import io.bitsquare.common.handlers.ResultHandler; -import io.bitsquare.common.util.LimitedKeyStrengthException; -import io.bitsquare.common.util.Utilities; -import io.bitsquare.p2p.P2PService; -import io.bitsquare.p2p.P2PServiceListener; -import io.bitsquare.trade.offer.OfferBookService; -import io.bitsquare.trade.offer.OpenOfferManager; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.bitcoinj.store.BlockStoreException; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; - -import java.nio.file.Paths; -import java.security.NoSuchAlgorithmException; -import java.security.Security; - -public class Headless { - private static final Logger log = LoggerFactory.getLogger(Headless.class); - private static Environment env; - private final Injector injector; - private final OfferBookService offerBookService; - private final OpenOfferManager openOfferManager; - private final HeadlessModule headlessModule; - - private P2PService p2pService; - - public static void setEnvironment(Environment env) { - Headless.env = env; - } - - public Headless() { - String logPath = Paths.get(env.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bitsquare").toString(); - Log.setup(logPath); - log.info("Log files under: " + logPath); - Version.printVersion(); - Utilities.printSysInfo(); - Log.setLevel(Level.toLevel(env.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY))); - - // setup UncaughtExceptionHandler - Thread.UncaughtExceptionHandler handler = (thread, throwable) -> { - // Might come from another thread - if (throwable.getCause() != null && throwable.getCause().getCause() != null && - throwable.getCause().getCause() instanceof BlockStoreException) { - log.error(throwable.getMessage()); - } else { - log.error("Uncaught Exception from thread " + Thread.currentThread().getName()); - log.error("throwableMessage= " + throwable.getMessage()); - log.error("throwableClass= " + throwable.getClass()); - log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable)); - throwable.printStackTrace(); - } - }; - Thread.setDefaultUncaughtExceptionHandler(handler); - Thread.currentThread().setUncaughtExceptionHandler(handler); - - try { - Utilities.checkCryptoPolicySetup(); - } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) { - e.printStackTrace(); - UserThread.execute(this::shutDown); - } - Security.addProvider(new BouncyCastleProvider()); - - - headlessModule = new HeadlessModule(env); - injector = Guice.createInjector(headlessModule); - Version.setBtcNetworkId(injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal()); - p2pService = injector.getInstance(P2PService.class); - offerBookService = injector.getInstance(OfferBookService.class); - openOfferManager = injector.getInstance(OpenOfferManager.class); - p2pService.start(new P2PServiceListener() { - @Override - public void onRequestingDataCompleted() { - openOfferManager.onAllServicesInitialized(); - } - - @Override - public void onNoSeedNodeAvailable() { - - } - - @Override - public void onNoPeersAvailable() { - - } - - @Override - public void onBootstrapComplete() { - - } - - @Override - public void onTorNodeReady() { - - } - - @Override - public void onHiddenServicePublished() { - - } - - @Override - public void onSetupFailed(Throwable throwable) { - - } - }); - } - - public void shutDown() { - gracefulShutDown(() -> { - log.debug("Shutdown complete"); - System.exit(0); - }); - } - - private void gracefulShutDown(ResultHandler resultHandler) { - log.debug("gracefulShutDown"); - try { - if (injector != null) { - injector.getInstance(ArbitratorManager.class).shutDown(); - injector.getInstance(OpenOfferManager.class).shutDown(() -> { - injector.getInstance(P2PService.class).shutDown(() -> { - injector.getInstance(WalletService.class).shutDownDone.addListener((ov, o, n) -> { - headlessModule.close(injector); - log.debug("Graceful shutdown completed"); - resultHandler.handleResult(); - }); - injector.getInstance(WalletService.class).shutDown(); - }); - }); - // we wait max 5 sec. - UserThread.runAfter(resultHandler::handleResult, 5); - } else { - UserThread.runAfter(resultHandler::handleResult, 1); - } - } catch (Throwable t) { - log.debug("App shutdown failed with exception"); - t.printStackTrace(); - System.exit(1); - } - } -} diff --git a/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java b/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java deleted file mode 100644 index e5a7574e308..00000000000 --- a/headless/src/main/java/io/bitsquare/headless/HeadlessMain.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare 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. - * - * Bitsquare 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 Bitsquare. If not, see . - */ - -package io.bitsquare.headless; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import io.bitsquare.app.AppOptionKeys; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.app.BitsquareExecutable; -import io.bitsquare.common.UserThread; -import joptsimple.OptionException; -import joptsimple.OptionParser; -import joptsimple.OptionSet; -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.DEFAULT_APP_NAME; -import static io.bitsquare.app.BitsquareEnvironment.DEFAULT_USER_DATA_DIR; - -public class HeadlessMain extends BitsquareExecutable { - private static final Logger log = LoggerFactory.getLogger(HeadlessMain.class); - private Headless headless; - 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(); - parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) - .withRequiredArg(); - parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)) - .withRequiredArg(); - - OptionSet options; - try { - options = parser.parse(args); - } catch (OptionException ex) { - System.out.println("error: " + ex.getMessage()); - System.out.println(); - parser.printHelpOn(System.out); - System.exit(EXIT_FAILURE); - return; - } - BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options); - - // need to call that before BitsquareAppMain().execute(args) - BitsquareExecutable.initAppDir(bitsquareEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY)); - - // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it. - // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method: - Thread.currentThread().setContextClassLoader(HeadlessMain.class.getClassLoader()); - - new HeadlessMain().execute(args); - } - - @Override - protected void doExecute(OptionSet options) { - Headless.setEnvironment(new BitsquareEnvironment(options)); - UserThread.execute(() -> headless = new Headless()); - - while (!isStopped) { - try { - Scanner scanner = new Scanner(System.in); - while (scanner.hasNextLine()) { - String inputString = scanner.nextLine(); - if (inputString.equals("q")) { - UserThread.execute(headless::shutDown); - isStopped = true; - } - } - } catch (Throwable ignore) { - } - } - } -} diff --git a/headless/src/main/java/io/bitsquare/headless/HeadlessModule.java b/headless/src/main/java/io/bitsquare/headless/HeadlessModule.java deleted file mode 100644 index 087288dcdbf..00000000000 --- a/headless/src/main/java/io/bitsquare/headless/HeadlessModule.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare 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. - * - * Bitsquare 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 Bitsquare. If not, see . - */ - -package io.bitsquare.headless; - -import com.google.inject.Singleton; -import io.bitsquare.alert.AlertModule; -import io.bitsquare.app.AppModule; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.arbitration.ArbitratorModule; -import io.bitsquare.btc.BitcoinModule; -import io.bitsquare.common.Clock; -import io.bitsquare.common.crypto.KeyRing; -import io.bitsquare.common.crypto.KeyStorage; -import io.bitsquare.crypto.EncryptionServiceModule; -import io.bitsquare.filter.FilterModule; -import io.bitsquare.p2p.P2PModule; -import io.bitsquare.storage.Storage; -import io.bitsquare.trade.TradeModule; -import io.bitsquare.trade.offer.OfferModule; -import io.bitsquare.user.Preferences; -import io.bitsquare.user.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; - -import java.io.File; - -import static com.google.inject.name.Names.named; - -class HeadlessModule extends AppModule { - private static final Logger log = LoggerFactory.getLogger(HeadlessModule.class); - - public HeadlessModule(Environment env) { - super(env); - } - - @Override - protected void configure() { - bind(KeyStorage.class).in(Singleton.class); - bind(KeyRing.class).in(Singleton.class); - bind(User.class).in(Singleton.class); - bind(Preferences.class).in(Singleton.class); - bind(Clock.class).in(Singleton.class); - - File storageDir = new File(env.getRequiredProperty(Storage.DIR_KEY)); - bind(File.class).annotatedWith(named(Storage.DIR_KEY)).toInstance(storageDir); - - File keyStorageDir = new File(env.getRequiredProperty(KeyStorage.DIR_KEY)); - bind(File.class).annotatedWith(named(KeyStorage.DIR_KEY)).toInstance(keyStorageDir); - - bind(BitsquareEnvironment.class).toInstance((BitsquareEnvironment) env); - - // ordering is used for shut down sequence - install(tradeModule()); - install(encryptionServiceModule()); - install(arbitratorModule()); - install(offerModule()); - install(torModule()); - install(bitcoinModule()); - install(alertModule()); - install(filterModule()); - } - - private TradeModule tradeModule() { - return new TradeModule(env); - } - - private EncryptionServiceModule encryptionServiceModule() { - return new EncryptionServiceModule(env); - } - - private ArbitratorModule arbitratorModule() { - return new ArbitratorModule(env); - } - - private AlertModule alertModule() { - return new AlertModule(env); - } - - private FilterModule filterModule() { - return new FilterModule(env); - } - - private OfferModule offerModule() { - return new OfferModule(env); - } - - private P2PModule torModule() { - return new P2PModule(env); - } - - private BitcoinModule bitcoinModule() { - return new BitcoinModule(env); - } -} diff --git a/monitor/pom.xml b/monitor/pom.xml deleted file mode 100644 index 49b69524daf..00000000000 --- a/monitor/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - parent - io.bitsquare - 0.4.9.9 - - 4.0.0 - - monitor - - - - - - false - ${basedir}/src/main/java - - **/*.fxml - **/*.css - - - - false - ${basedir}/src/main/resources - - **/*.* - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - - false - - - io.bitsquare.monitor.MonitorMain - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - package - - shade - - - true - bundled - Monitor - - - - - - - - - - - io.bitsquare - core - ${project.parent.version} - - - - - - net.sf.py4j - py4j - 0.10.1 - - - \ No newline at end of file diff --git a/monitor/src/main/java/io/bitsquare/monitor/Gateway.java b/monitor/src/main/java/io/bitsquare/monitor/Gateway.java deleted file mode 100644 index 00a5630b1dd..00000000000 --- a/monitor/src/main/java/io/bitsquare/monitor/Gateway.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.bitsquare.monitor; - -import io.bitsquare.trade.offer.Offer; -import io.bitsquare.trade.offer.OfferBookService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import py4j.GatewayServer; - -import java.util.List; - -public class Gateway { - private static final Logger log = LoggerFactory.getLogger(Gateway.class); - private OfferBookService offerBookService; - - public Gateway(OfferBookService offerBookService) { - this.offerBookService = offerBookService; - - GatewayServer gatewayServer = new GatewayServer(this); - gatewayServer.start(); - log.info("Gateway Server Started"); - } - - public List getOffers() { - return offerBookService.getOffers(); - } -} diff --git a/monitor/src/main/java/io/bitsquare/monitor/Monitor.java b/monitor/src/main/java/io/bitsquare/monitor/Monitor.java deleted file mode 100644 index a80ca9faca2..00000000000 --- a/monitor/src/main/java/io/bitsquare/monitor/Monitor.java +++ /dev/null @@ -1,160 +0,0 @@ -package io.bitsquare.monitor; - -import ch.qos.logback.classic.Level; -import com.google.inject.Guice; -import com.google.inject.Injector; -import io.bitsquare.app.AppOptionKeys; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.app.Log; -import io.bitsquare.app.Version; -import io.bitsquare.arbitration.ArbitratorManager; -import io.bitsquare.btc.WalletService; -import io.bitsquare.common.CommonOptionKeys; -import io.bitsquare.common.UserThread; -import io.bitsquare.common.handlers.ResultHandler; -import io.bitsquare.common.util.LimitedKeyStrengthException; -import io.bitsquare.common.util.Utilities; -import io.bitsquare.p2p.P2PService; -import io.bitsquare.p2p.P2PServiceListener; -import io.bitsquare.trade.offer.OfferBookService; -import io.bitsquare.trade.offer.OpenOfferManager; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.bitcoinj.store.BlockStoreException; -import org.bouncycastle.jce.provider.BouncyCastleProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; - -import java.nio.file.Paths; -import java.security.NoSuchAlgorithmException; -import java.security.Security; - -public class Monitor { - private static final Logger log = LoggerFactory.getLogger(Monitor.class); - private static Environment env; - private final Injector injector; - private final OfferBookService offerBookService; - private final Gateway gateway; - private final OpenOfferManager openOfferManager; - private final MonitorModule monitorModule; - - private P2PService p2pService; - - public static void setEnvironment(Environment env) { - Monitor.env = env; - } - - public Monitor() { - String logPath = Paths.get(env.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bitsquare").toString(); - Log.setup(logPath); - log.info("Log files under: " + logPath); - Version.printVersion(); - Utilities.printSysInfo(); - Log.setLevel(Level.toLevel(env.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY))); - - // setup UncaughtExceptionHandler - Thread.UncaughtExceptionHandler handler = (thread, throwable) -> { - // Might come from another thread - if (throwable.getCause() != null && throwable.getCause().getCause() != null && - throwable.getCause().getCause() instanceof BlockStoreException) { - log.error(throwable.getMessage()); - } else { - log.error("Uncaught Exception from thread " + Thread.currentThread().getName()); - log.error("throwableMessage= " + throwable.getMessage()); - log.error("throwableClass= " + throwable.getClass()); - log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable)); - throwable.printStackTrace(); - } - }; - Thread.setDefaultUncaughtExceptionHandler(handler); - Thread.currentThread().setUncaughtExceptionHandler(handler); - - try { - Utilities.checkCryptoPolicySetup(); - } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) { - e.printStackTrace(); - UserThread.execute(this::shutDown); - } - Security.addProvider(new BouncyCastleProvider()); - - - monitorModule = new MonitorModule(env); - injector = Guice.createInjector(monitorModule); - Version.setBtcNetworkId(injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal()); - p2pService = injector.getInstance(P2PService.class); - offerBookService = injector.getInstance(OfferBookService.class); - openOfferManager = injector.getInstance(OpenOfferManager.class); - p2pService.start(new P2PServiceListener() { - @Override - public void onRequestingDataCompleted() { - openOfferManager.onAllServicesInitialized(); - } - - @Override - public void onNoSeedNodeAvailable() { - - } - - @Override - public void onNoPeersAvailable() { - - } - - @Override - public void onBootstrapComplete() { - - } - - @Override - public void onTorNodeReady() { - - } - - @Override - public void onHiddenServicePublished() { - - } - - @Override - public void onSetupFailed(Throwable throwable) { - - } - }); - - gateway = new Gateway(offerBookService); - } - - public void shutDown() { - gracefulShutDown(() -> { - log.debug("Shutdown complete"); - System.exit(0); - }); - } - - private void gracefulShutDown(ResultHandler resultHandler) { - log.debug("gracefulShutDown"); - try { - if (injector != null) { - injector.getInstance(ArbitratorManager.class).shutDown(); - injector.getInstance(OpenOfferManager.class).shutDown(() -> { - injector.getInstance(P2PService.class).shutDown(() -> { - injector.getInstance(WalletService.class).shutDownDone.addListener((ov, o, n) -> { - monitorModule.close(injector); - log.debug("Graceful shutdown completed"); - resultHandler.handleResult(); - }); - injector.getInstance(WalletService.class).shutDown(); - }); - }); - // we wait max 5 sec. - UserThread.runAfter(resultHandler::handleResult, 5); - } else { - UserThread.runAfter(resultHandler::handleResult, 1); - } - } catch (Throwable t) { - log.debug("App shutdown failed with exception"); - t.printStackTrace(); - System.exit(1); - } - } -} diff --git a/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java b/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java deleted file mode 100644 index 2d90f556fba..00000000000 --- a/monitor/src/main/java/io/bitsquare/monitor/MonitorMain.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare 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. - * - * Bitsquare 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 Bitsquare. If not, see . - */ - -package io.bitsquare.monitor; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import io.bitsquare.app.AppOptionKeys; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.app.BitsquareExecutable; -import io.bitsquare.common.UserThread; -import joptsimple.OptionException; -import joptsimple.OptionParser; -import joptsimple.OptionSet; -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.DEFAULT_APP_NAME; -import static io.bitsquare.app.BitsquareEnvironment.DEFAULT_USER_DATA_DIR; - -public class MonitorMain extends BitsquareExecutable { - private static final Logger log = LoggerFactory.getLogger(MonitorMain.class); - private Monitor monitor; - 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(); - parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)) - .withRequiredArg(); - parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)) - .withRequiredArg(); - - OptionSet options; - try { - options = parser.parse(args); - } catch (OptionException ex) { - System.out.println("error: " + ex.getMessage()); - System.out.println(); - parser.printHelpOn(System.out); - System.exit(EXIT_FAILURE); - return; - } - BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options); - - // need to call that before BitsquareAppMain().execute(args) - BitsquareExecutable.initAppDir(bitsquareEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY)); - - // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it. - // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method: - Thread.currentThread().setContextClassLoader(MonitorMain.class.getClassLoader()); - - new MonitorMain().execute(args); - } - - @Override - protected void doExecute(OptionSet options) { - Monitor.setEnvironment(new BitsquareEnvironment(options)); - UserThread.execute(() -> monitor = new Monitor()); - - while (!isStopped) { - try { - Scanner scanner = new Scanner(System.in); - while (scanner.hasNextLine()) { - String inputString = scanner.nextLine(); - if (inputString.equals("q")) { - UserThread.execute(monitor::shutDown); - isStopped = true; - } - } - } catch (Throwable ignore) { - } - } - } -} diff --git a/monitor/src/main/java/io/bitsquare/monitor/MonitorModule.java b/monitor/src/main/java/io/bitsquare/monitor/MonitorModule.java deleted file mode 100644 index a0f717ebe64..00000000000 --- a/monitor/src/main/java/io/bitsquare/monitor/MonitorModule.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare 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. - * - * Bitsquare 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 Bitsquare. If not, see . - */ - -package io.bitsquare.monitor; - -import com.google.inject.Singleton; -import io.bitsquare.alert.AlertModule; -import io.bitsquare.app.AppModule; -import io.bitsquare.app.BitsquareEnvironment; -import io.bitsquare.arbitration.ArbitratorModule; -import io.bitsquare.btc.BitcoinModule; -import io.bitsquare.common.Clock; -import io.bitsquare.common.crypto.KeyRing; -import io.bitsquare.common.crypto.KeyStorage; -import io.bitsquare.crypto.EncryptionServiceModule; -import io.bitsquare.filter.FilterModule; -import io.bitsquare.p2p.P2PModule; -import io.bitsquare.storage.Storage; -import io.bitsquare.trade.TradeModule; -import io.bitsquare.trade.offer.OfferModule; -import io.bitsquare.user.Preferences; -import io.bitsquare.user.User; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; - -import java.io.File; - -import static com.google.inject.name.Names.named; - -class MonitorModule extends AppModule { - private static final Logger log = LoggerFactory.getLogger(MonitorModule.class); - - public MonitorModule(Environment env) { - super(env); - } - - @Override - protected void configure() { - bind(KeyStorage.class).in(Singleton.class); - bind(KeyRing.class).in(Singleton.class); - bind(User.class).in(Singleton.class); - bind(Preferences.class).in(Singleton.class); - bind(Clock.class).in(Singleton.class); - - File storageDir = new File(env.getRequiredProperty(Storage.DIR_KEY)); - bind(File.class).annotatedWith(named(Storage.DIR_KEY)).toInstance(storageDir); - - File keyStorageDir = new File(env.getRequiredProperty(KeyStorage.DIR_KEY)); - bind(File.class).annotatedWith(named(KeyStorage.DIR_KEY)).toInstance(keyStorageDir); - - bind(BitsquareEnvironment.class).toInstance((BitsquareEnvironment) env); - - // ordering is used for shut down sequence - install(tradeModule()); - install(encryptionServiceModule()); - install(arbitratorModule()); - install(offerModule()); - install(torModule()); - install(bitcoinModule()); - install(alertModule()); - install(filterModule()); - } - - private TradeModule tradeModule() { - return new TradeModule(env); - } - - private EncryptionServiceModule encryptionServiceModule() { - return new EncryptionServiceModule(env); - } - - private ArbitratorModule arbitratorModule() { - return new ArbitratorModule(env); - } - - private AlertModule alertModule() { - return new AlertModule(env); - } - - private FilterModule filterModule() { - return new FilterModule(env); - } - - private OfferModule offerModule() { - return new OfferModule(env); - } - - private P2PModule torModule() { - return new P2PModule(env); - } - - private BitcoinModule bitcoinModule() { - return new BitcoinModule(env); - } -}