Example usage for org.apache.commons.cli CommandLine getOptionValue

List of usage examples for org.apache.commons.cli CommandLine getOptionValue

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValue.

Prototype

public String getOptionValue(char opt) 

Source Link

Document

Retrieve the argument, if any, of this option.

Usage

From source file:com.astexample.RecognizeGoogleTest.java

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

    String audioFile = "";
    String host = "speech.googleapis.com";
    Integer port = 443;/*from   w  w w .ja  va2  s . co m*/
    Integer sampling = 16000;

    CommandLineParser parser = new DefaultParser();

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg()
            .withArgName("FILE_PATH").create());
    options.addOption(
            OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com")
                    .hasArg().withArgName("ENDPOINT").create());
    options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg()
            .withArgName("PORT").create());
    options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000")
            .hasArg().withArgName("RATE").create());

    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("file")) {
            audioFile = line.getOptionValue("file");
        } else {
            System.err.println("An Audio file must be specified (e.g. /foo/baz.raw).");
            System.exit(1);
        }

        if (line.hasOption("host")) {
            host = line.getOptionValue("host");
        } else {
            System.err.println("An API enpoint must be specified (typically speech.googleapis.com).");
            System.exit(1);
        }

        if (line.hasOption("port")) {
            port = Integer.parseInt(line.getOptionValue("port"));
        } else {
            System.err.println("An SSL port must be specified (typically 443).");
            System.exit(1);
        }

        if (line.hasOption("sampling")) {
            sampling = Integer.parseInt(line.getOptionValue("sampling"));
        } else {
            System.err.println("An Audio sampling rate must be specified.");
            System.exit(1);
        }
    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        System.exit(1);
    }

    RecognizeGoogleTest client = new RecognizeGoogleTest(host, port, audioFile, sampling);
    try {
        client.recognize();
    } finally {
        client.shutdown();
    }
}

From source file:com.google.cloud.speech.grpc.demos.RecognizeClient.java

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

    String audioFile = "";
    String host = "speech.googleapis.com";
    Integer port = 443;//from www.j  a  v a 2s . c  om
    Integer sampling = 16000;

    CommandLineParser parser = new DefaultParser();

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg()
            .withArgName("FILE_PATH").create());
    options.addOption(
            OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com")
                    .hasArg().withArgName("ENDPOINT").create());
    options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg()
            .withArgName("PORT").create());
    options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000")
            .hasArg().withArgName("RATE").create());

    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("file")) {
            audioFile = line.getOptionValue("file");
        } else {
            System.err.println("An Audio file must be specified (e.g. /foo/baz.raw).");
            System.exit(1);
        }

        if (line.hasOption("host")) {
            host = line.getOptionValue("host");
        } else {
            System.err.println("An API enpoint must be specified (typically speech.googleapis.com).");
            System.exit(1);
        }

        if (line.hasOption("port")) {
            port = Integer.parseInt(line.getOptionValue("port"));
        } else {
            System.err.println("An SSL port must be specified (typically 443).");
            System.exit(1);
        }

        if (line.hasOption("sampling")) {
            sampling = Integer.parseInt(line.getOptionValue("sampling"));
        } else {
            System.err.println("An Audio sampling rate must be specified.");
            System.exit(1);
        }
    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        System.exit(1);
    }

    RecognizeClient client = new RecognizeClient(host, port, audioFile, sampling);
    try {
        client.recognize();
    } finally {
        client.shutdown();
    }
}

From source file:com.dhenton9000.screenshots.ScreenShotLauncher.java

/**
 * main launching method that takes command line arguments
 *
 * @param args/* w  w  w.  ja  va  2  s.  c o  m*/
 */
