Example usage for org.apache.commons.cli Options addOption

List of usage examples for org.apache.commons.cli Options addOption

Introduction

In this page you can find the example usage for org.apache.commons.cli Options addOption.

Prototype

public Options addOption(String opt, boolean hasArg, String description) 

Source Link

Document

Add an option that only contains a short-name.

Usage

From source file:com.vmware.photon.controller.common.auth.AuthOIDCRegistrar.java

public static int main(String[] args) {
    Options options = new Options();
    options.addOption(USERNAME_ARG, true, "Lightwave user name");
    options.addOption(PASSWORD_ARG, true, "Password");
    options.addOption(TARGET_ARG, true, "Registration Hostname or IPAddress"); // Possible
                                                                               // load-balancer
                                                                               // address
    options.addOption(MANAGEMENT_UI_REG_FILE_ARG, true, "Management UI Registration Path");
    options.addOption(SWAGGER_UI_REG_FILE_ARG, true, "Swagger UI Registration Path");
    options.addOption(HELP_ARG, false, "Help");

    try {//w ww.  j av  a 2 s  . co m
        String username = null;
        String password = null;
        String registrationAddress = null;
        String mgmtUiRegPath = null;
        String swaggerUiRegPath = null;

        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = null;
        cmd = parser.parse(options, args);

        if (cmd.hasOption(HELP_ARG)) {
            showUsage(options);
            return 0;
        }

        if (cmd.hasOption(USERNAME_ARG)) {
            username = cmd.getOptionValue(USERNAME_ARG);
        }

        if (cmd.hasOption(PASSWORD_ARG)) {
            password = cmd.getOptionValue(PASSWORD_ARG);
        }

        if (cmd.hasOption(TARGET_ARG)) {
            registrationAddress = cmd.getOptionValue(TARGET_ARG);
        }

        if (cmd.hasOption(MANAGEMENT_UI_REG_FILE_ARG)) {
            mgmtUiRegPath = cmd.getOptionValue(MANAGEMENT_UI_REG_FILE_ARG);
        }

        if (cmd.hasOption(SWAGGER_UI_REG_FILE_ARG)) {
            swaggerUiRegPath = cmd.getOptionValue(SWAGGER_UI_REG_FILE_ARG);
        }

        if (username == null || username.trim().isEmpty()) {
            throw new UsageException("Error: username is not specified");
        }

        if (password == null) {
            char[] passwd = System.console().readPassword("Password:");
            password = new String(passwd);
        }

        DomainInfo domainInfo = DomainInfo.build();

        AuthOIDCRegistrar registrar = new AuthOIDCRegistrar(domainInfo);

        registrar.register(registrationAddress, username, password, mgmtUiRegPath, swaggerUiRegPath);

        return 0;
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        return ERROR_PARSE_EXCEPTION;
    } catch (UsageException e) {
        System.err.println(e.getMessage());
        showUsage(options);
        return ERROR_USAGE_EXCEPTION;
    } catch (AuthException e) {
        System.err.println(e.getMessage());
        return ERROR_AUTH_EXCEPTION;
    }
}

From source file:com.yahoo.gondola.cli.GondolaAgent.java

public static void main(String[] args) throws ParseException, IOException {
    PropertyConfigurator.configure("conf/log4j.properties");
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    options.addOption("port", true, "Listening port");
    options.addOption("config", true, "config file");
    options.addOption("h", false, "help");
    CommandLine commandLine = parser.parse(options, args);

    if (commandLine.hasOption("help")) {
        new HelpFormatter().printHelp("GondolaAgent", options);
        return;//w w w  . j a  va  2 s . co  m
    }

    if (commandLine.hasOption("port")) {
        port = Integer.parseInt(commandLine.getOptionValue("port"));
    } else {
        port = 1200;
    }
    if (commandLine.hasOption("config")) {
        configFile = commandLine.getOptionValue("config");
    }

    config = new Config(new File(configFile));

    logger.info("Initialize system, kill all gondola processes");
    new DefaultExecutor().execute(org.apache.commons.exec.CommandLine.parse("bin/gondola-local-test.sh stop"));

    new GondolaAgent(port);
}

From source file:com.movielabs.availstool.AvailsTool.java

