Example usage for org.apache.commons.exec Executor setExitValue

List of usage examples for org.apache.commons.exec Executor setExitValue

Introduction

In this page you can find the example usage for org.apache.commons.exec Executor setExitValue.

Prototype

void setExitValue(final int value);

Source Link

Document

Define the exitValue of the process to be considered successful.

Usage

From source file:gov.nasa.jpl.magicdraw.projectUsageIntegrity.graph.SSCAEProjectUsageGraph.java

public BufferedImageFile convertDOTFile(@Nonnull File pugDOT, @Nonnull DOTImageFormat dotImageFormat)
        throws IIOException, IOException, InterruptedException {
    String dotCommand = ProjectUsageIntegrityPlugin.getInstance().getDOTexecutablePath();
    if (null == dotCommand)
        return null;

    File pugTemp = pugDOT.getParentFile();
    File pugImage = new File(pugTemp.getAbsoluteFile() + File.separator + project.getID() + "."
            + DOTImageFormatName.get(dotImageFormat));
    if (pugImage.exists()) {
        pluginLog.info(String.format("%s - convertDOTFile - deleting previous image for '%s' : '%s'",
                pluginName, project.getName(), pugImage.getName()));
        pugImage.delete();//w w w . ja  v a 2  s .  com
    }

    CommandLine cmdLine = new CommandLine(dotCommand);
    cmdLine.addArgument("-Tpng");
    cmdLine.addArgument("-o");
    cmdLine.addArgument(pugImage.getName());
    cmdLine.addArgument(pugDOT.getName());

    pluginLog.info(String.format("%s - convertDOTgraph - converting gv to image for '%s'", pluginName,
            project.getName()));

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);

    // consider '0' exit value as success.
    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    executor.setWatchdog(watchdog);
    executor.setWorkingDirectory(pugTemp);
    executor.execute(cmdLine, resultHandler);

    resultHandler.waitFor();

    if (!executor.isFailure(resultHandler.getExitValue())) {
        pluginLog.info(String.format("%s - convertDOTgraph - reading image for '%s' from: '%s'", pluginName,
                project.getName(), pugImage.getName()));
        BufferedImageFile imageFile = new BufferedImageFile(pugImage);

        pluginLog.info(
                String.format("%s - convertDOTgraph - got image for '%s'", pluginName, project.getName()));
        return imageFile;
    }

    return null;
}

From source file:gov.nasa.jpl.magicdraw.projectUsageIntegrity.graph.SSCAEProjectUsageGraph.java

/**
 * @param pugDOT gv file/* w  w  w.jav a 2s  .  co m*/
 * @return true if the graphviz application was opened successfully for the gv file.
 * @throws IIOException
 * @throws IOException
 * @throws InterruptedException
 */
public boolean openDOTFileWithGraphViz(@Nonnull File pugDOT)
        throws IIOException, IOException, InterruptedException {
    String graphvizApp = ProjectUsageIntegrityPlugin.getInstance().getGraphvizApplicationPath();
    if (null == graphvizApp)
        return false;

    File pugTemp = pugDOT.getParentFile();

    CommandLine cmdLine;

    switch (SSCAEProjectUsageIntegrityOptions.getCurrentPlatform()) {
    case LINUX:
        cmdLine = new CommandLine(graphvizApp);
        break;
    case MACOSX:
        cmdLine = new CommandLine("/usr/bin/open");
        cmdLine.addArgument("-a");
        cmdLine.addArgument(graphvizApp);
        break;
    case WINDOWS:
        cmdLine = new CommandLine("cmd");
        cmdLine.addArgument("/c");
        cmdLine.addArgument("start");
        cmdLine.addArgument(graphvizApp);
        break;
    default:
        return false;
    }
    cmdLine.addArgument(pugDOT.getName());

    pluginLog.info(String.format("%s - openDOTFileWithGraphViz - opening DOT file for project: '%s'",
            pluginName, project.getName()));

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);

    // consider '0' exit value as success.
    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    executor.setWatchdog(watchdog);
    executor.setWorkingDirectory(pugTemp);
    executor.execute(cmdLine, resultHandler);

    resultHandler.waitFor();

    if (executor.isFailure(resultHandler.getExitValue())) {
        pluginLog.error(String.format(
                "%s - openDOTFileWithGraphViz - error while opening DOT file for project '%s' from: '%s'",
                pluginName, project.getName(), pugDOT.getAbsolutePath()), resultHandler.getException());
        return false;
    }

    pluginLog.info(String.format("%s - openDOTFileWithGraphViz - opened DOT file for project '%s' from: '%s'",
            pluginName, project.getName(), pugDOT.getAbsolutePath()));
    return true;
}

