Example usage for org.apache.commons.cli OptionBuilder withArgName

List of usage examples for org.apache.commons.cli OptionBuilder withArgName

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder withArgName.

Prototype

public static OptionBuilder withArgName(String name) 

Source Link

Document

The next Option created will have the specified argument value name.

Usage

From source file:com.github.zk1931.zabkv.Main.java

public static void main(String[] args) throws Exception {
    // Options for command arguments.
    Options options = new Options();

    Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number")
            .create("port");

    Option ip = OptionBuilder.withArgName("ip").hasArg(true).isRequired(true)
            .withDescription("current ip address").create("ip");

    Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.")
            .create("join");

    Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help")
            .withDescription("print out usages.").create("h");

    options.addOption(port).addOption(ip).addOption(join).addOption(help);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;/*from  w ww . j av a2  s. co  m*/

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("zabkv", options);
            return;
        }
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("zabkv", options);
        return;
    }

    int zabPort = Integer.parseInt(cmd.getOptionValue("port"));
    String myIp = cmd.getOptionValue("ip");

    if (zabPort < 5000 && zabPort >= 5010) {
        System.err.println("port parameter can have value only between 5000 & 5010");
        System.exit(1);
    }

    int serverPort = zabPort % 5000 + 8000;

    Database db = new Database(myIp, zabPort, cmd.getOptionValue("join"));

    Server server = new Server(serverPort);
    ServletHandler handler = new ServletHandler();
    server.setHandler(handler);
    ServletHolder holder = new ServletHolder(new RequestHandler(db));
    handler.addServletWithMapping(holder, "/*");
    server.start();
    server.join();
    System.out.println("hi");
}

From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyJson.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;/*from w w w .  j a v a2 s . c  o m*/
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> pairs = SequenceFileUtils
            .readDirectory(new Path(inputPath));

    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list1 = Lists.newArrayList();
    List<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> list2 = Lists.newArrayList();

    for (PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p : pairs) {
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();

        if (bigram.getJsonObject().get("Left").getAsString().equals("light")) {
            list1.add(p);
        }

        if (bigram.getJsonObject().get("Left").getAsString().equals("contain")) {
            list2.add(p);
        }
    }

    Collections.sort(list1,
            new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() {
                public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1,
                        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) {
                    if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                        return e1.getLeftElement().compareTo(e2.getLeftElement());
                    }

                    return e2.getRightElement().compareTo(e1.getRightElement());
                }
            });

    Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter1 = Iterators
            .limit(list1.iterator(), 10);
    while (iter1.hasNext()) {
        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter1.next();
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }

    Collections.sort(list2,
            new Comparator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>>() {
                public int compare(PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e1,
                        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> e2) {
                    if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                        return e1.getLeftElement().compareTo(e2.getLeftElement());
                    }

                    return e2.getRightElement().compareTo(e1.getRightElement());
                }
            });

    Iterator<PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable>> iter2 = Iterators
            .limit(list2.iterator(), 10);
    while (iter2.hasNext()) {
        PairOfWritables<BigramRelativeFrequencyJson.MyTuple, FloatWritable> p = iter2.next();
        BigramRelativeFrequencyJson.MyTuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }
}

From source file:edu.usc.pgroup.floe.client.commands.Scale.java

