Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

In this page you can find the example usage for java.lang RuntimeException RuntimeException.

Prototype

public RuntimeException(Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:chibi.gemmaanalysis.cli.deprecated.AddExperimentalDesignCLI.java

/**
 * @param args/*from   w w w  . ja  v  a 2 s.  c o m*/
 */
public static void main(String[] args) {
    AddExperimentalDesignCLI p = new AddExperimentalDesignCLI();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = p.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Total run time: " + watch.getTime());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.arpnetworking.clusteraggregator.Main.java

/**
 * Entry point./*from   w ww .j a v  a  2s.  co  m*/
 *
 * @param args command line arguments
 */
public static void main(final String[] args) {
    Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
        LOGGER.error().setMessage("Unhandled exception!").setThrowable(throwable).log();
    });

    Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
        LOGGER.error().setMessage("Unhandled exception!").setThrowable(throwable).log();
    });

    LOGGER.info().setMessage("Launching cluster-aggregator").log();

    Runtime.getRuntime().addShutdownHook(SHUTDOWN_THREAD);

    if (args.length != 1) {
        throw new RuntimeException("No configuration file specified");
    }

    LOGGER.debug().setMessage("Loading configuration from file").addData("file", args[0]).log();

    Optional<DynamicConfiguration> configuration = Optional.absent();
    Optional<Configurator<Main, ClusterAggregatorConfiguration>> configurator = Optional.absent();
    try {
        final File configurationFile = new File(args[0]);
        configurator = Optional.of(new Configurator<>(Main::new, ClusterAggregatorConfiguration.class));
        final ObjectMapper objectMapper = ClusterAggregatorConfiguration.createObjectMapper();
        configuration = Optional.of(new DynamicConfiguration.Builder().setObjectMapper(objectMapper)
                .addSourceBuilder(new JsonNodeFileSource.Builder().setObjectMapper(objectMapper)
                        .setFile(configurationFile))
                .addTrigger(new FileTrigger.Builder().setFile(configurationFile).build())
                .addListener(configurator.get()).build());

        configuration.get().launch();

        // Wait for application shutdown
        SHUTDOWN_SEMAPHORE.acquire();
    } catch (final InterruptedException e) {
        throw Throwables.propagate(e);
    } finally {
        if (configurator.isPresent()) {
            configurator.get().shutdown();
        }
        if (configuration.isPresent()) {
            configuration.get().shutdown();
        }
        // Notify the shutdown that we're done
        SHUTDOWN_SEMAPHORE.release();
    }
}

From source file:de.mustnotbenamed.quickstart.undertowserver.Main.java

