Search in sources :

Example 66 with OptionSet

use of joptsimple.OptionSet in project voldemort by voldemort.

the class ZoneClipperCLI method getValidOptions.

private static OptionSet getValidOptions(String[] args) {
    OptionSet options = null;
    try {
        options = parser.parse(args);
    } catch (OptionException oe) {
        printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
    }
    if (options.has("help")) {
        printUsage();
        System.exit(0);
    }
    Set<String> missing = CmdUtils.missing(options, "current-cluster", "current-stores", "drop-zoneid");
    if (missing.size() > 0) {
        printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing));
    }
    return options;
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet)

Example 67 with OptionSet

use of joptsimple.OptionSet in project bitsquare by bitsquare.

the class SeedNodeMain method main.

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_seednode");
    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(SeedNodeMain.class.getClassLoader());
    new SeedNodeMain().execute(args);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 68 with OptionSet

use of joptsimple.OptionSet in project bitsquare by bitsquare.

the class SeedNodeMain method doExecute.

@Override
protected void doExecute(OptionSet options) {
    final BitsquareEnvironment environment = new BitsquareEnvironment(options);
    SeedNode.setEnvironment(environment);
    UserThread.execute(() -> seedNode = new SeedNode());
    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 = environment.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(environment);
            }, 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) Logger(org.slf4j.Logger) UserThread(io.bitsquare.common.UserThread) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) DEFAULT_USER_DATA_DIR(io.bitsquare.app.BitsquareEnvironment.DEFAULT_USER_DATA_DIR) Executors(java.util.concurrent.Executors) AppOptionKeys(io.bitsquare.app.AppOptionKeys) OptionException(joptsimple.OptionException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) BitsquareExecutable(io.bitsquare.app.BitsquareExecutable) OptionParser(joptsimple.OptionParser) RestartUtil(io.bitsquare.common.util.RestartUtil) Profiler(io.bitsquare.common.util.Profiler) BlockStoreException(org.bitcoinj.store.BlockStoreException) ThreadFactory(java.util.concurrent.ThreadFactory) OptionSet(joptsimple.OptionSet) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) DEFAULT_APP_NAME(io.bitsquare.app.BitsquareEnvironment.DEFAULT_APP_NAME) BlockStoreException(org.bitcoinj.store.BlockStoreException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) UserThread(io.bitsquare.common.UserThread)

Example 69 with OptionSet

use of joptsimple.OptionSet in project bitsquare by bitsquare.

the class BitsquareAppMain 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;
    }
    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(BitsquareAppMain.class.getClassLoader());
    new BitsquareAppMain().execute(args);
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 70 with OptionSet

use of joptsimple.OptionSet in project jgnash by ccavanaugh.

the class jGnashFx method main.

public static void main(final String[] args) throws Exception {
    if (OS.getJavaVersion() < 1.8f) {
        System.out.println(ResourceUtils.getString("Message.JVM8"));
        System.out.println(ResourceUtils.getString("Message.Version") + " " + System.getProperty("java.version") + "\n");
        // try and show a dialog
        JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JVM8"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (OS.getJavaRelease() < OS.JVM_RELEASE_71) {
        JOptionPane.showMessageDialog(null, ResourceUtils.getString("Message.JFX"), ResourceUtils.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Register the default exception handler
    Thread.setDefaultUncaughtExceptionHandler(new StaticUIMethods.ExceptionHandler());
    configureLogging();
    OptionParser parser = buildParser();
    try {
        final OptionSet options = parser.parse(args);
        // Does the user want to uninstall and clear their registry settings
        if (options.has(UNINSTALL_OPTION_SHORT)) {
            PortablePreferences.deleteUserPreferences();
            System.exit(0);
        }
        // Needs to be checked for launching
        if (options.has(VERBOSE_OPTION_SHORT)) {
            System.setProperty("javafx.verbose", "true");
        }
        // Check to see if portable preferences are being used
        if (options.has(PORTABLE_FILE_OPTION)) {
            final File file = (File) options.valueOf(PORTABLE_FILE_OPTION);
            if (file.exists()) {
                PortablePreferences.initPortablePreferences(file.getAbsolutePath());
            }
        } else if (options.has(PORTABLE_OPTION_SHORT)) {
            // simple use of portable preferences
            PortablePreferences.initPortablePreferences(null);
        }
        if (options.has(PORT_OPTION)) {
            port = (Integer) options.valueOf(PORT_OPTION);
        }
        if (options.has(PASSWORD_OPTION)) {
            password = ((String) options.valueOf(PASSWORD_OPTION)).toCharArray();
        }
        if (options.has(FILE_OPTION_SHORT)) {
            final File file = (File) options.valueOf(FILE_OPTION_SHORT);
            if (file.exists()) {
                dataFile = file;
            }
        } else if (!options.nonOptionArguments().isEmpty() && dataFile == null) {
            // Check for no-option version of a file load
            for (final Object object : options.nonOptionArguments()) {
                if (object instanceof String) {
                    if (Files.exists(Paths.get((String) object))) {
                        dataFile = new File((String) object);
                        break;
                    } else {
                        System.err.println(object + " was not a valid file");
                        // force an exit with an error
                        System.exit(1);
                    }
                }
            }
        }
        if (options.has(HOST_OPTION)) {
            host = (String) options.valueOf(HOST_OPTION);
        }
        if (options.has(SERVER_OPTION)) {
            final File file = (File) options.valueOf(SERVER_OPTION);
            if (file.exists()) {
                serverFile = file;
            }
        }
        if (serverFile != null) {
            // not needed anymore, trigger GC
            parser = null;
            startServer();
        } else {
            // not needed anymore, trigger GC
            parser = null;
            setupNetworking();
            launch(args);
        }
    } catch (final Exception exception) {
        if (parser != null) {
            parser.printHelpOn(System.err);
        }
    }
}
Also used : StaticUIMethods(jgnash.uifx.StaticUIMethods) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

OptionSet (joptsimple.OptionSet)121 OptionParser (joptsimple.OptionParser)93 File (java.io.File)40 OptionException (joptsimple.OptionException)22 IOException (java.io.IOException)20 List (java.util.List)16 Cluster (voldemort.cluster.Cluster)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 StoreDefinition (voldemort.store.StoreDefinition)12 ClusterMapper (voldemort.xml.ClusterMapper)10 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)9 FileNotFoundException (java.io.FileNotFoundException)6 VoldemortException (voldemort.VoldemortException)6 BufferedReader (java.io.BufferedReader)5 Properties (java.util.Properties)5 OptionSpec (joptsimple.OptionSpec)5 Node (voldemort.cluster.Node)5 ByteArray (voldemort.utils.ByteArray)5 Closer (com.google.common.io.Closer)4