public static void main(String[] args) throws Exception {
    String fileName, outFile, sheetName;
    int sheetNum = -1;

    Logger log = LogManager.getLogger(AvailsTool.class.getName());
    log.info("Initializing logger");

    Options options = new Options();
    options.addOption(Opts.v.name(), false, "verbose mode");
    options.addOption(Opts.s.name(), true, "specify sheet");
    options.addOption(Opts.f.name(), true, "specify file name");
    options.addOption(Opts.o.name(), true, "specify output file name");
    options.addOption(Opts.sstoxml.name(), false, "convert avails spreadsheet to XML");
    options.addOption(Opts.xmltoss.name(), false, "convert avails XML to a spreadsheet");
    options.addOption(Opts.dumpsheet.name(), false, "dump a single sheet from a spreadsheet");
    options.addOption(Opts.dumpss.name(), false, "dump a spreadsheet file");
    options.addOption(Opts.wx.name(), false, "treat warning as fatal error");
    options.addOption(Opts.clean.name(), false, "clean up data entries");

    CommandLineParser cli = new DefaultParser();

    try {//from   w  w w  .  j av  a2s. com
        CommandLine cmd = cli.parse(options, args);
        boolean optToXML = cmd.hasOption(Opts.sstoxml.name());
        boolean optToSS = cmd.hasOption(Opts.xmltoss.name());
        boolean optDumpSS = cmd.hasOption(Opts.dumpss.name());
        boolean optDumpSheet = cmd.hasOption(Opts.dumpsheet.name());
        fileName = cmd.getOptionValue(Opts.f.name());
        sheetName = cmd.getOptionValue(Opts.s.name());
        boolean clean = cmd.hasOption(Opts.clean.name());
        boolean wx = cmd.hasOption(Opts.wx.name());
        boolean verbose = cmd.hasOption(Opts.v.name());
        AvailSS ss;
        AvailsSheet as;
        String message;

        if (sheetName != null) {
            Pattern pat = Pattern.compile("^\\d+$");
            Matcher m = pat.matcher(sheetName);
            if (m.matches())
                sheetNum = Integer.parseInt(sheetName);
        }

        if (fileName == null)
            throw new ParseException("input file not specified");

        if (!(optToXML | optToSS | optDumpSS | optDumpSheet))
            throw new ParseException("missing operation");

        if (optToXML) {
            if (optToSS | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");

            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);
            message = "toXML file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            log.info("Options: -clean:" + clean + "; -wx:" + wx + "; output file: " + outFile);
            String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
            String shortDesc = String.format("generated XML from %s:%s on %s", fileName, sheetName, timeStamp);
            as.makeXMLFile(outFile, shortDesc);
        } else if (optToSS) {
            if (optToXML | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            // TODO implement this
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");
            AvailXML x = new AvailXML(fileName, log);
            x.makeSS(outFile);
        } else if (optDumpSS) {
            if (optToXML | optToSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            message = "dumping file: " + fileName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            AvailSS.dumpFile(fileName);
        } else { // dumpSheet
            if (sheetName == null)
                throw new ParseException("sheet name not specified");
            message = "dumping file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);

            ss.dumpSheet(sheetName);
        }
    } catch (ParseException exp) {
        System.out.println("bad command line: " + exp.getMessage());
        usage();
        System.exit(-1);
    }
}

From source file:lapispaste.Main.java

public static void main(String[] args) throws Exception {
    // create Options object
    Options options = new Options();
    String version;/*  w w w  . ja va  2s. c o  m*/

    version = "0.1";

    // populate Options with.. well options :P
    options.addOption("v", false, "Display version");
    options.addOption("f", true, "File to paste");

    // non-critical options
    options.addOption("t", true, "Code language");
    options.addOption("p", false, "Read from pipe");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    // assemble a map of values
    final Map<String, String> pastemap = new HashMap<String, String>();

    if (cmd.hasOption("t"))
        pastemap.put("format", cmd.getOptionValue("t").toString());
    else
        pastemap.put("format", "text");

    // critical options
    if (cmd.hasOption("v"))
        System.out.println("lapispaste version " + version);
    else if (cmd.hasOption("f")) {
        File file = new File(cmd.getOptionValue("f"));
        StringBuffer pdata = readData(new FileReader(file));
        paster(pastemap, pdata);
    } else if (cmd.hasOption("p")) {
        StringBuffer pdata = readData(new InputStreamReader(System.in));
        paster(pastemap, pdata);
    } else {
        // Did not recieve what was expected
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("lapispaste [OPTIONS] [FILE]", options);
    }

}

From source file:ed.util.LicenseHeaderCheck.java

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

    Options o = new Options();
    o.addOption("r", false, "recursive");
    o.addOption("skip", true, "substrings not to match");

    CommandLine cl = (new BasicParser()).parse(o, args);

    if (cl.getArgList().size() < 2) {
        System.err.println("usage: LicenseHeaderCheck [-r] <header file> <dir or files>");
        return;//w w w.  ja  va 2  s .  c om
    }

    LicenseHeaderCheck checker = new LicenseHeaderCheck(new File(cl.getArgList().get(0).toString()),
            cl.hasOption("r"));

    if (cl.getOptionValues("skip") != null)
        for (String skip : cl.getOptionValues("skip"))
            checker.addSkip(skip);

    for (int i = 1; i < cl.getArgList().size(); i++) {
        checker.go(new File(cl.getArgList().get(i).toString()));
    }
}

From source file:com.incapture.rapgen.GenApi.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("l", true, "Language to generate");
    options.addOption("o", true, "Output root folder for kernel files");
    options.addOption("a", true, "Output root folder for api files");
    options.addOption("w", true, "Output root folder for web files");
    options.addOption("d", true, "Template dir to use (use either this or 't')");
    options.addOption("t", true, "Template file to use (use either this or 'd')");
    options.addOption("g", true, "The type of grammar to generate, current options are 'SDK' or 'API'");
    options.addOption("mainApiFile", true, "FileName specifying the api");
    options.addOption("codeSamplesJava", true, "A path to search for files that have Java code samples");
    options.addOption("codeSamplesPython", true, "A path to search for files that have Python code samples");

    CommandLineParser cparser = new PosixParser();
    try {//from  w  w w.  j a  va2 s .c o m
        CommandLine cmd = cparser.parse(options, args);
        String mainApiFile = cmd.getOptionValue("mainApiFile");
        String outputKernelFolder = cmd.getOptionValue('o');
        String outputApiFolder = cmd.getOptionValue('a');
        String outputWebFolder = cmd.getOptionValue('w');
        String codeSamplesJava = cmd.getOptionValue("codeSamplesJava");
        String codeSamplesPython = cmd.getOptionValue("codeSamplesPython");

        GenType genType = GenType.valueOf(cmd.getOptionValue('g'));

        // The language will ultimately choose the walker class
        String language = cmd.getOptionValue('l');
        if (cmd.hasOption('d') && cmd.hasOption('t')) {
            throw new IllegalArgumentException(
                    "Cannot define both a template folder ('d') and file ('t'). Please use one OR the other.");
        }

        // And off we go

        TLexer lexer = new TLexer();
        ResourceBasedApiReader apiReader = new ResourceBasedApiReader();
        lexer.setApiReader(apiReader);
        lexer.setCharStream(apiReader.read(mainApiFile));

        // Using the lexer as the token source, we create a token
        // stream to be consumed by the parser
        //
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        // Now we need an instance of our parser
        //
        TParser parser = new TParser(tokens);

        hmxdef_return psrReturn = parser.hmxdef();

        // load in T.stg template group, put in templates variable
        StringTemplateGroup templates = null;

        if (!isSlateMd(language)) {
            templates = TemplateRepo.getTemplates(language, genType);
        }
        Tree t = psrReturn.getTree();

        CommonTreeNodeStream ns = new CommonTreeNodeStream(t);
        ns.setTokenStream(tokens);
        if (templates != null) {
            templates.registerRenderer(String.class, new UpCaseRenderer());
        }
        AbstractTTree walker = TreeFactory.createTreeWalker(ns, templates, language);
        System.out.println("Generating files with a " + walker.getClass().getName());
        if (walker instanceof TTree) {
            if (genType.equals(GenType.API)) {
                ((TTree) walker).apiGen();
            } else {
                ((TTree) walker).sdkGen();
            }
        } else if (walker instanceof TTreeRuby) {
            System.out.println("Running for Ruby");
            /* TTreeRuby.hmxdef_return out = */
            ((TTreeRuby) walker).hmxdef();
        } else if (walker instanceof TTreeJS) {
            System.out.println("Running for JavaScript");
            /* TTreeJS.hmxdef_return out = */
            ((TTreeJS) walker).hmxdef();
        } else if (walker instanceof TTreeDoc) {
            System.out.println("Running for Documentation");
            /* TTreeDoc.hmxdef_return out = */
            ((TTreeDoc) walker).hmxdef();
        } else if (walker instanceof TTreeVB) {
            System.out.println("Running for VB");
            /* TTreeVB.hmxdef_return out = */
            ((TTreeVB) walker).hmxdef();
        } else if (walker instanceof TTreeGo) {
            System.out.println("Running for Go");
            /* TTreeGo.hmxdef_return out = */
            ((TTreeGo) walker).hmxdef();
        } else if (walker instanceof TTreeCpp) {
            System.out.println("Running for Cpp");
            /* TTreeGo.hmxdef_return out = */
            ((TTreeCpp) walker).hmxdef();
        } else if (walker instanceof TTreePython) {
            System.out.println("Running for Python");
            /* TTreePython.hmxdef_return out = */
            ((TTreePython) walker).hmxdef();
        } else if (walker instanceof TTreeSlateMd) {
            System.out.println("Running for Slate Markdown");
            TTreeSlateMd slateMdWalker = (TTreeSlateMd) walker;
            slateMdWalker.setupCodeParser(codeSamplesJava, codeSamplesPython);
            slateMdWalker.hmxdef();
        } else if (walker instanceof TTreeDotNet) {
            System.out.println("Running for DotNet");
            ((TTreeDotNet) walker).apiGen();
        } else if (walker instanceof TTreeCurtisDoc) {
            System.out.println("Running for CurtisDoc");
            ((TTreeCurtisDoc) walker).apiGen();
        }
        // Now dump the files out
        System.out.println("Genereated source output locations:");
        System.out.println(String.format("kernel: [%s]", outputKernelFolder));
        System.out.println(String.format("api: [%s]", outputApiFolder));
        System.out.println(String.format("web: [%s]", outputWebFolder));
        walker.dumpFiles(outputKernelFolder, outputApiFolder, outputWebFolder);

    } catch (ParseException e) {
        System.err.println("Error parsing command line - " + e.getMessage());
        System.out.println("Usage: " + options.toString());
    } catch (IOException | RecognitionException e) {
        System.err.println("Error running GenApi: " + ExceptionToString.format(e));
    }
}