public static void main(String[] args) {

    final String[] actions = { ACTIONS.source.toString(), ACTIONS.target.toString(),
            ACTIONS.compare.toString() };
    final List actionArray = Arrays.asList(actions);

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("action").hasArg().isRequired().withArgName("action").create());
    HelpFormatter formatter = new HelpFormatter();

    String header = "Process screenshots\n" + "--action=source   create source screenshots\n"
            + "--action=target     create the screenshots for comparison\n"
            + "--action=compare  compare the images\n" + "%s\n\n";

    String action = null;
    try {
        // parse the command line arguments
        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, args);

        // validate that action option has been set
        if (line.hasOption("action")) {
            action = line.getOptionValue("action");
            LOG.debug("action '" + action + "'");
            if (!actionArray.contains(action)) {

                formatter.printHelp(ScreenShotLauncher.class.getName(),
                        String.format(header, String.format("action option '%s' is invalid", action)), options,
                        "\n\n", true);
                System.exit(1);

            }

        } else {
            formatter.printHelp(ScreenShotLauncher.class.getName(), String.format(header, "not found"), options,
                    "\n\n", false);
            System.exit(1);
        }
    } catch (ParseException exp) {
        formatter.printHelp(ScreenShotLauncher.class.getName(),
                String.format(header, "problem " + exp.getMessage()), options, "\n\n", false);
        System.exit(1);

    }
    ACTIONS actionEnum = ACTIONS.valueOf(action);
    ScreenShotLauncher launcher = new ScreenShotLauncher();
    try {
        launcher.handleRequest(actionEnum);
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);

    }
}