public static void main(String[] args) {
    CommandLine cmd = null;//from w w  w . ja  va 2  s .  c o m

    try {
        CommandLineParser parser = new GnuParser();
        cmd = parser.parse(createCliOption(), args);
    } catch (Exception e) {
        System.err.println("Failed to parse options: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("webapp", createCliOption());

        System.err.println("\n");
        System.err.println("### DEV ###");
        e.printStackTrace();

        System.exit(-1);
    }

    // start Webserver
    try {
        UndertowBootstrap.UndertowOptions options = new UndertowBootstrap.UndertowOptions();

        options.setHost(CliHelper.option(cmd, OPTION_HOST, options.getHost()));
        options.setPort(CliHelper.option(cmd, OPTION_PORT, options.getPort()));
        options.setContextPath(CliHelper.option(cmd, OPTION_CONTEXT_PATH, options.getContextPath()));

        new WeldUndertowBootstrap(options).startup();
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.sitewhere.web.rest.documentation.RestDocumentationGenerator.java

public static void main(String[] args) {
    if (args.length < 2) {
        throw new RuntimeException("Missing arguments needed to create REST documentation.");
    }/*w  w  w  . ja v a  2s  .  c  o m*/

    System.out.println("Generating SiteWhere REST documentation...");
    try {
        // Required since some internal operations require a user to be
        // logged in.
        try {
            SecurityContextHolder.getContext().setAuthentication(SiteWhereServer.getSystemAuthentication());
        } catch (SiteWhereException e) {
            throw new RuntimeException("Unable to set system user.", e);
        }

        File resources = new File(args[0]);
        if (!resources.exists()) {
            throw new SiteWhereException("Unable to find REST documentation resources folder.");
        }
        List<ParsedController> controllers = parseControllers(resources);
        generateRestDocumentation(controllers, resources, args[1]);
    } catch (SiteWhereException e) {
        System.err.println("Unable to generate SiteWhere REST documentation.");
        e.printStackTrace(System.err);
    }
    System.out.println("Finished generating SiteWhere REST documentation...");
}

From source file:gobblin.util.CLIPasswordEncryptor.java

public static void main(String[] args) throws ParseException {
    CommandLine cl = parseArgs(args);//from   w ww  .jav  a2 s  . c om
    if (shouldPrintUsageAndExit(cl)) {
        printUsage();
        return;
    }
    String masterPassword = getMasterPassword(cl);
    TextEncryptor encryptor = getEncryptor(cl, masterPassword);

    if (cl.hasOption(ENCRYPTED_PWD_OPTION)) {
        Matcher matcher = ENCRYPTED_PATTERN.matcher(cl.getOptionValue(ENCRYPTED_PWD_OPTION));
        if (matcher.find()) {
            String encrypted = matcher.group(1);
            System.out.println(encryptor.decrypt(encrypted));
        } else {
            throw new RuntimeException("Input encrypted password does not match pattern \"ENC(...)\"");
        }
    } else if (cl.hasOption(PLAIN_PWD_OPTION)) {
        System.out.println("ENC(" + encryptor.encrypt(cl.getOptionValue(PLAIN_PWD_OPTION)) + ")");
    } else {
        printUsage();
        throw new RuntimeException(
                String.format("Must provide -%s or -%s option.", PLAIN_PWD_OPTION, ENCRYPTED_PWD_OPTION));
    }
}

From source file:com.github.jjYBdx4IL.utils.lang.ConstantClassCreator.java

public static void main(String[] args) {
    try {//  ww  w .j ava  2s.c o  m
        CommandLineParser parser = new GnuParser();
        Options options = new Options();
        options.addOption(OPTNAME_H, OPTNAME_HELP, false, "show help (this page)");
        options.addOption(null, OPTNAME_SYSPROP, true, "system property name(s)");
        options.addOption(null, OPTNAME_OUTPUT_CLASSNAME, true, "output classname");
        options.addOption(null, OPTNAME_OUTPUT_DIRECTORY, true, "output directory");
        CommandLine line = parser.parse(options, args);
        if (line.hasOption(OPTNAME_H)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(ConstantClassCreator.class.getName(), options);
        } else if (line.hasOption(OPTNAME_SYSPROP)) {
            new ConstantClassCreator().run(line);
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.run.task.RandomTaskCreator.java

public static void main(String[] args) throws IOException {
    String projectPrefix = ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix();
    if (projectPrefix == null) {
        throw new RuntimeException("Project prefix not specified");
    }//from  w w  w .  j  a va  2 s  .co m
    createRandomTask();
}

From source file:org.javaee7.ejb.stateless.remote.AccountSessionBeanWithInterface.java

public static void main(String[] args) {
    try {//  w ww . j  a  v a 2  s  . c om
        ObjectMapper mapper = new ObjectMapper();
        URL url = new URL("http://localhost:8180/account-1.0-SNAPSHOT/statistics");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");

        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

        String output;
        String result = null;
        while ((output = br.readLine()) != null) {
            result = result + output;
        }
        conn.disconnect();

    } catch (MalformedURLException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }
}

From source file:azkaban.jobtype.HadoopSecureHiveWrapper.java

public static void main(final String[] args) throws Exception {

    String propsFile = System.getenv(ProcessJob.JOB_PROP_ENV);
    Properties prop = new Properties();
    prop.load(new BufferedReader(new FileReader(propsFile)));

    hiveScript = prop.getProperty("hive.script");

    final Configuration conf = new Configuration();

    UserGroupInformation.setConfiguration(conf);
    securityEnabled = UserGroupInformation.isSecurityEnabled();

    if (shouldProxy(prop)) {
        UserGroupInformation proxyUser = null;
        String userToProxy = prop.getProperty("user.to.proxy");
        if (securityEnabled) {
            String filelocation = System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
            if (filelocation == null) {
                throw new RuntimeException("hadoop token information not set.");
            }//w  w w  . j  a  va2  s  . c o  m
            if (!new File(filelocation).exists()) {
                throw new RuntimeException("hadoop token file doesn't exist.");
            }

            logger.info("Found token file " + filelocation);

            logger.info("Setting " + HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY + " to "
                    + filelocation);
            System.setProperty(HadoopSecurityManager.MAPREDUCE_JOB_CREDENTIALS_BINARY, filelocation);

            UserGroupInformation loginUser = null;

            loginUser = UserGroupInformation.getLoginUser();
            logger.info("Current logged in user is " + loginUser.getUserName());

            logger.info("Creating proxy user.");
            proxyUser = UserGroupInformation.createProxyUser(userToProxy, loginUser);

            for (Token<?> token : loginUser.getTokens()) {
                proxyUser.addToken(token);
            }
        } else {
            proxyUser = UserGroupInformation.createRemoteUser(userToProxy);
        }

        logger.info("Proxied as user " + userToProxy);

        proxyUser.doAs(new PrivilegedExceptionAction<Void>() {
            @Override
            public Void run() throws Exception {
                runHive(args);
                return null;
            }
        });

    } else {
        logger.info("Not proxying. ");
        runHive(args);
    }
}

From source file:com.heliosdecompiler.helios.Helios.java

public static void main(String[] args) {
    try {/*from ww w .  j a va2  s  . c o m*/
        LanguageController languageController = new LanguageController(); // blehhhhhh
        Message.init(languageController);

        GraphicsProvider launcher = getGraphicsProvider().newInstance();

        launcher.startSplash();
        launcher.updateSplash(Message.STARTUP_PREPARING_ENVIRONMENT);

        Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
        defaultCharset.setAccessible(true);
        defaultCharset.set(null, StandardCharsets.UTF_8);
        if (!Charset.defaultCharset().equals(StandardCharsets.UTF_8))
            throw new RuntimeException("Charset: " + Charset.defaultCharset());
        if (!Constants.DATA_DIR.exists() && !Constants.DATA_DIR.mkdirs())
            throw new RuntimeException("Could not create data directory");
        if (!Constants.ADDONS_DIR.exists() && !Constants.ADDONS_DIR.mkdirs())
            throw new RuntimeException("Could not create addons directory");
        if (Constants.DATA_DIR.isFile())
            throw new RuntimeException("Data directory is file");
        if (Constants.ADDONS_DIR.isFile())
            throw new RuntimeException("Addons directory is file");

        EventBus eventBus = new AsyncEventBus(Executors.newCachedThreadPool());

        Configuration configuration = loadConfiguration();
        Class<? extends UserInterfaceController> uiController = getUIControllerImpl();

        Injector mainInjector = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(MessageHandler.class).to(launcher.getMessageHandlerImpl());
                bind(UserInterfaceController.class).to(uiController);
                bind(Configuration.class).toInstance(configuration);
                bind(EventBus.class).toInstance(eventBus);
            }
        });

        mainInjector.getInstance(UserInterfaceController.class).initialize();

        launcher.updateSplash(Message.STARTUP_LOADING_GRAPHICS);
        launcher.prepare(mainInjector);

        launcher.updateSplash(Message.STARTUP_DONE);
        launcher.start();

        mainInjector.getInstance(PathController.class).reload();
        mainInjector.getInstance(UpdateController.class).doUpdate();
        handleCommandLine(args, mainInjector);
    } catch (Throwable t) {
        displayError(t);
        System.exit(1);
    }
}