Search in sources :

Example 1 with BisqEnvironment

use of io.bisq.core.app.BisqEnvironment in project bisq-api by mrosseel.

the class ApiModule method configure.

@Override
protected void configure() {
    bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);
    // bind(CachingViewLoader.class).in(Singleton.class);
    bind(KeyStorage.class).in(Singleton.class);
    bind(KeyRing.class).in(Singleton.class);
    bind(User.class).in(Singleton.class);
    // bind(NotificationCenter.class).in(Singleton.class);
    bind(Clock.class).in(Singleton.class);
    bind(Preferences.class).in(Singleton.class);
    bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class);
    bind(SeedNodesRepository.class).to(CoreSeedNodesRepository.class).in(Singleton.class);
    File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR));
    bind(File.class).annotatedWith(named(Storage.STORAGE_DIR)).toInstance(storageDir);
    File keyStorageDir = new File(environment.getRequiredProperty(KeyStorage.KEY_STORAGE_DIR));
    bind(File.class).annotatedWith(named(KeyStorage.KEY_STORAGE_DIR)).toInstance(keyStorageDir);
    bind(BtcWalletService.class).in(Singleton.class);
    bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class).in(Singleton.class);
    bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class).in(Singleton.class);
    // added for API usage
    bind(BisqApiApplication.class).in(Singleton.class);
    bind(MainViewModelHeadless.class).in(Singleton.class);
    Boolean useDevPrivilegeKeys = environment.getProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS, Boolean.class, false);
    bind(boolean.class).annotatedWith(Names.named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS)).toInstance(useDevPrivilegeKeys);
    // ordering is used for shut down sequence
    install(tradeModule());
    install(encryptionServiceModule());
    install(arbitratorModule());
    install(offerModule());
    install(p2pModule());
    install(bitcoinModule());
    install(daoModule());
    install(alertModule());
    install(filterModule());
}
Also used : User(io.bisq.core.user.User) CoreNetworkProtoResolver(io.bisq.core.proto.network.CoreNetworkProtoResolver) KeyStorage(io.bisq.common.crypto.KeyStorage) Clock(io.bisq.common.Clock) BisqApiApplication(io.bisq.api.service.BisqApiApplication) CorePersistenceProtoResolver(io.bisq.core.proto.persistable.CorePersistenceProtoResolver) KeyRing(io.bisq.common.crypto.KeyRing) BtcWalletService(io.bisq.core.btc.wallet.BtcWalletService) BisqEnvironment(io.bisq.core.app.BisqEnvironment) Preferences(io.bisq.core.user.Preferences) CoreSeedNodesRepository(io.bisq.core.network.CoreSeedNodesRepository) File(java.io.File)

Example 2 with BisqEnvironment

use of io.bisq.core.app.BisqEnvironment in project bisq-api by mrosseel.

the class ApiMain method main.