From source file:edu.cmu.lti.oaqa.knn4qa.apps.GenTranEmbeddings.java

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

    options.addOption(CommonParams.MEMINDEX_PARAM, null, true, CommonParams.MEMINDEX_DESC);
    options.addOption(CommonParams.GIZA_ROOT_DIR_PARAM, null, true, CommonParams.GIZA_ROOT_DIR_DESC);
    options.addOption(CommonParams.GIZA_ITER_QTY_PARAM, null, true, CommonParams.GIZA_ITER_QTY_DESC);
    options.addOption(OUT_FILE_PARAM, null, true, OUT_FILE_DESC);
    options.addOption(MAX_MODEL_ORDER_PARAM, null, true, MAX_MODEL_ORDER_DESC);
    options.addOption(MIN_PROB_PARAM, null, true, MIN_PROB_DESC);
    options.addOption(MAX_DIGIT_PARAM, null, true, MAX_DIGIT_DESC);
    options.addOption(CommonParams.MAX_WORD_QTY_PARAM, null, true, CommonParams.MAX_WORD_QTY_PARAM);

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    try {/*from w w  w.  j av  a  2  s . c  om*/
        CommandLine cmd = parser.parse(options, args);

        int maxWordQty = Integer.MAX_VALUE;

        String tmpi = cmd.getOptionValue(CommonParams.MAX_WORD_QTY_PARAM);

        if (null != tmpi) {
            maxWordQty = Integer.parseInt(tmpi);
        }

        String memIndexPref = cmd.getOptionValue(CommonParams.MEMINDEX_PARAM);

        if (null == memIndexPref) {
            Usage("Specify '" + CommonParams.MEMINDEX_DESC + "'", options);
        }
        String gizaRootDir = cmd.getOptionValue(CommonParams.GIZA_ROOT_DIR_PARAM);
        if (null == gizaRootDir) {
            Usage("Specify '" + CommonParams.GIZA_ROOT_DIR_PARAM + "'", options);
        }
        int gizaIterQty = -1;
        if (cmd.hasOption(CommonParams.GIZA_ITER_QTY_PARAM)) {
            gizaIterQty = Integer.parseInt(cmd.getOptionValue(CommonParams.GIZA_ITER_QTY_PARAM));
        }
        if (gizaIterQty <= 0) {
            Usage("Specify '" + CommonParams.GIZA_ITER_QTY_DESC + "'", options);
        }
        int maxModelOrder = -1;
        if (cmd.hasOption(MAX_MODEL_ORDER_PARAM)) {
            maxModelOrder = Integer.parseInt(cmd.getOptionValue(MAX_MODEL_ORDER_PARAM));
        }
        String outFilePrefix = cmd.getOptionValue(OUT_FILE_PARAM);
        if (null == outFilePrefix) {
            Usage("Specify '" + OUT_FILE_DESC + "'", options);
        }

        float minProb = 0;

        if (cmd.hasOption(MIN_PROB_PARAM)) {
            minProb = Float.parseFloat(cmd.getOptionValue(MIN_PROB_PARAM));
        } else {
            Usage("Specify '" + MIN_PROB_DESC + "'", options);
        }

        int maxDigit = 5;
        if (cmd.hasOption(MAX_DIGIT_PARAM)) {
            maxDigit = Integer.parseInt(cmd.getOptionValue(MAX_DIGIT_PARAM));
        }

        // We use unlemmatized text here, because lemmatized dictionary is going to be mostly subset of the unlemmatized one.
        int fieldId = FeatureExtractor.TEXT_UNLEMM_FIELD_ID;

        String memFwdIndxName = FeatureExtractor.indexFileName(memIndexPref,
                FeatureExtractor.mFieldNames[fieldId]);

        FrequentIndexWordFilterAndRecoder filterAndRecoder = new FrequentIndexWordFilterAndRecoder(
                memFwdIndxName, maxWordQty);

        InMemForwardIndex index = new InMemForwardIndex(memFwdIndxName);
        BM25SimilarityLucene simil = new BM25SimilarityLucene(FeatureExtractor.BM25_K1, FeatureExtractor.BM25_B,
                index);
        String prefix = gizaRootDir + "/" + FeatureExtractor.mFieldNames[fieldId] + "/";

        GizaVocabularyReader answVoc = new GizaVocabularyReader(prefix + "source.vcb", filterAndRecoder);
        GizaVocabularyReader questVoc = new GizaVocabularyReader(prefix + "target.vcb", filterAndRecoder);

        GizaTranTableReaderAndRecoder answToQuestTran = new GizaTranTableReaderAndRecoder(
                false /* don't flip a translation table */, prefix + "/output.t1." + gizaIterQty,
                filterAndRecoder, answVoc, questVoc, (float) FeatureExtractor.DEFAULT_PROB_SELF_TRAN, minProb);

        int order = 0;

        System.out.println("Starting to compute the 0-order model");
        HashIntObjMap<SparseVector> currModel = SparseEmbeddingReaderAndRecorder.createTranVecDict(index,
                filterAndRecoder, minProb, answToQuestTran);
        System.out.println("0-order model is computed");
        SparseEmbeddingReaderAndRecorder.saveDict(index, outFilePrefix + ".0", currModel, maxDigit);
        System.out.println("0-order model is saved");

        while (order < maxModelOrder) {
            ++order;
            System.out.println("Starting to compute the " + order + "-order model");
            currModel = SparseEmbeddingReaderAndRecorder.nextOrderDict(currModel, index, minProb,
                    answToQuestTran);
            System.out.println(order + "-order model is computed");
            SparseEmbeddingReaderAndRecorder.saveDict(index, outFilePrefix + "." + order, currModel, maxDigit);
            System.out.println(order + "-order model is saved");
        }

    } catch (ParseException e) {
        Usage("Cannot parse arguments", options);
    } catch (Exception e) {
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    }

    System.out.println("Terminated successfully!");

}

From source file:HBBRequestor.java