From source file:ISMAGS.CommandLineInterface.java

public static void main(String[] args) throws IOException {
    String folder = null, files = null, motifspec = null, output = null;

    Options opts = new Options();
    opts.addOption("folder", true, "Folder name");
    opts.addOption("linkfiles", true,
            "Link files seperated by spaces (format: linktype[char] directed[d/u] filename)");
    opts.addOption("motif", true, "Motif description by two strings (format: linktypes)");
    opts.addOption("output", true, "Output file name");

    CommandLineParser parser = new PosixParser();
    try {/*  w w w .  j a  v  a 2s . c  o m*/
        CommandLine cmd = parser.parse(opts, args);
        if (cmd.hasOption("folder")) {
            folder = cmd.getOptionValue("folder");
        }
        if (cmd.hasOption("linkfiles")) {
            files = cmd.getOptionValue("linkfiles");
        }
        if (cmd.hasOption("motif")) {
            motifspec = cmd.getOptionValue("motif");
        }
        if (cmd.hasOption("output")) {
            output = cmd.getOptionValue("output");
        }
    } catch (ParseException e) {
        Die("Error: Parsing error");
    }

    if (print) {
        printBanner(folder, files, motifspec, output);
    }

    if (folder == null || files == null || motifspec == null || output == null) {
        Die("Error: not all options are provided");
    } else {
        ArrayList<String> linkfiles = new ArrayList<String>();
        ArrayList<String> linkTypes = new ArrayList<String>();
        ArrayList<String> sourcenetworks = new ArrayList<String>();
        ArrayList<String> destinationnetworks = new ArrayList<String>();
        ArrayList<Boolean> directed = new ArrayList<Boolean>();
        StringTokenizer st = new StringTokenizer(files, " ");
        while (st.hasMoreTokens()) {
            linkTypes.add(st.nextToken());
            directed.add(st.nextToken().equals("d"));
            sourcenetworks.add(st.nextToken());
            destinationnetworks.add(st.nextToken());
            linkfiles.add(folder + st.nextToken());
        }
        ArrayList<LinkType> allLinkTypes = new ArrayList<LinkType>();
        HashMap<Character, LinkType> typeTranslation = new HashMap<Character, LinkType>();
        for (int i = 0; i < linkTypes.size(); i++) {
            String n = linkTypes.get(i);
            char nn = n.charAt(0);
            LinkType t = typeTranslation.get(nn);
            if (t == null) {
                t = new LinkType(directed.get(i), n, i, nn, sourcenetworks.get(i), destinationnetworks.get(i));
            }
            allLinkTypes.add(t);
            typeTranslation.put(nn, t);
        }
        if (print) {
            System.out.println("Reading network..");
        }
        Network network = Network.readNetworkFromFiles(linkfiles, allLinkTypes);

        Motif motif = getMotif(motifspec, typeTranslation);

        if (print) {
            System.out.println("Starting the search..");
        }
        MotifFinder mf = new MotifFinder(network);
        long tijd = System.nanoTime();
        Set<MotifInstance> motifs = mf.findMotif(motif, false);
        tijd = System.nanoTime() - tijd;
        if (print) {
            System.out.println("Completed search in " + tijd / 1000000 + " milliseconds");
        }
        if (print) {
            System.out.println("Found " + motifs.size() + " instances of " + motifspec + " motif");
        }
        if (print) {
            System.out.println("Writing instances to file: " + output);
        }
        printMotifs(motifs, output);
        if (print) {
            System.out.println("Done.");
        }
        //            Set<MotifInstance> motifs=null;
        //            MotifFinder mf=null;
        //            System.out.println("Starting the search..");
        //            long tstart = System.nanoTime();
        //            for (int i = 0; i < it; i++) {
        //
        //                mf = new MotifFinder(network, allLinkTypes, true);
        //                motifs = mf.findMotif(motif);
        //            }
        //
        //            long tend = System.nanoTime();
        //            double time_in_ms = (tend - tstart) / 1000000.0;
        //            System.out.println("Found " + mf.totalFound + " motifs, " + time_in_ms + " ms");
        ////        System.out.println("Evaluated " + mf.totalNrMappedNodes+ " search nodes");
        ////        System.out.println("Found " + motifs.size() + " motifs, " + time_in_ms + " ms");
        //            printMotifs(motifs, output);

    }

}