public static void main(String[] args) throws Exception {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("BisqApiMain").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
    BisqEnvironment.setDefaultAppName("bisq_api");
    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;
    }
    BisqEnvironment bisqEnvironment = getBisqEnvironment(options);
    // need to call that before BisqAppMain().execute(args)
    BisqExecutable.initAppDir(bisqEnvironment.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(ApiMain.class.getClassLoader());
    new ApiMain().execute(args);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BisqEnvironment(io.bisq.core.app.BisqEnvironment) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 3 with BisqEnvironment

use of io.bisq.core.app.BisqEnvironment in project bisq-api by mrosseel.

the class ApiMain method doExecute.

@SuppressWarnings("InfiniteLoopStatement")
@Override
protected void doExecute(OptionSet options) {
    final BisqEnvironment bisqEnvironment = getBisqEnvironment(options);
    Api.setEnvironment(bisqEnvironment);
    UserThread.execute(() -> {
        try {
            api = new Api();
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
        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();
            log.error("We shut down the app because an unhandled error occurred");
            // We don't use the restart as in case of OutOfMemory errors the restart might fail as well
            // The run loop will restart the node anyway...
            System.exit(EXIT_FAILURE);
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);
    String maxMemoryOption = bisqEnvironment.getProperty(AppOptionKeys.MAX_MEMORY);
    if (maxMemoryOption != null && !maxMemoryOption.isEmpty()) {
        try {
            maxMemory = Integer.parseInt(maxMemoryOption);
        } catch (Throwable t) {
            log.error(t.getMessage());
        }
    }
    UserThread.runPeriodically(() -> {
        Profiler.printSystemLoad(log);
        long usedMemoryInMB = Profiler.getUsedMemoryInMB();
        if (!stopped) {
            if (usedMemoryInMB > (maxMemory - 100)) {
                log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + "We are over our memory warn limit and call the GC. usedMemoryInMB: {}" + "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n", usedMemoryInMB);
                System.gc();
                usedMemoryInMB = Profiler.getUsedMemoryInMB();
                Profiler.printSystemLoad(log);
            }
            final long finalUsedMemoryInMB = usedMemoryInMB;
            UserThread.runAfter(() -> {
                if (finalUsedMemoryInMB > maxMemory)
                    restart(bisqEnvironment);
            }, 1);
        }
    }, CHECK_MEMORY_PERIOD_SEC);
    while (true) {
        try {
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException ignore) {
        }
    }
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) BisqEnvironment(io.bisq.core.app.BisqEnvironment) BisqExecutable(io.bisq.core.app.BisqExecutable) Profiler(io.bisq.common.util.Profiler) UserThread(io.bisq.common.UserThread) AppOptionKeys(io.bisq.core.app.AppOptionKeys) IOException(java.io.IOException) RestartUtil(io.bisq.common.util.RestartUtil) Executors(java.util.concurrent.Executors) DEFAULT_APP_NAME(io.bisq.core.app.BisqEnvironment.DEFAULT_APP_NAME) DEFAULT_USER_DATA_DIR(io.bisq.core.app.BisqEnvironment.DEFAULT_USER_DATA_DIR) Slf4j(lombok.extern.slf4j.Slf4j) OptionException(joptsimple.OptionException) OptionParser(joptsimple.OptionParser) BlockStoreException(org.bitcoinj.store.BlockStoreException) ThreadFactory(java.util.concurrent.ThreadFactory) OptionSet(joptsimple.OptionSet) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) BlockStoreException(org.bitcoinj.store.BlockStoreException) BisqEnvironment(io.bisq.core.app.BisqEnvironment) IOException(java.io.IOException) OptionException(joptsimple.OptionException) BlockStoreException(org.bitcoinj.store.BlockStoreException) UserThread(io.bisq.common.UserThread)

Example 4 with BisqEnvironment

use of io.bisq.core.app.BisqEnvironment in project bisq-api by mrosseel.

the class BisqApiWithUI method start.

@SuppressWarnings("PointlessBooleanExpression")
@Override
public void start(Stage stage) throws IOException {
    BisqApiWithUI.primaryStage = stage;
    String logPath = Paths.get(bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bisq").toString();
    Log.setup(logPath);
    log.info("Log files under: " + logPath);
    Utilities.printSysInfo();
    Log.setLevel(Level.toLevel(bisqEnvironment.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY)));
    UserThread.setExecutor(Platform::runLater);
    UserThread.setTimerClass(UITimer.class);
    shutDownHandler = this::stop;
    BisqApp.shutDownHandler = shutDownHandler;
    // 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 if (throwable instanceof ClassCastException && "sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData".equals(throwable.getMessage())) {
            log.warn(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();
            UserThread.execute(() -> showErrorPopup(throwable, false));
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);
    try {
        Utilities.checkCryptoPolicySetup();
    } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
        e.printStackTrace();
        UserThread.execute(() -> showErrorPopup(e, true));
    }
    Security.addProvider(new BouncyCastleProvider());
    final BaseCurrencyNetwork baseCurrencyNetwork = BisqEnvironment.getBaseCurrencyNetwork();
    final String currencyCode = baseCurrencyNetwork.getCurrencyCode();
    Res.setBaseCurrencyCode(currencyCode);
    Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
    CurrencyUtil.setBaseCurrencyCode(currencyCode);
    try {
        // Guice
        bisqAppModule = new BisqAppModule(bisqEnvironment, primaryStage);
        injector = Guice.createInjector(bisqAppModule);
        injector.getInstance(InjectorViewFactory.class).setInjector(injector);
        injector.getInstance(BisqApiApplication.class).run("server", "bisq-api.yml");
        // All classes which are persisting objects need to be added here
        // Maintain order!
        ArrayList<PersistedDataHost> persistedDataHosts = new ArrayList<>();
        persistedDataHosts.add(injector.getInstance(Preferences.class));
        persistedDataHosts.add(injector.getInstance(User.class));
        persistedDataHosts.add(injector.getInstance(Navigation.class));
        persistedDataHosts.add(injector.getInstance(AddressEntryList.class));
        persistedDataHosts.add(injector.getInstance(TradeManager.class));
        persistedDataHosts.add(injector.getInstance(OpenOfferManager.class));
        persistedDataHosts.add(injector.getInstance(TradeManager.class));
        persistedDataHosts.add(injector.getInstance(ClosedTradableManager.class));
        persistedDataHosts.add(injector.getInstance(FailedTradesManager.class));
        persistedDataHosts.add(injector.getInstance(DisputeManager.class));
        persistedDataHosts.add(injector.getInstance(P2PService.class));
        persistedDataHosts.add(injector.getInstance(VotingManager.class));
        persistedDataHosts.add(injector.getInstance(CompensationRequestManager.class));
        // we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
        persistedDataHosts.stream().forEach(e -> {
            try {
                log.debug("call readPersisted at " + e.getClass().getSimpleName());
                e.readPersisted();
            } catch (Throwable e1) {
                log.error("readPersisted error", e1);
            }
        });
        Version.setBaseCryptoNetworkId(BisqEnvironment.getBaseCurrencyNetwork().ordinal());
        Version.printVersion();
        if (Utilities.isLinux())
            System.setProperty("prism.lcdtext", "false");
        Storage.setDatabaseCorruptionHandler((String fileName) -> {
            corruptedDatabaseFiles.add(fileName);
            if (mainView != null)
                mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        });
        // load the main view and create the main scene
        CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
        mainView = (MainView) viewLoader.load(MainView.class);
        mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        /* Storage.setDatabaseCorruptionHandler((String fileName) -> {
                corruptedDatabaseFiles.add(fileName);
                if (mainView != null)
                    mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
            });*/
        // 740
        scene = new Scene(mainView.getRoot(), 1200, 710);
        Font.loadFont(getClass().getResource("/fonts/Verdana.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBold.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaItalic.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBoldItalic.ttf").toExternalForm(), 13);
        scene.getStylesheets().setAll("/io/bisq/gui/bisq.css", "/io/bisq/gui/images.css", "/io/bisq/gui/CandleStickChart.css");
        // configure the system tray
        SystemTray.create(primaryStage, shutDownHandler);
        primaryStage.setOnCloseRequest(event -> {
            event.consume();
            stop();
        });
        scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
            Utilities.isAltOrCtrlPressed(KeyCode.W, keyEvent);
            if (Utilities.isCtrlPressed(KeyCode.W, keyEvent) || Utilities.isCtrlPressed(KeyCode.Q, keyEvent)) {
                stop();
            } else {
                if (Utilities.isAltOrCtrlPressed(KeyCode.E, keyEvent)) {
                    showEmptyWalletPopup(injector.getInstance(BtcWalletService.class));
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.M, keyEvent)) {
                    showSendAlertMessagePopup();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.F, keyEvent)) {
                    showFilterPopup();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.J, keyEvent)) {
                    WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
                    if (walletsManager.areWalletsAvailable())
                        new ShowWalletDataWindow(walletsManager).show();
                    else
                        new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
                } else if (Utilities.isAltOrCtrlPressed(KeyCode.G, keyEvent)) {
                    if (injector.getInstance(BtcWalletService.class).isWalletReady())
                        injector.getInstance(ManualPayoutTxWindow.class).show();
                    else
                        new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
                } else if (DevEnv.DEV_MODE) {
                    // dev ode only
                    if (Utilities.isAltOrCtrlPressed(KeyCode.B, keyEvent)) {
                        // BSQ empty wallet not public yet
                        showEmptyWalletPopup(injector.getInstance(BsqWalletService.class));
                    } else if (Utilities.isAltOrCtrlPressed(KeyCode.P, keyEvent)) {
                        showFPSWindow();
                    } else if (Utilities.isAltOrCtrlPressed(KeyCode.Z, keyEvent)) {
                        showDebugWindow();
                    }
                }
            }
        });
        // configure the primary stage
        primaryStage.setTitle(bisqEnvironment.getRequiredProperty(AppOptionKeys.APP_NAME_KEY));
        primaryStage.setScene(scene);
        primaryStage.setMinWidth(1020);
        primaryStage.setMinHeight(620);
        // on windows the title icon is also used as task bar icon in a larger size
        // on Linux no title icon is supported but also a large task bar icon is derived from that title icon
        String iconPath;
        if (Utilities.isOSX())
            iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
        else if (Utilities.isWindows())
            iconPath = "/images/task_bar_icon_windows.png";
        else
            iconPath = "/images/task_bar_icon_linux.png";
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
        // make the UI visible
        primaryStage.show();
        if (!Utilities.isCorrectOSArchitecture()) {
            String osArchitecture = Utilities.getOSArchitecture();
            // We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.
            // Needs at least more testing on different machines...
            new Popup<>().warning(Res.get("popup.warning.wrongVersion", osArchitecture, Utilities.getJVMArchitecture(), osArchitecture)).show();
        }
        UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
    } catch (Throwable throwable) {
        log.error("Error during app init", throwable);
        showErrorPopup(throwable, false);
    }
}
Also used : StageStyle(javafx.stage.StageStyle) Version(io.bisq.common.app.Version) Key(com.google.inject.Key) User(io.bisq.core.user.User) ImageUtil(io.bisq.gui.util.ImageUtil) LoggerFactory(org.slf4j.LoggerFactory) UserThread(io.bisq.common.UserThread) Security(java.security.Security) StackPane(javafx.scene.layout.StackPane) Application(javafx.application.Application) Parent(javafx.scene.Parent) ClosedTradableManager(io.bisq.core.trade.closed.ClosedTradableManager) ResultHandler(io.bisq.common.handlers.ResultHandler) DisputeManager(io.bisq.core.arbitration.DisputeManager) CurrencyUtil(io.bisq.common.locale.CurrencyUtil) BlockStoreException(org.bitcoinj.store.BlockStoreException) Pane(javafx.scene.layout.Pane) AddressEntryList(io.bisq.core.btc.AddressEntryList) Font(javafx.scene.text.Font) Res(io.bisq.common.locale.Res) KeyEvent(javafx.scene.input.KeyEvent) UITimer(io.bisq.gui.common.UITimer) CommonOptionKeys(io.bisq.common.CommonOptionKeys) Platform(javafx.application.Platform) List(java.util.List) BisqAppModule(io.bisq.gui.app.BisqAppModule) Logger(ch.qos.logback.classic.Logger) OpenOfferManager(io.bisq.core.offer.OpenOfferManager) InjectorViewFactory(io.bisq.gui.common.view.guice.InjectorViewFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EventStreams(org.reactfx.EventStreams) Storage(io.bisq.common.storage.Storage) VotingManager(io.bisq.core.dao.vote.VotingManager) io.bisq.core.btc.wallet(io.bisq.core.btc.wallet) SystemTray(io.bisq.gui.SystemTray) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) TradeManager(io.bisq.core.trade.TradeManager) Scene(javafx.scene.Scene) BaseCurrencyNetwork(io.bisq.core.btc.BaseCurrencyNetwork) ArbitratorManager(io.bisq.core.arbitration.ArbitratorManager) Preferences(io.bisq.core.user.Preferences) io.bisq.gui.main.overlays.windows(io.bisq.gui.main.overlays.windows) CompensationRequestManager(io.bisq.core.dao.compensation.CompensationRequestManager) ArrayList(java.util.ArrayList) AlertManager(io.bisq.core.alert.AlertManager) FilterManager(io.bisq.core.filter.FilterManager) FailedTradesManager(io.bisq.core.trade.failed.FailedTradesManager) MainView(io.bisq.gui.main.MainView) LimitedKeyStrengthException(io.bisq.common.crypto.LimitedKeyStrengthException) KeyCode(javafx.scene.input.KeyCode) Modality(javafx.stage.Modality) BisqEnvironment(io.bisq.core.app.BisqEnvironment) Label(javafx.scene.control.Label) Profiler(io.bisq.common.util.Profiler) ViewLoader(io.bisq.gui.common.view.ViewLoader) Popup(io.bisq.gui.main.overlays.popups.Popup) AppOptionKeys(io.bisq.core.app.AppOptionKeys) IOException(java.io.IOException) Names(com.google.inject.name.Names) View(io.bisq.gui.common.view.View) Log(io.bisq.common.app.Log) BisqApiApplication(io.bisq.api.service.BisqApiApplication) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) Navigation(io.bisq.gui.Navigation) Level(ch.qos.logback.classic.Level) P2PService(io.bisq.network.p2p.P2PService) CachingViewLoader(io.bisq.gui.common.view.CachingViewLoader) Stage(javafx.stage.Stage) Utilities(io.bisq.common.util.Utilities) BisqApp(io.bisq.gui.app.BisqApp) Paths(java.nio.file.Paths) DevEnv(io.bisq.common.app.DevEnv) PersistedDataHost(io.bisq.common.proto.persistable.PersistedDataHost) Guice(com.google.inject.Guice) DebugView(io.bisq.gui.main.debug.DebugView) Image(javafx.scene.image.Image) TradeManager(io.bisq.core.trade.TradeManager) User(io.bisq.core.user.User) Platform(javafx.application.Platform) DisputeManager(io.bisq.core.arbitration.DisputeManager) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) P2PService(io.bisq.network.p2p.P2PService) Image(javafx.scene.image.Image) BisqApiApplication(io.bisq.api.service.BisqApiApplication) CachingViewLoader(io.bisq.gui.common.view.CachingViewLoader) CompensationRequestManager(io.bisq.core.dao.compensation.CompensationRequestManager) LimitedKeyStrengthException(io.bisq.common.crypto.LimitedKeyStrengthException) Popup(io.bisq.gui.main.overlays.popups.Popup) AddressEntryList(io.bisq.core.btc.AddressEntryList) Preferences(io.bisq.core.user.Preferences) InjectorViewFactory(io.bisq.gui.common.view.guice.InjectorViewFactory) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) FailedTradesManager(io.bisq.core.trade.failed.FailedTradesManager) Navigation(io.bisq.gui.Navigation) BlockStoreException(org.bitcoinj.store.BlockStoreException) VotingManager(io.bisq.core.dao.vote.VotingManager) Scene(javafx.scene.Scene) UserThread(io.bisq.common.UserThread) OpenOfferManager(io.bisq.core.offer.OpenOfferManager) BisqAppModule(io.bisq.gui.app.BisqAppModule) PersistedDataHost(io.bisq.common.proto.persistable.PersistedDataHost) BaseCurrencyNetwork(io.bisq.core.btc.BaseCurrencyNetwork) ClosedTradableManager(io.bisq.core.trade.closed.ClosedTradableManager)