public static void main(String[] args) throws Exception {
    String hostId = "";
    String partnerId = "";
    String userId = "";

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption("h", "host", true, "EBICS Host ID");
    options.addOption("p", "partner", true, "Registred Partner ID for you user");
    options.addOption("u", "user", true, "User ID to initiate");

    // Parse the program arguments
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption('h')) {
        System.out.println("Host-ID is mandatory");
        System.exit(0);/*from  w ww .  j a  v a  2s .  c o  m*/
    } else {
        hostId = commandLine.getOptionValue('h');
        System.out.println("host: " + hostId);
    }

    if (!commandLine.hasOption('p')) {
        System.out.println("Partner-ID is mandatory");
        System.exit(0);
    } else {
        partnerId = commandLine.getOptionValue('p');
        System.out.println("partnerId: " + partnerId);
    }

    if (!commandLine.hasOption('u')) {
        System.out.println("User-ID is mandatory");
        System.exit(0);
    } else {
        userId = commandLine.getOptionValue('u');
        System.out.println("userId: " + userId);
    }

    HBBRequestor hbbRequestor;
    PasswordCallback pwdHandler;
    Product product;

    hbbRequestor = new HBBRequestor();
    product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null);
    pwdHandler = new UserPasswordHandler(userId, "2012");

    // Load alredy created user
    hbbRequestor.loadUser(hostId, partnerId, userId, pwdHandler);

    // Send hbb Requets
    hbbRequestor.sendHPBRequest(userId, product);

    // Perform save for the changed data
    hbbRequestor.quit();
}

From source file:FDLRequestor.java

public static void main(String[] args) throws Exception {
    String hostId = "";
    String partnerId = "";
    String userId = "";

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption("h", "host", true, "EBICS Host ID");
    options.addOption("p", "partner", true, "Registred Partner ID for you user");
    options.addOption("u", "user", true, "User ID to initiate");

    // Parse the program arguments
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption('h')) {
        System.out.println("Host-ID is mandatory");
        System.exit(0);//from   w ww  .  ja v a2 s .c o m
    } else {
        hostId = commandLine.getOptionValue('h');
        System.out.println("host: " + hostId);
    }

    if (!commandLine.hasOption('p')) {
        System.out.println("Partner-ID is mandatory");
        System.exit(0);
    } else {
        partnerId = commandLine.getOptionValue('p');
        System.out.println("partnerId: " + partnerId);
    }

    if (!commandLine.hasOption('u')) {
        System.out.println("User-ID is mandatory");
        System.exit(0);
    } else {
        userId = commandLine.getOptionValue('u');
        System.out.println("userId: " + userId);
    }

    FDLRequestor fdlRequestor;
    PasswordCallback pwdHandler;
    Product product;
    String filePath;

    fdlRequestor = new FDLRequestor();
    product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null);
    pwdHandler = new UserPasswordHandler(userId, "2012");

    // Load alredy created user
    fdlRequestor.loadUser(hostId, partnerId, userId, pwdHandler);

    filePath = System.getProperty("user.home") + File.separator + "download.txt";

    // Send FDL Requets
    fdlRequestor.fetchFile(filePath, userId, product, OrderType.FDL, true, null, null);
}

From source file:FULRequestor.java

public static void main(String[] args) throws Exception {
    String hostId = "";
    String partnerId = "";
    String userId = "";

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption("h", "host", true, "EBICS Host ID");
    options.addOption("p", "partner", true, "Registred Partner ID for you user");
    options.addOption("u", "user", true, "User ID to initiate");

    // Parse the program arguments
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption('h')) {
        System.out.println("Host-ID is mandatory");
        System.exit(0);// w  ww  .  j a  va2 s . c  o m
    } else {
        hostId = commandLine.getOptionValue('h');
        System.out.println("host: " + hostId);
    }

    if (!commandLine.hasOption('p')) {
        System.out.println("Partner-ID is mandatory");
        System.exit(0);
    } else {
        partnerId = commandLine.getOptionValue('p');
        System.out.println("partnerId: " + partnerId);
    }

    if (!commandLine.hasOption('u')) {
        System.out.println("User-ID is mandatory");
        System.exit(0);
    } else {
        userId = commandLine.getOptionValue('u');
        System.out.println("userId: " + userId);
    }

    FULRequestor hbbRequestor;
    PasswordCallback pwdHandler;
    Product product;
    String filePath;

    hbbRequestor = new FULRequestor();
    product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null);
    pwdHandler = new UserPasswordHandler(userId, "2012");

    // Load alredy created user
    hbbRequestor.loadUser(hostId, partnerId, userId, pwdHandler);

    filePath = System.getProperty("user.home") + File.separator + "test.txt";
    // Send FUL Requets
    hbbRequestor.sendFile(filePath, userId, product);
}