/**
 * Entry point for Scale command./*from   ww  w .  java 2  s  .c o  m*/
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option dirOption = OptionBuilder.withArgName("direction").hasArg().isRequired()
            .withDescription("Scale Direction.").create("dir");

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option cntOption = OptionBuilder.withArgName("num").hasArg().withType(new String())
            .withDescription("Number of instances to scale up/down").create("cnt");

    options.addOption(dirOption);
    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(cntOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String dir = line.getOptionValue("dir");
    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String cnt = line.getOptionValue("cnt");

    LOGGER.info("direction: {}", dir);
    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("count: {}", cnt);

    ScaleDirection direction = Enum.valueOf(ScaleDirection.class, dir);
    int count = Integer.parseInt(cnt);
    try {
        FloeClient.getInstance().getClient().scale(direction, app, pellet, count);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:com.hurence.logisland.runner.StreamProcessingRunner.java

/**
 * main entry point/*  www.  j  ava2  s.  c  o m*/
 *
 * @param args
 */
public static void main(String[] args) {

    logger.info("starting StreamProcessingRunner");

    //////////////////////////////////////////
    // Commande lien management
    Parser parser = new GnuParser();
    Options options = new Options();

    String helpMsg = "Print this message.";
    Option help = new Option("help", helpMsg);
    options.addOption(help);

    OptionBuilder.withArgName("conf");
    OptionBuilder.withLongOpt("config-file");
    OptionBuilder.isRequired();
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("config file path");
    Option conf = OptionBuilder.create("conf");
    options.addOption(conf);

    Optional<EngineContext> engineInstance = Optional.empty();
    try {
        System.out.println(BannerLoader.loadBanner());

        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String configFile = line.getOptionValue("conf");

        // load the YAML config
        LogislandConfiguration sessionConf = ConfigReader.loadConfig(configFile);

        // instantiate engine and all the processor from the config
        engineInstance = ComponentFactory.getEngineContext(sessionConf.getEngine());
        if (!engineInstance.isPresent()) {
            throw new IllegalArgumentException("engineInstance could not be instantiated");
        }
        if (!engineInstance.get().isValid()) {
            throw new IllegalArgumentException("engineInstance is not valid with input configuration !");
        }
        logger.info("starting Logisland session version {}", sessionConf.getVersion());
        logger.info(sessionConf.getDocumentation());
    } catch (Exception e) {
        logger.error("unable to launch runner", e);
        System.exit(-1);
    }
    String engineName = engineInstance.get().getEngine().getIdentifier();
    try {
        // start the engine
        EngineContext engineContext = engineInstance.get();
        logger.info("start engine {}", engineName);
        engineInstance.get().getEngine().start(engineContext);
        logger.info("awaitTermination for engine {}", engineName);
        engineContext.getEngine().awaitTermination(engineContext);
        System.exit(0);
    } catch (Exception e) {
        logger.error("something went bad while running the job {} : {}", engineName, e);
        System.exit(-1);
    }

}

From source file:cc.twittertools.util.ExtractSubcollection.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory")
            .create(COLLECTION_OPTION));
    options.addOption(/* w w w  .  ja  v  a 2  s.  c o  m*/
            OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION));

    CommandLine cmdline = null;
    CommandLineParser parser = new GnuParser();
    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ExtractSubcollection.class.getName(), options);
        System.exit(-1);
    }

    String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION);

    LongOpenHashSet tweetids = new LongOpenHashSet();
    File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION));
    if (!tweetidsFile.exists()) {
        System.err.println("Error: " + tweetidsFile + " does not exist!");
        System.exit(-1);
    }
    LOG.info("Reading tweetids from " + tweetidsFile);

    FileInputStream fin = new FileInputStream(tweetidsFile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));

    String s;
    while ((s = br.readLine()) != null) {
        tweetids.add(Long.parseLong(s));
    }
    br.close();
    fin.close();
    LOG.info("Read " + tweetids.size() + " tweetids.");

    File file = new File(collectionPath);
    if (!file.exists()) {
        System.err.println("Error: " + file + " does not exist!");
        System.exit(-1);
    }

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    StatusStream stream = new JsonStatusCorpusReader(file);
    Status status;
    while ((status = stream.next()) != null) {
        if (tweetids.contains(status.getId())) {
            out.println(status.getJsonObject().toString());
        }
    }
    stream.close();
    out.close();
}

From source file:fr.cnrs.sharp.Main.java