Example 5 with BisqEnvironment

use of io.bisq.core.app.BisqEnvironment in project bisq-api by mrosseel.

the class BisqApiWithUIMain method main.

public static void main(String[] args) throws Exception {
    // 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
    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;
    }
    BisqEnvironment bisqEnvironment = getBisqEnvironment(options);
    // need to call that before bisqAppMain().execute(args)
    initAppDir(bisqEnvironment.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(BisqApiWithUIMain.class.getClassLoader());
    new BisqApiWithUIMain().execute(args);
}
Also used : BisqEnvironment(io.bisq.core.app.BisqEnvironment) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

BisqEnvironment (io.bisq.core.app.BisqEnvironment)5 OptionException (joptsimple.OptionException)3 OptionParser (joptsimple.OptionParser)3 OptionSet (joptsimple.OptionSet)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 BisqApiApplication (io.bisq.api.service.BisqApiApplication)2 UserThread (io.bisq.common.UserThread)2 Profiler (io.bisq.common.util.Profiler)2 AppOptionKeys (io.bisq.core.app.AppOptionKeys)2 IOException (java.io.IOException)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)2 BlockStoreException (org.bitcoinj.store.BlockStoreException)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Names (com.google.inject.name.Names)1 Clock (io.bisq.common.Clock)1