From source file:ee.ria.xroad.proxy.opmonitoring.OpMonitoringBufferMemoryUsage.java

/**
 * Main function./* w  w  w  .  j a  v a  2  s.  c  om*/
 * @param args args
 * @throws Exception if something goes wrong.
 */
public static void main(String args[]) throws Exception {

    CommandLine cmd = parseCommandLine(args);

    if (cmd.hasOption("help")) {
        usage();

        System.exit(0);
    }

    int count = cmd.getOptionValue("count") != null ? Integer.parseInt(cmd.getOptionValue("count"))
            : DEFAULT_COUNT;

    int shortStrLen = cmd.getOptionValue("short-string-length") != null
            ? Integer.parseInt(cmd.getOptionValue("short-string-length"))
            : DEFAULT_SHORT_LONG_STRING_LENGTH;

    int longStrLen = cmd.getOptionValue("long-string-length") != null
            ? Integer.parseInt(cmd.getOptionValue("long-string-length"))
            : DEFAULT_LONG_STRING_LENGTH;

    Runtime runtime = Runtime.getRuntime();

    long before = getUsedBytes(runtime);

    createBuffer(count, shortStrLen, longStrLen);

    long after = getUsedBytes(runtime);

    log.info("Records count {}, used heap {}MB", count, (after - before) / MB);
}

From source file:com.dumontierlab.pdb2rdf.cluster.ClusterServer.java

public static void main(String[] args) {

    Options options = createOptions();//from   ww w  .java  2s.c o  m
    CommandLineParser parser = createCliParser();

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

        if (!cmd.hasOption("dir")) {
            LOG.fatal("You need to specify the input directory");
            System.exit(1);
        }
        File inputDir = new File(cmd.getOptionValue("dir"));
        if (!inputDir.exists() || !inputDir.isDirectory()) {
            LOG.fatal("The specified input directory is not a valid directory");
            System.exit(1);
        }

        int port = DEFAULT_PORT;
        if (cmd.hasOption("port")) {
            try {
                port = Integer.parseInt(cmd.getOptionValue("port"));
            } catch (NumberFormatException e) {
                LOG.fatal("Invalid port number", e);
                System.exit(1);
            }
        }
        boolean gzip = cmd.hasOption("gzip");

        try {
            startServer(inputDir, gzip, port);
        } catch (Exception e) {
            LOG.fatal("Unable to start the server.", e);
            System.exit(1);
        }

    } catch (ParseException e) {
        LOG.fatal("Unable understand your command.");
        printUsage();
        System.exit(1);
    }

}

From source file:com.yahoo.pasc.paxos.server.PaxosServer.java

/**
 * @param args//  ww  w  .  j a v a 2s  .  c  o m
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IOException 
 * @throws MalformedURLException
 */