public static void main(String args[]) {
    Options options = new Options();

    Option versionOpt = new Option("v", "version", false, "print the version information and exit");
    Option helpOpt = new Option("h", "help", false, "print the help");

    Option inProvFileOpt = OptionBuilder.withArgName("input_PROV_file_1> ... <input_PROV_file_n")
            .withLongOpt("input_PROV_files").withDescription("The list of PROV input files, in RDF Turtle.")
            .hasArgs().create("i");

    Option inRawFileOpt = OptionBuilder.withArgName("input_raw_file_1> ... <input_raw_file_n")
            .withLongOpt("input_raw_files")
            .withDescription(//  ww  w  . j a v a 2s . co m
                    "The list of raw files to be fingerprinted and possibly interlinked with owl:sameAs.")
            .hasArgs().create("ri");

    Option summaryOpt = OptionBuilder.withArgName("summary").withLongOpt("summary")
            .withDescription("Materialization of wasInfluencedBy relations.").create("s");

    options.addOption(inProvFileOpt);
    options.addOption(inRawFileOpt);
    options.addOption(versionOpt);
    options.addOption(helpOpt);
    options.addOption(summaryOpt);

    String header = "SharpTB is a tool to maturate provenance based on PROV inferences";
    String footer = "\nPlease report any issue to alban.gaignard@univ-nantes.fr";

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("SharpTB", header, options, footer, true);
            System.exit(0);
        }

        if (cmd.hasOption("v")) {
            logger.info("SharpTB version 0.1.0");
            System.exit(0);
        }

        if (cmd.hasOption("ri")) {
            String[] inFiles = cmd.getOptionValues("ri");
            Model model = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    //1. fingerprint
                    try {
                        model.add(Interlinking.fingerprint(p));
                    } catch (IOException e) {
                        logger.error("Cannot fingerprint file " + inFile);
                    }
                }
            }
            //2. genSameAs
            Model sameAs = Interlinking.generateSameAs(model);
            sameAs.write(System.out, "TTL");
        }

        if (cmd.hasOption("i")) {
            String[] inFiles = cmd.getOptionValues("i");
            Model data = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    RDFDataMgr.read(data, inFile, Lang.TTL);
                }
            }
            Model res = Harmonization.harmonizeProv(data);

            try {
                Path pathInfProv = Files.createTempFile("PROV-inf-tgd-egd-", ".ttl");
                res.write(new FileWriter(pathInfProv.toFile()), "TTL");
                System.out.println("Harmonized PROV written to file " + pathInfProv.toString());

                //if the summary option is activated, then save the subgraph and generate a visualization
                if (cmd.hasOption("s")) {

                    String queryInfluence = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
                            + "PREFIX prov: <http://www.w3.org/ns/prov#> \n" + "CONSTRUCT { \n"
                            + "    ?x ?p ?y .\n" + "    ?x rdfs:label ?lx .\n" + "    ?y rdfs:label ?ly .\n"
                            + "} WHERE {\n" + "    ?x ?p ?y .\n"
                            + "    FILTER (?p IN (prov:wasInfluencedBy)) .\n" + "    ?x rdfs:label ?lx .\n"
                            + "    ?y rdfs:label ?ly .\n" + "}";

                    Query query = QueryFactory.create(queryInfluence);
                    QueryExecution queryExec = QueryExecutionFactory.create(query, res);
                    Model summary = queryExec.execConstruct();
                    queryExec.close();
                    Util.writeHtmlViz(summary);
                }

            } catch (IOException ex) {
                logger.error("Impossible to write the harmonized provenance file.");
                System.exit(1);
            }
        } else {
            //                logger.info("Please fill the -i input parameter.");
            //                HelpFormatter formatter = new HelpFormatter();
            //                formatter.printHelp("SharpTB", header, options, footer, true);
            //                System.exit(0);
        }

    } catch (ParseException ex) {
        logger.error("Error while parsing command line arguments. Please check the following help:");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("SharpToolBox", header, options, footer, true);
        System.exit(1);
    }
}

From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequency.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;//from  ww w . ja va  2 s.c o m
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzeBigramRelativeFrequency.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    List<PairOfWritables<PairOfStrings, FloatWritable>> pairs = SequenceFileUtils
            .readDirectory(new Path(inputPath));

    List<PairOfWritables<PairOfStrings, FloatWritable>> list1 = Lists.newArrayList();
    List<PairOfWritables<PairOfStrings, FloatWritable>> list2 = Lists.newArrayList();

    for (PairOfWritables<PairOfStrings, FloatWritable> p : pairs) {
        PairOfStrings bigram = p.getLeftElement();

        if (bigram.getLeftElement().equals("light")) {
            list1.add(p);
        }
        if (bigram.getLeftElement().equals("contain")) {
            list2.add(p);
        }
    }

    Collections.sort(list1, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
        public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
                PairOfWritables<PairOfStrings, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10);
    while (iter1.hasNext()) {
        PairOfWritables<PairOfStrings, FloatWritable> p = iter1.next();
        PairOfStrings bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }

    Collections.sort(list2, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
        public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
                PairOfWritables<PairOfStrings, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10);
    while (iter2.hasNext()) {
        PairOfWritables<PairOfStrings, FloatWritable> p = iter2.next();
        PairOfStrings bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }
}

From source file:net.ovres.tuxcourser.TuxCourser.java