From source file:it.drwolf.ridire.index.cwb.CWBPatternSearcher.java

@SuppressWarnings("unchecked")
public void test() {
    String query = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ncat A 0 9 > \"/home/drwolf/ridirecleaner_tmp/res.tbl\";";
    File temp = null;/*www .  j  av  a 2  s  .  co m*/
    try {
        temp = File.createTempFile("ridireQ", ".query");
        FileUtils.writeStringToFile(temp, query);
        Executor executor = new DefaultExecutor();
        CommandLine commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(temp.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        File resFile = new File("/home/drwolf/ridirecleaner_tmp/res.tbl");
        List<String> lines = FileUtils.readLines(resFile);
        this.resultsSimple = new ArrayList<CWBResult>();
        for (String l : lines) {
            String[] res = l.split("--%%%--");
            CWBResult item = new CWBResult(res[0], res[1], res[2], "", null, null);
            this.resultsSimple.add(item);
        }
        this.entityManager.createNativeQuery("drop table if exists pippo").executeUpdate();
        this.entityManager.createNativeQuery(
                "CREATE TABLE `pippo` (`text_id` varchar(40) DEFAULT NULL,`beginPosition` int(11) DEFAULT NULL,`endPosition` int(11) DEFAULT NULL,`refnumber` bigint(20) NOT NULL,`dist` smallint(6) NOT NULL,`word` varchar(40) NOT NULL,`lemma` varchar(40) NOT NULL, `pos` varchar(40) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8")
                .executeUpdate();
        File tmpAwk = File.createTempFile("ridireAWK", ".awk");
        String awk = "BEGIN{ OFS = FS = \"\t\" } { print $3, $1, $2, NR-1, -5, $4 } { print $3, $1, $2, NR-1, -4, $5 } { print $3, $1, $2, NR-1, -3, $6 } { print $3, $1, $2, NR-1, -2, $7 } { print $3, $1, $2, NR-1, -1, $8 } { print $3, $1, $2, NR-1, 1, $9 } { print $3, $1, $2, NR-1, 2, $10 } { print $3, $1, $2, NR-1, 3, $11 } { print $3, $1, $2, NR-1, 4, $12 } { print $3, $1, $2, NR-1, 5, $13 } ";
        FileUtils.writeStringToFile(tmpAwk, awk);
        File tmpTabulate = File.createTempFile("ridireTAB", ".tab");
        String tabulate = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ntabulate A match, matchend, match text_id, match[-5] word, match[-4] word, match[-3] word, match[-2] word, match[-1] word, matchend[1] word, matchend[2] word, matchend[3] word, matchend[4] word, matchend[5] word "
                + ">  \"| awk -f '" + tmpAwk.getAbsolutePath() + "' > '" + tmpTabulate.getAbsolutePath()
                + "'\";";
        File tempSh = File.createTempFile("ridireSH", ".sh");
        FileUtils.writeStringToFile(tempSh, tabulate);
        tempSh.setExecutable(true);
        executor = new DefaultExecutor();
        executor.setExitValue(0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBPatternSearcher.TIMEOUT);
        executor.setWatchdog(watchdog);
        commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(tempSh.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        FileUtils.deleteQuietly(tempSh);
        this.entityManager
                .createNativeQuery(
                        "LOAD DATA LOCAL INFILE '" + tmpTabulate.getAbsolutePath() + "' INTO TABLE " + "pippo")
                .executeUpdate();
        long n = ((Number) this.entityManager.createNativeQuery("select sum(freq) as somma from freq_forma_all")
                .getSingleResult()).longValue();
        long r1 = ((Number) this.entityManager
                .createNativeQuery("select count(*) from pippo where dist between -3 and 3").getSingleResult())
                        .longValue();
        String nativeQuery = "select pippo.word, count(pippo.word) as observed," + " (" + r1
                + " * (freq_forma_all.freq) / " + n + ") as expected, sign(COUNT(pippo.word) - (" + r1
                + " * (freq_forma_all.freq) / " + n
                + ")) * 2 * ( IF(COUNT(pippo.word) > 0, COUNT(pippo.word) * log(COUNT(pippo.word) / (" + r1
                + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + r1 + " - COUNT(pippo.word)) > 0, (" + r1
                + " - COUNT(pippo.word)) * log((" + r1 + " - COUNT(pippo.word)) / (" + r1 + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) + IF(((freq_forma_all.freq) - COUNT(pippo.word)) > 0, ((freq_forma_all.freq) - COUNT(pippo.word)) * log(((freq_forma_all.freq) - COUNT(pippo.word)) / ("
                + (n - r1) + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) > 0, (" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) * log((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) / (" + (n - r1) + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) ) as significance, freq_forma_all.freq, count(distinct(text_id)) as text_id_count from pippo, freq_forma_all where pippo.word = freq_forma_all.item and dist between -3 and 3 and freq_forma_all.freq >= 1 group by pippo.word having observed >= 1 order by significance desc LIMIT 0, 50 ";
        List<Object[]> res = this.entityManager.createNativeQuery(nativeQuery).getResultList();
        for (Object[] r : res) {
            System.out.println(r[0] + "\t" + r[3]);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:it.drwolf.ridire.index.cwb.CWBConcordancer.java

@SuppressWarnings("unchecked")
public void test() {
    String query = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ncat A 0 9 > \"/home/drwolf/ridirecleaner_tmp/res.tbl\";";
    File temp = null;//w  ww.  j av  a  2s  . com
    try {
        temp = File.createTempFile("ridireQ", ".query");
        FileUtils.writeStringToFile(temp, query);
        Executor executor = new DefaultExecutor();
        CommandLine commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(temp.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        File resFile = new File("/home/drwolf/ridirecleaner_tmp/res.tbl");
        List<String> lines = FileUtils.readLines(resFile);
        this.resultsSimple = new ArrayList<CWBResult>();
        for (String l : lines) {
            String[] res = l.split("--%%%--");
            CWBResult item = new CWBResult(res[0], res[1], res[2], "", null, null);
            this.resultsSimple.add(item);
        }
        this.entityManager.createNativeQuery("drop table if exists pippo").executeUpdate();
        this.entityManager.createNativeQuery(
                "CREATE TABLE `pippo` (`text_id` varchar(40) DEFAULT NULL,`beginPosition` int(11) DEFAULT NULL,`endPosition` int(11) DEFAULT NULL,`refnumber` bigint(20) NOT NULL,`dist` smallint(6) NOT NULL,`word` varchar(40) NOT NULL,`lemma` varchar(40) NOT NULL, `pos` varchar(40) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8")
                .executeUpdate();
        File tmpAwk = File.createTempFile("ridireAWK", ".awk");
        String awk = "BEGIN{ OFS = FS = \"\t\" } { print $3, $1, $2, NR-1, -5, $4 } { print $3, $1, $2, NR-1, -4, $5 } { print $3, $1, $2, NR-1, -3, $6 } { print $3, $1, $2, NR-1, -2, $7 } { print $3, $1, $2, NR-1, -1, $8 } { print $3, $1, $2, NR-1, 1, $9 } { print $3, $1, $2, NR-1, 2, $10 } { print $3, $1, $2, NR-1, 3, $11 } { print $3, $1, $2, NR-1, 4, $12 } { print $3, $1, $2, NR-1, 5, $13 } ";
        FileUtils.writeStringToFile(tmpAwk, awk);
        File tmpTabulate = File.createTempFile("ridireTAB", ".tab");
        String tabulate = "set AutoShow off;\nset ProgressBar off;\nset PrettyPrint off;\nset Context 5 words;\nset LeftKWICDelim '--%%%--';\nset RightKWICDelim '--%%%--';\nshow -cpos;\nA=\"e\";\ntabulate A match, matchend, match text_id, match[-5] word, match[-4] word, match[-3] word, match[-2] word, match[-1] word, matchend[1] word, matchend[2] word, matchend[3] word, matchend[4] word, matchend[5] word "
                + ">  \"| awk -f '" + tmpAwk.getAbsolutePath() + "' > '" + tmpTabulate.getAbsolutePath()
                + "'\";";
        File tempSh = File.createTempFile("ridireSH", ".sh");
        FileUtils.writeStringToFile(tempSh, tabulate);
        tempSh.setExecutable(true);
        executor = new DefaultExecutor();
        executor.setExitValue(0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBConcordancer.TIMEOUT);
        executor.setWatchdog(watchdog);
        commandLine = new CommandLine("/usr/local/cwb-3.4.3/bin/cqp");
        commandLine.addArgument("-f").addArgument(tempSh.getAbsolutePath()).addArgument("-D")
                .addArgument("RIDIRE2").addArgument("-r").addArgument("/usr/local/share/cwb/registry/");
        executor.execute(commandLine);
        FileUtils.deleteQuietly(tempSh);
        this.entityManager
                .createNativeQuery(
                        "LOAD DATA LOCAL INFILE '" + tmpTabulate.getAbsolutePath() + "' INTO TABLE " + "pippo")
                .executeUpdate();
        long n = ((Number) this.entityManager.createNativeQuery("select sum(freq) as somma from freq_forma_all")
                .getSingleResult()).longValue();
        long r1 = ((Number) this.entityManager
                .createNativeQuery("select count(*) from pippo where dist between -3 and 3").getSingleResult())
                        .longValue();
        String nativeQuery = "select pippo.word, count(pippo.word) as observed," + " (" + r1
                + " * (freq_forma_all.freq) / " + n + ") as expected, sign(COUNT(pippo.word) - (" + r1
                + " * (freq_forma_all.freq) / " + n
                + ")) * 2 * ( IF(COUNT(pippo.word) > 0, COUNT(pippo.word) * log(COUNT(pippo.word) / (" + r1
                + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + r1 + " - COUNT(pippo.word)) > 0, (" + r1
                + " - COUNT(pippo.word)) * log((" + r1 + " - COUNT(pippo.word)) / (" + r1 + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) + IF(((freq_forma_all.freq) - COUNT(pippo.word)) > 0, ((freq_forma_all.freq) - COUNT(pippo.word)) * log(((freq_forma_all.freq) - COUNT(pippo.word)) / ("
                + (n - r1) + " * (freq_forma_all.freq) / " + n + ")), 0) + IF((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) > 0, (" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) * log((" + (n - r1)
                + " - ((freq_forma_all.freq) - COUNT(pippo.word))) / (" + (n - r1) + " * (" + n
                + " - (freq_forma_all.freq)) / " + n
                + ")), 0) ) as significance, freq_forma_all.freq, count(distinct(text_id)) as text_id_count from pippo, freq_forma_all where pippo.word = freq_forma_all.item and dist between -3 and 3 and freq_forma_all.freq >= 1 group by pippo.word having observed >= 1 order by significance desc LIMIT 0, 50 ";
        List<Object[]> res = this.entityManager.createNativeQuery(nativeQuery).getResultList();
        for (Object[] r : res) {
            System.out.println(r[0] + "\t" + r[3]);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.apache.bigtop.itest.hive.HiveHelper.java

public static Map<String, String> execCommand(CommandLine commandline, Map<String, String> envVars) {

    System.out.println("Executing command:");
    System.out.println(commandline.toString());
    Map<String, String> env = null;
    Map<String, String> entry = new HashMap<String, String>();
    try {//from w w w . j  ava 2 s  .  co m
        env = EnvironmentUtils.getProcEnvironment();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        LOG.debug("Failed to get process environment: " + e1.getMessage());
        e1.printStackTrace();
    }
    if (envVars != null) {
        for (String key : envVars.keySet()) {
            env.put(key, envVars.get(key));
        }
    }

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 10000);
    Executor executor = new DefaultExecutor();
    executor.setExitValue(1);
    executor.setWatchdog(watchdog);
    executor.setStreamHandler(streamHandler);
    try {
        executor.execute(commandline, env, resultHandler);
    } catch (ExecuteException e) {
        // TODO Auto-generated catch block
        LOG.debug("Failed to execute command with exit value: " + String.valueOf(resultHandler.getExitValue()));
        LOG.debug("outputStream: " + outputStream.toString());
        entry.put("exitValue", String.valueOf(resultHandler.getExitValue()));
        entry.put("outputStream", outputStream.toString() + e.getMessage());
        e.printStackTrace();
        return entry;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        LOG.debug("Failed to execute command with exit value: " + String.valueOf(resultHandler.getExitValue()));
        LOG.debug("outputStream: " + outputStream.toString());
        entry.put("exitValue", String.valueOf(resultHandler.getExitValue()));
        entry.put("outputStream", outputStream.toString() + e.getMessage());
        e.printStackTrace();
        return entry;
    }

    try {
        resultHandler.waitFor();
        /*System.out.println("Command output: "+outputStream.toString());*/
        entry.put("exitValue", String.valueOf(resultHandler.getExitValue()));
        entry.put("outputStream", outputStream.toString());
        return entry;
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        /*System.out.println("Command output: "+outputStream.toString());*/
        LOG.debug("exitValue: " + String.valueOf(resultHandler.getExitValue()));
        LOG.debug("outputStream: " + outputStream.toString());
        entry.put("exitValue", String.valueOf(resultHandler.getExitValue()));
        entry.put("outputStream", outputStream.toString());
        e.printStackTrace();
        return entry;
    }
}

From source file:org.apache.stratos.python.cartridge.agent.integration.tests.PythonAgentIntegrationTest.java

/**
 * TearDown method for test method testPythonCartridgeAgent
 *///from w w  w. j a va  2 s. co  m
protected void tearDown(String sourcePath) {
    for (Map.Entry<String, Executor> entry : executorList.entrySet()) {
        try {
            String commandText = entry.getKey();
            Executor executor = entry.getValue();
            log.info("Terminating process: " + commandText);
            executor.setExitValue(0);
            executor.getWatchdog().destroyProcess();
        } catch (Exception ignore) {
        }
    }
    // wait until everything cleans up to avoid connection errors
    sleep(1000);
    for (ServerSocket serverSocket : serverSocketMap.values()) {
        try {
            log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress());
            serverSocket.close();
        } catch (IOException ignore) {
        }
    }
    try {
        if (thriftTestServer != null) {
            thriftTestServer.stop();
        }
    } catch (Exception ignore) {
    }

    if (sourcePath != null) {
        try {
            log.info("Deleting source checkout folder...");
            FileUtils.deleteDirectory(new File(sourcePath));
        } catch (Exception ignore) {
        }
    }
    log.info("Terminating event receivers...");
    this.instanceStatusEventReceiver.terminate();
    this.topologyEventReceiver.terminate();
    this.initializerEventReceiver.terminate();

    this.instanceStatusEventReceiver = null;
    this.topologyEventReceiver = null;
    this.initializerEventReceiver = null;

    this.instanceActivated = false;
    this.instanceStarted = false;

    // stop the broker services
    for (Map.Entry<String, BrokerService> entry : this.messageBrokers.entrySet()) {
        try {
            log.debug("Stopping broker service [" + entry.getKey() + "]");
            entry.getValue().stop();
        } catch (Exception ignore) {
        }
    }

    this.messageBrokers = null;

    // TODO: use thread synchronization and assert all connections are properly closed
    // leave some room to clear up active connections
    sleep(1000);
}

From source file:org.apache.stratos.python.cartridge.agent.test.PythonAgentTestManager.java

/**
 * TearDown method for test method testPythonCartridgeAgent
 *///from w w w.ja v  a  2 s .  c o  m
protected void tearDown(String sourcePath) {
    for (Map.Entry<String, Executor> entry : executorList.entrySet()) {
        try {
            String commandText = entry.getKey();
            Executor executor = entry.getValue();
            log.info("Terminating process: " + commandText);
            executor.setExitValue(0);
            executor.getWatchdog().destroyProcess();
        } catch (Exception ignore) {
        }
    }
    // wait until everything cleans up to avoid connection errors
    sleep(1000);
    for (ServerSocket serverSocket : serverSocketMap.values()) {
        try {
            log.info("Stopping socket server: " + serverSocket.getLocalSocketAddress());
            serverSocket.close();
        } catch (IOException ignore) {
        }
    }
    try {
        if (thriftTestServer != null) {
            thriftTestServer.stop();
        }
    } catch (Exception e) {
        log.error("Could not stop Thrift test server", e);
    }

    try {
        log.info("Deleting source checkout folder...");
        FileUtils.deleteDirectory(new File(sourcePath));
    } catch (Exception ignore) {
    }
    this.instanceStatusEventReceiver.terminate();
    this.topologyEventReceiver.terminate();

    this.instanceActivated = false;
    this.instanceStarted = false;
    try {
        broker.stop();
    } catch (Exception e) {
        log.error("Error while stopping the broker service", e);
    }
}

From source file:org.brailleblaster.util.ProgramCaller.java

public ProgramCaller(String command, String[] args, int returnValue) throws ExecuteException, IOException {
    cmdLine = new CommandLine(command + BBIni.getNativeCommandSuffix());
    for (int i = 0; i < args.length; i++)
        cmdLine.addArgument(args[i]);/*w  w w .jav a  2s.c o  m*/
    resultHandler = new DefaultExecuteResultHandler();
    ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);
    Executor executor = new DefaultExecutor();
    executor.setExitValue(returnValue);
    executor.setWatchdog(watchdog);
    executor.execute(cmdLine, resultHandler);
}

From source file:org.cloudifysource.dsl.context.utils.VolumeUtils.java

private static void executeCommandLine(final String commandLine, final long timeout)
        throws LocalStorageOperationException, TimeoutException {

    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    executor.setWatchdog(watchdog);//from   ww w.ja  v a  2s.c o m
    ProcessOutputStream outAndErr = new ProcessOutputStream();
    try {
        PumpStreamHandler streamHandler = new PumpStreamHandler(outAndErr);
        executor.setStreamHandler(streamHandler);
        logger.info("Executing commandLine : '" + commandLine + "'");
        executor.execute(CommandLine.parse(commandLine));
        logger.info("Execution completed successfully. Process output was : " + outAndErr.getOutput());
    } catch (final Exception e) {
        if (watchdog.killedProcess()) {
            throw new TimeoutException("Timed out while executing commandLine : '" + commandLine + "'");
        }
        throw new LocalStorageOperationException("Failed executing commandLine : '" + commandLine
                + ". Process output was : " + outAndErr.getOutput(), e);
    }
}

From source file:org.cloudifysource.utilitydomain.context.blockstorage.VolumeUtils.java

private static void executeCommandLine(final String commandLine, final long timeout)
        throws LocalStorageOperationException, TimeoutException {

    Executor executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    executor.setWatchdog(watchdog);//from  w  w w  . j  av a  2  s .c o  m
    ProcessOutputStream outAndErr = new ProcessOutputStream();
    try {
        PumpStreamHandler streamHandler = new PumpStreamHandler(outAndErr);
        executor.setStreamHandler(streamHandler);
        logger.info("Executing commandLine : '" + commandLine + "'");
        executor.execute(CommandLine.parse(commandLine));
        logger.info("Execution completed successfully. Process output was : " + outAndErr.getOutput());
    } catch (final Exception e) {
        if (watchdog.killedProcess()) {
            throw new TimeoutException("Timed out while executing commandLine : '" + commandLine + "'");
        }

        throw new LocalStorageOperationException("Failed executing commandLine : '" + commandLine
                + ". Process output was : " + outAndErr.getOutput(), e);
    }
}