From source file:fr.liglab.jlcm.RunPLCM.java

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

    Options options = new Options();
    CommandLineParser parser = new PosixParser();

    options.addOption("a", false, "Output all frequent itemsets, not only closed ones");
    options.addOption("b", false,
            "Benchmark mode : patterns are not outputted at all (in which case OUTPUT_PATH is ignored)");
    options.addOption("h", false, "Show help");
    options.addOption("m", false,
            "Give peak memory usage after mining (instanciates a watcher thread that periodically triggers garbage collection)");
    options.addOption("s", false, "Sort items in outputted patterns, in ascending order");
    options.addOption("S", false, "Use arbitrary strings as item IDs (space-separated)");
    options.addOption("t", true,
            "How many threads will be launched (defaults to your machine's processors count)");
    options.addOption("v", false, "Enable verbose mode, which logs every extension of the empty pattern");
    options.addOption("V", false,
            "Enable ultra-verbose mode, which logs every pattern extension (use with care: it may produce a LOT of output)");

    try {//  w ww.  ja  va 2  s  . c o m
        CommandLine cmd = parser.parse(options, args);

        if (cmd.getArgs().length < 2 || cmd.getArgs().length > 3 || cmd.hasOption('h')) {
            printMan(options);
        } else {
            standalone(cmd);
        }
    } catch (ParseException e) {
        printMan(options);
    }
}