public static void main(String[] argss) throws Exception {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("WARN|INFO|FINE").hasArg()
            .withDescription("Set the log level. Valid values include WARN, INFO, and FINE.")
            .withLongOpt("loglevel").create("l"));
    options.addOption("h", "help", false, "Displays this help and exits");
    options.addOption("v", "version", false, "Displays version information and exits");

    options.addOption(OptionBuilder.withArgName("TYPE").hasArg()
            .withDescription("Sets the output type. Valid values are tux11 and ppracer05").withLongOpt("output")
            .create());/*from   w w w  .ja va  2s  .c om*/

    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    try {
        line = parser.parse(options, argss);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        System.exit(-1);
    }

    if (line.hasOption("loglevel")) {
        String lvl = line.getOptionValue("loglevel");
        Level logLevel = Level.parse(lvl);
        Logger.getLogger("net.ovres.tuxcourser").setLevel(logLevel);
    }

    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar TuxCourser.jar [Options]", "Options", options, "");
        return;
    }
    if (line.hasOption("version")) {
        System.out.println("TuxCourser Version " + Settings.getVersion());
        return;
    }

    String[] remaining = line.getArgs();

    // Initialize all the different item and terrain types
    ModuleClassLoader.load();

    if (remaining.length == 0) { // Just show the gui.
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        new net.ovres.tuxcourser.gui.TuxCourserGui().setVisible(true);
    } else if (remaining.length == 3) {
        new TuxCourser().convertCourse(new File(remaining[0]), new File(remaining[1]), remaining[2],
                TYPE_TUXRACER11);
    } else {
        usage();
        System.exit(-1);
    }
}

From source file:edu.usc.pgroup.floe.client.commands.Signal.java

/**
 * Entry point for Scale command./*from  w  w  w. j  av a  2 s. com*/
 * @param args command line arguments sent by the floe.py script.
 */
public static void main(final String[] args) {

    Options options = new Options();

    Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Application Name").create("app");

    Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("Pellet Name").create("pellet");

    Option signalOption = OptionBuilder.withArgName("data").hasArg().withType(new String())
            .withDescription("signal data to send to the pellet").create("data");

    options.addOption(appOption);
    options.addOption(pelletNameOption);
    options.addOption(signalOption);

    CommandLineParser parser = new BasicParser();
    CommandLine line;

    try {
        line = parser.parse(options, args);

    } catch (ParseException e) {
        LOGGER.error("Invalid command: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("scale options", options);
        return;
    }

    String app = line.getOptionValue("app");
    String pellet = line.getOptionValue("pellet");
    String data = line.getOptionValue("data");

    LOGGER.info("Application: {}", app);
    LOGGER.info("Pellet: {}", pellet);
    LOGGER.info("data: {}", data);

    byte[] datab = Utils.serialize(data);
    try {
        TSignal signal = new TSignal();
        signal.set_destApp(app);
        signal.set_destPellet(pellet);
        signal.set_data(datab);
        FloeClient.getInstance().getClient().signal(signal);
    } catch (TException e) {
        LOGGER.error("Error while connecting to the coordinator: {}", e);
    }
}

From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyTuple.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;//from   ww w .j a v a2 s  . co  m
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    List<PairOfWritables<Tuple, FloatWritable>> pairs = SequenceFileUtils.readDirectory(new Path(inputPath));

    List<PairOfWritables<Tuple, FloatWritable>> list1 = Lists.newArrayList();
    List<PairOfWritables<Tuple, FloatWritable>> list2 = Lists.newArrayList();

    for (PairOfWritables<Tuple, FloatWritable> p : pairs) {
        Tuple bigram = p.getLeftElement();

        if (bigram.get(0).equals("light")) {
            list1.add(p);
        }

        if (bigram.get(0).equals("contain")) {
            list2.add(p);
        }
    }

    Collections.sort(list1, new Comparator<PairOfWritables<Tuple, FloatWritable>>() {
        @SuppressWarnings("unchecked")
        public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<Tuple, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10);
    while (iter1.hasNext()) {
        PairOfWritables<Tuple, FloatWritable> p = iter1.next();
        Tuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }

    Collections.sort(list2, new Comparator<PairOfWritables<Tuple, FloatWritable>>() {
        @SuppressWarnings("unchecked")
        public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) {
            if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) {
                return e1.getLeftElement().compareTo(e2.getLeftElement());
            }

            return e2.getRightElement().compareTo(e1.getRightElement());
        }
    });

    Iterator<PairOfWritables<Tuple, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10);
    while (iter2.hasNext()) {
        PairOfWritables<Tuple, FloatWritable> p = iter2.next();
        Tuple bigram = p.getLeftElement();
        System.out.println(bigram + "\t" + p.getRightElement());
    }
}