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;
}
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);
}
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) {
}
}
}
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);
}
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);
}
}
}
Aggregations