From source file:MainServer.java

public static void main(String[] args) {
    int port = 1234;
    String filepath = "";
    String complete_path = "";
    String connection_type = "";
    String ip_address = "";
    int port_out = 0;
    int delay = 20; //20 by default

    //parse commands using getOpt (cli)
    //add Options
    Options options = new Options();

    options.addOption("p", true, "port_to_listen_on");
    options.addOption("d", true, "directory");
    options.addOption("T", false, "TCP mode");
    options.addOption("U", false, "UDP mode");
    options.addOption("s", true, "iPAddress");
    options.addOption("P", true, "port_to_connect_to");
    options.addOption("D", true, "delay");

    CommandLineParser clp = new DefaultParser();
    try {//  w  ww  .j  a v  a 2s .  c om
        CommandLine cl = clp.parse(options, args);

        //options for the server
        if (cl.hasOption("p")) {
            port = Integer.parseInt(cl.getOptionValue("p"));
        } else {
            System.err.println("No valid port selected.");
            return;
        }

        if (cl.hasOption("d")) {
            filepath = cl.getOptionValue("d");
            //if there a '/' in front, remove it to make it a valid directory
            if (filepath.substring(0, 1).equalsIgnoreCase("/")) {
                filepath = filepath.substring(1);
            }
        } else {
            System.err.println("No valid directory given.");
            return;
        }

        if (cl.hasOption("D")) {
            delay = Integer.parseInt(cl.getOptionValue("D"));
        }

        //options for the client
        if (cl.hasOption("T")) {
            connection_type = "T";
        } else if (cl.hasOption("U")) {
            connection_type = "U";
        }

        if (cl.hasOption("s")) {
            ip_address = cl.getOptionValue("s");
        }

        if (cl.hasOption("P")) {
            port_out = Integer.parseInt(cl.getOptionValue("P"));
        }

    } catch (ParseException e) {
        //TODO: handle exception
    }

    //create directory (if it doesn't already exist)
    try {
        Files.createDirectories(Paths.get(filepath));
    } catch (Exception e) {
        //TODO: handle exception
        System.err.println("Couldn't create directory");
        System.err.println(filepath);
    }

    //read in required files (create them if they dont already exist)
    try {
        Files.createFile(Paths.get(filepath + "/gossip.txt"));
        Files.createFile(Paths.get(filepath + "/peers.txt"));
    } catch (Exception e) {
        //TODO: handle exception
    }
    WriteToFiles.readFiles(filepath);

    //start the servers
    TCPServerSock tcpServer = new TCPServerSock(port, filepath, delay);
    UDPServer udpServer = new UDPServer(port, filepath);

    Thread tcpThread = new Thread(tcpServer);
    Thread udpThread = new Thread(udpServer);

    tcpThread.start();
    udpThread.start();

    //start the client
    if (!connection_type.equals("") && port_out != 0 && !ip_address.equals("")) {
        Client client = new Client(ip_address, port_out, connection_type);
        Thread clientThread = new Thread(client);
        clientThread.start();
    }

    //Start thread to forget peers
    ForgetPeer forgetPeer = new ForgetPeer(filepath + "/peers.txt", delay);
    Thread forgetPeerThread = new Thread(forgetPeer);
    forgetPeerThread.start();
}