public static void main(String[] args) throws SecurityException, NoSuchFieldException, IOException {

    CommandLineParser parser = new PosixParser();
    Options options;

    {
        Option id = new Option("i", true, "client id");
        Option port = new Option("p", true, "port used by server");
        Option buffer = new Option("b", true, "number of batched messages");
        //            Option clients      = new Option("c", true, "clients (hostname:port,...)");
        Option servers = new Option("s", true, "servers (hostname:port,...)");
        Option maxInstances = new Option("m", true, "max number of instances");
        Option anm = new Option("a", false, "protection against ANM faults");
        Option udp = new Option("u", false, "use UDP");
        Option cWindow = new Option("w", true, "congestion window");
        Option threads = new Option("t", true, "number of threads");
        Option digests = new Option("d", true, "max digests");
        Option ckPeriod = new Option("k", true, "checkpointing period");
        Option inlineThresh = new Option("n", true, "threshold for sending requests iNline with accepts ");
        Option twoStages = new Option("2", false, "2 stages");
        Option digestQuorum = new Option("q", true, "digest quorum");
        Option leaderReplies = new Option("r", false, "leader replies");
        Option zookeeper = new Option("z", true, "zookeeper connection string");

        options = new Options();
        options.addOption(id).addOption(port).addOption(buffer).addOption(servers).addOption(threads)
                .addOption(anm).addOption(udp).addOption(maxInstances) //.addOption(leader)
                .addOption(cWindow).addOption(digests).addOption(ckPeriod).addOption(inlineThresh)
                .addOption(twoStages).addOption(digestQuorum).addOption(leaderReplies).addOption(zookeeper);
    }

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

        String serverAddresses[] = line.hasOption('s') ? line.getOptionValue('s').split(",")
                : new String[] { "10.78.36.104:20548", "10.78.36.104:20748" };
        //            String clientAddresses[] = line.hasOption('c') ? line.getOptionValue('c').split(",") : new String[] { "localhost:9000" };
        String zookeeper = line.hasOption('z') ? line.getOptionValue('z') : "localhost:2181";
        int serverId = line.hasOption('i') ? Integer.parseInt(line.getOptionValue('i')) : 0;
        int batchSize = line.hasOption('b') ? Integer.parseInt(line.getOptionValue('b')) : 1;
        int port = line.hasOption('p') ? Integer.parseInt(line.getOptionValue('p')) : 20548;
        int maxInstances = line.hasOption('m') ? Integer.parseInt(line.getOptionValue('m')) : 16 * 1024;
        int congestionWindow = line.hasOption('w') ? Integer.parseInt(line.getOptionValue('w')) : 1;
        int digests = line.hasOption('d') ? Integer.parseInt(line.getOptionValue('d')) : 16;
        int inlineThreshold = line.hasOption('n') ? Integer.parseInt(line.getOptionValue('n')) : 1000;
        boolean protection = line.hasOption('a');
        boolean udp = line.hasOption('u');
        boolean twoStages = line.hasOption('2');
        int quorum = serverAddresses.length / 2 + 1;
        int digestQuorum = line.hasOption('q') ? Integer.parseInt(line.getOptionValue('q')) : quorum;
        int threads = line.hasOption('t') ? Integer.parseInt(line.getOptionValue('t'))
                : Runtime.getRuntime().availableProcessors() * 2 + 1;

        if (batchSize <= 0) {
            throw new RuntimeException("BatchSize must be greater than 0");
        }

        PaxosState state = new PaxosState(maxInstances, batchSize, serverId, quorum, digestQuorum,
                serverAddresses.length, congestionWindow, digests);
        if (line.hasOption('k'))
            state.setCheckpointPeriod(Integer.parseInt(line.getOptionValue('k')));
        if (line.hasOption('r'))
            state.setLeaderReplies(true);
        state.setRequestThreshold(inlineThreshold);

        if (!protection) {
            System.out.println("PANM disabled!");
        }

        final PascRuntime<PaxosState> runtime = new PascRuntime<PaxosState>(protection);
        runtime.setState(state);
        runtime.addHandler(Accept.class, new AcceptorAccept());
        runtime.addHandler(Prepare.class, new AcceptorPrepare());
        runtime.addHandler(Accepted.class, new Learner());
        runtime.addHandler(Prepared.class, new ProposerPrepared());
        runtime.addHandler(Request.class, new ProposerRequest());
        runtime.addHandler(InlineRequest.class, new ProposerRequest());
        runtime.addHandler(Digest.class, new DigestHandler());
        runtime.addHandler(PreReply.class, new LearnerPreReply());
        runtime.addHandler(Leader.class, new LeadershipHandler());

        if (udp) {
            new UdpServer(runtime, serverAddresses, null, port, threads, serverId).run();
        } else {
            new TcpServer(runtime, new EmptyStateMachine(), null, zookeeper, serverAddresses, port, threads,
                    serverId, twoStages).run();
        }
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Paxos", options);

        System.err.println("Unexpected exception: " + e);
        e.printStackTrace();

        System.exit(-1);
    }
}