From source file:jp.primecloud.auto.tool.management.main.Main.java

public static void main(String args[]) {
    Options options = new Options();
    options.addOption("Z", false, "Zabbix mode");
    options.addOption("U", false, "UPDATE mode");
    options.addOption("S", false, "SELECT mode");
    options.addOption("C", false, "Create Mode");
    options.addOption("P", false, "Show Platform");
    options.addOption("L", false, "Show Users");
    options.addOption("E", false, "Ecrypt UserPassword");
    options.addOption("I", false, "IaasGateway Mode");
    options.addOption("A", false, "PCC-API Genarate ID or Key Mode");
    options.addOption("W", false, "Decrypt UserPassword");

    options.addOption("username", true, "Create the username");
    options.addOption("password", true, "Create the password");
    options.addOption("firstname", true, "Create the firstname");
    options.addOption("familyname", true, "Create the familyname");
    options.addOption("userno", true, "Create the userno");

    options.addOption("dburl", "connectionurl", true, "PrimeCloud Controller database url");
    options.addOption("dbuser", "username", true, "PrimeCloud Controller database username");
    options.addOption("dbpass", "password", true, "PrimeCloud Controller database password");

    options.addOption("sql", true, "SQL");
    options.addOption("columnname", true, "columnName");
    options.addOption("columntype", true, "columnType");
    options.addOption("salt", true, "Salt");

    OptionBuilder.withLongOpt("prepared");
    OptionBuilder.hasArgs();//from  ww  w  .ja  v a  2  s . c o m
    OptionBuilder.withDescription("execute as PreparedStatement");
    OptionBuilder.withArgName("params");
    Option optionPrepared = OptionBuilder.create();
    options.addOption(optionPrepared);

    // for Zabbix
    options.addOption("enable", false, "enable");
    options.addOption("disable", false, "disable");
    options.addOption("get", false, "getUser from zabbix");
    options.addOption("check", false, "API setting check for zabbix");

    options.addOption("config", true, "Property can obtain from management-config.properties");
    options.addOption("platformkind", true, "Platform kind. e.g. ec2 and ec2_vpc or vmware");
    options.addOption("platformname", true, "Platform can obtain from auto-config.xml");
    options.addOption("platformno", true, "Platform can obtain from auto-config.xml");

    // for IaasGateway(AWS, Cloudstack)
    options.addOption("keyname", true, "import your key pair as keyName");
    options.addOption("publickey", true, "import your public key");

    // for PCC
    options.addOption("accessid", true, "accessid for PCC-API");
    options.addOption("secretkey", true, "secretkey for PCC-API");
    options.addOption("generatetype", true, "genarateType for PCC-API");

    options.addOption("h", "help", false, "help");

    CommandLineParser parser = new BasicParser();

    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(
                "???????? -h?????????");
        return;
    }

    if (commandLine.hasOption("h")) {
        HelpFormatter f = new HelpFormatter();
        f.printHelp("PCC script ", options);
    }

    ManagementConfigLoader.init();
    //?

    //Zabbix?
    if (commandLine.hasOption("Z")) {
        if (commandLine.hasOption("C")) {
            //Zabbix?
            ZabbixMain.createExecute(commandLine);
        } else if (commandLine.hasOption("U")) {
            //Zabbix
            ZabbixMain.updateExecute(commandLine);
        } else if (commandLine.hasOption("disable")) {
            //Zabbix
            ZabbixMain.disableExecute(commandLine);
        } else if (commandLine.hasOption("enable")) {
            //Zabbix
            ZabbixMain.enableExecute(commandLine);
        } else if (commandLine.hasOption("get")) {
            //Zabbix?
            ZabbixMain.getUser(commandLine);
        } else if (commandLine.hasOption("check")) {
            //Zabbix??
            ZabbixMain.checkApiVersion();
        }
        //PCC?
    } else if (commandLine.hasOption("U")) {
        if (commandLine.hasOption("prepared")) {
            SQLMain.updateExecutePrepared(commandLine);
        } else {
            //Update?
            SQLMain.updateExecute(commandLine);
        }
    } else if (commandLine.hasOption("S")) {
        //Select?
        SQLMain.selectExecute(commandLine);
    } else if (commandLine.hasOption("P")) {
        //?
        ConfigMain.showPlatforms();
    } else if (commandLine.hasOption("L")) {
        //PCC?
        UserService.showUserPlatform();
    } else if (commandLine.hasOption("config")) {
        //???
        ConfigMain.getProperty(commandLine.getOptionValue("config"));
    } else if (commandLine.hasOption("platformname") && commandLine.hasOption("platformkind")) {
        //??????
        ConfigMain.getPlatformNo(commandLine.getOptionValue("platformname"),
                commandLine.getOptionValue("platformkind"));
    } else if (commandLine.hasOption("E")) {
        //PCC??
        UserService.encryptUserPassword(commandLine.getOptionValue("password"));
    } else if (commandLine.hasOption("I")) {
        //IaasGatewayCall??AWS or Cloudstack???
        IaasGatewayMain.importExecute(commandLine);
    } else if (commandLine.hasOption("A")) {
        PccApiGenerateService.genarate(commandLine);
    } else if (commandLine.hasOption("W")) {
        //PCC??
        UserService.decryptUserPassword(commandLine.getOptionValue("password"),
                commandLine.getOptionValue("salt"));
    }
}