Example usage for java.util List get

List of usage examples for java.util List get

Introduction

In this page you can find the example usage for java.util List get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.aerospike.load.AerospikeLoad.java

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

    Thread statPrinter = new Thread(new PrintStat(counters));
    try {/*from  w ww  . j a v  a  2s  . co m*/
        log.info("Aerospike loader started");
        Options options = new Options();
        options.addOption("h", "host", true, "Server hostname (default: localhost)");
        options.addOption("p", "port", true, "Server port (default: 3000)");
        options.addOption("n", "namespace", true, "Namespace (default: test)");
        options.addOption("s", "set", true, "Set name. (default: null)");
        options.addOption("c", "config", true, "Column definition file name");
        options.addOption("wt", "write-threads", true,
                "Number of writer threads (default: Number of cores * 5)");
        options.addOption("rt", "read-threads", true,
                "Number of reader threads (default: Number of cores * 1)");
        options.addOption("l", "rw-throttle", true, "Throttling of reader to writer(default: 10k) ");
        options.addOption("tt", "transaction-timeout", true,
                "write transaction timeout in miliseconds(default: No timeout)");
        options.addOption("et", "expiration-time", true,
                "Expiration time of records in seconds (default: never expire)");
        options.addOption("T", "timezone", true,
                "Timezone of source where data dump is taken (default: local timezone)");
        options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)");
        options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)");
        options.addOption("v", "verbose", false, "Logging all");
        options.addOption("u", "usage", false, "Print usage.");

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

        if (args.length == 0 || cl.hasOption("u")) {
            logUsage(options);
            return;
        }

        if (cl.hasOption("l")) {
            rwThrottle = Integer.parseInt(cl.getOptionValue("l"));
        } else {
            rwThrottle = Constants.READLOAD;
        }
        // Get all command line options
        params = Utils.parseParameters(cl);

        //Get client instance
        AerospikeClient client = new AerospikeClient(params.host, params.port);
        if (!client.isConnected()) {
            log.error("Client is not able to connect:" + params.host + ":" + params.port);
            return;
        }

        if (params.verbose) {
            log.setLevel(Level.DEBUG);
        }

        // Get available processors to calculate default number of threads
        int cpus = Runtime.getRuntime().availableProcessors();
        nWriterThreads = cpus * scaleFactor;
        nReaderThreads = cpus;

        // Get writer thread count
        if (cl.hasOption("wt")) {
            nWriterThreads = Integer.parseInt(cl.getOptionValue("wt"));
            nWriterThreads = (nWriterThreads > 0
                    ? (nWriterThreads > Constants.MAX_THREADS ? Constants.MAX_THREADS : nWriterThreads)
                    : 1);
            log.debug("Using writer Threads: " + nWriterThreads);
        }
        writerPool = Executors.newFixedThreadPool(nWriterThreads);

        // Get reader thread count
        if (cl.hasOption("rt")) {
            nReaderThreads = Integer.parseInt(cl.getOptionValue("rt"));
            nReaderThreads = (nReaderThreads > 0
                    ? (nReaderThreads > Constants.MAX_THREADS ? Constants.MAX_THREADS : nReaderThreads)
                    : 1);
            log.debug("Using reader Threads: " + nReaderThreads);
        }

        String columnDefinitionFileName = cl.getOptionValue("c", null);

        log.debug("Column definition files/directory: " + columnDefinitionFileName);
        if (columnDefinitionFileName == null) {
            log.error("Column definition files/directory not specified. use -c <file name>");
            return;
        }

        File columnDefinitionFile = new File(columnDefinitionFileName);
        if (!columnDefinitionFile.exists()) {
            log.error("Column definition files/directory does not exist: "
                    + Utils.getFileName(columnDefinitionFileName));
            return;
        }

        // Get data file list
        String[] files = cl.getArgs();
        if (files.length == 0) {
            log.error("No data file Specified: add <file/dir name> to end of the command ");
            return;
        }
        List<String> allFileNames = new ArrayList<String>();
        allFileNames = Utils.getFileNames(files);
        if (allFileNames.size() == 0) {
            log.error("Given datafiles/directory does not exist");
            return;
        }
        for (int i = 0; i < allFileNames.size(); i++) {
            log.debug("File names:" + Utils.getFileName(allFileNames.get(i)));
            File file = new File(allFileNames.get(i));
            counters.write.recordTotal = counters.write.recordTotal + file.length();
        }

        //remove column definition file from list
        allFileNames.remove(columnDefinitionFileName);

        log.info("Number of data files:" + allFileNames.size());

        /**
         * Process column definition file to get meta data and bin mapping.
         */
        metadataColumnDefs = new ArrayList<ColumnDefinition>();
        binColumnDefs = new ArrayList<ColumnDefinition>();
        metadataConfigs = new HashMap<String, String>();

        if (Parser.processJSONColumnDefinitions(columnDefinitionFile, metadataConfigs, metadataColumnDefs,
                binColumnDefs, params)) {
            log.info("Config file processed.");
        } else {
            throw new Exception("Config file parsing Error");
        }

        // Add metadata of config to parameters
        String metadata;
        if ((metadata = metadataConfigs.get(Constants.INPUT_TYPE)) != null) {
            params.fileType = metadata;
            if (params.fileType.equals(Constants.CSV_FILE)) {

                // Version check
                metadata = metadataConfigs.get(Constants.VERSION);
                String[] vNumber = metadata.split("\\.");
                int v1 = Integer.parseInt(vNumber[0]);
                int v2 = Integer.parseInt(vNumber[1]);
                if ((v1 <= Constants.MajorV) && (v2 <= Constants.MinorV)) {
                    log.debug("Config version used:" + metadata);
                } else
                    throw new Exception("\"" + Constants.VERSION + ":" + metadata + "\" is not Supported");

                // Set delimiter 
                if ((metadata = metadataConfigs.get(Constants.DELIMITER)) != null && metadata.length() == 1) {
                    params.delimiter = metadata.charAt(0);
                } else {
                    log.warn("\"" + Constants.DELIMITER + ":" + metadata
                            + "\" is not properly specified in config file. Default is ','");
                }

                if ((metadata = metadataConfigs.get(Constants.IGNORE_FIRST_LINE)) != null) {
                    params.ignoreFirstLine = metadata.equals("true");
                } else {
                    log.warn("\"" + Constants.IGNORE_FIRST_LINE + ":" + metadata
                            + "\" is not properly specified in config file. Default is false");
                }

                if ((metadata = metadataConfigs.get(Constants.COLUMNS)) != null) {
                    counters.write.colTotal = Integer.parseInt(metadata);
                } else {
                    throw new Exception("\"" + Constants.COLUMNS + ":" + metadata
                            + "\" is not properly specified in config file");
                }
            } else {
                throw new Exception("\"" + params.fileType + "\" is not supported in config file");
            }
        } else {
            throw new Exception("\"" + Constants.INPUT_TYPE + "\" is not specified in config file");
        }

        // add config input to column definitions
        if (params.fileType.equals(Constants.CSV_FILE)) {
            List<String> binName = null;
            if (params.ignoreFirstLine) {
                String line;
                BufferedReader br = new BufferedReader(
                        new InputStreamReader(new FileInputStream(allFileNames.get(0)), "UTF8"));
                if ((line = br.readLine()) != null) {
                    binName = Parser.getCSVRawColumns(line, params.delimiter);
                    br.close();
                    if (binName.size() != counters.write.colTotal) {
                        throw new Exception("Number of column in config file and datafile are mismatch."
                                + " Datafile: " + Utils.getFileName(allFileNames.get(0)) + " Configfile: "
                                + Utils.getFileName(columnDefinitionFileName));
                    }
                }
            }

            //update columndefs for metadata
            for (int i = 0; i < metadataColumnDefs.size(); i++) {
                if (metadataColumnDefs.get(i).staticValue) {

                } else {
                    if (metadataColumnDefs.get(i).binValuePos < 0) {
                        if (metadataColumnDefs.get(i).columnName == null) {
                            if (metadataColumnDefs.get(i).jsonPath == null) {
                                log.error("dynamic metadata having improper info"
                                        + metadataColumnDefs.toString()); //TODO
                            } else {
                                //TODO check for json_path   
                            }
                        } else {
                            if (params.ignoreFirstLine) {
                                if (binName.indexOf(metadataColumnDefs.get(i).binValueHeader) != -1) {
                                    metadataColumnDefs.get(i).binValuePos = binName
                                            .indexOf(metadataColumnDefs.get(i).binValueHeader);
                                } else {
                                    throw new Exception("binName missing in data file:"
                                            + metadataColumnDefs.get(i).binValueHeader);
                                }
                            }
                        }
                    } else {
                        if (params.ignoreFirstLine)
                            metadataColumnDefs.get(i).binValueHeader = binName
                                    .get(metadataColumnDefs.get(i).binValuePos);
                    }
                }
                if ((!metadataColumnDefs.get(i).staticValue) && (metadataColumnDefs.get(i).binValuePos < 0)) {
                    throw new Exception("Information for bin mapping is missing in config file:"
                            + metadataColumnDefs.get(i));
                }

                if (metadataColumnDefs.get(i).srcType == null) {
                    throw new Exception(
                            "Source data type is not properly mentioned:" + metadataColumnDefs.get(i));
                }

                if (metadataColumnDefs.get(i).binNameHeader == Constants.SET
                        && !metadataColumnDefs.get(i).srcType.equals(SrcColumnType.STRING)) {
                    throw new Exception("Set name should be string type:" + metadataColumnDefs.get(i));
                }

                if (metadataColumnDefs.get(i).binNameHeader.equalsIgnoreCase(Constants.SET)
                        && params.set != null) {
                    throw new Exception(
                            "Set name is given both in config file and commandline. Provide only once.");
                }
            }

            //update columndefs for bins
            for (int i = 0; i < binColumnDefs.size(); i++) {
                if (binColumnDefs.get(i).staticName) {

                } else {
                    if (binColumnDefs.get(i).binNamePos < 0) {
                        if (binColumnDefs.get(i).columnName == null) {
                            if (binColumnDefs.get(i).jsonPath == null) {
                                log.error("dynamic bin having improper info"); //TODO
                            } else {
                                //TODO check for json_path
                            }
                        } else {
                            if (params.ignoreFirstLine) {
                                if (binName.indexOf(binColumnDefs.get(i).binNameHeader) != -1) {
                                    binColumnDefs.get(i).binNamePos = binName
                                            .indexOf(binColumnDefs.get(i).binNameHeader);
                                } else {
                                    throw new Exception("binName missing in data file:"
                                            + binColumnDefs.get(i).binNameHeader);
                                }
                            }
                        }
                    } else {
                        if (params.ignoreFirstLine)
                            binColumnDefs.get(i).binNameHeader = binName.get(binColumnDefs.get(i).binNamePos);
                    }
                }

                if (binColumnDefs.get(i).staticValue) {

                } else {
                    if (binColumnDefs.get(i).binValuePos < 0) {
                        if (binColumnDefs.get(i).columnName == null) {
                            if (binColumnDefs.get(i).jsonPath == null) {
                                log.error("dynamic bin having improper info"); //TODO
                            } else {
                                //TODO check for json_path
                            }
                        } else {
                            if (params.ignoreFirstLine) {
                                if (binName.contains(binColumnDefs.get(i).binValueHeader)) {
                                    binColumnDefs.get(i).binValuePos = binName
                                            .indexOf(binColumnDefs.get(i).binValueHeader);
                                } else if (!binColumnDefs.get(i).binValueHeader.toLowerCase()
                                        .equals(Constants.SYSTEM_TIME)) {
                                    throw new Exception("Wrong column name mentioned in config file:"
                                            + binColumnDefs.get(i).binValueHeader);
                                }
                            }
                        }
                    } else {
                        if (params.ignoreFirstLine)
                            binColumnDefs.get(i).binValueHeader = binName.get(binColumnDefs.get(i).binValuePos);
                    }

                    //check for missing entries in config file
                    if (binColumnDefs.get(i).binValuePos < 0 && binColumnDefs.get(i).binValueHeader == null) {
                        throw new Exception("Information missing(Value header or bin mapping) in config file:"
                                + binColumnDefs.get(i));
                    }

                    //check for proper data type in config file.
                    if (binColumnDefs.get(i).srcType == null) {
                        throw new Exception(
                                "Source data type is not properly mentioned:" + binColumnDefs.get(i));
                    }

                    //check for valid destination type
                    if ((binColumnDefs.get(i).srcType.equals(SrcColumnType.TIMESTAMP)
                            || binColumnDefs.get(i).srcType.equals(SrcColumnType.BLOB))
                            && binColumnDefs.get(i).dstType == null) {
                        throw new Exception("Destination type is not mentioned: " + binColumnDefs.get(i));
                    }

                    //check for encoding
                    if (binColumnDefs.get(i).dstType != null && binColumnDefs.get(i).encoding == null) {
                        throw new Exception(
                                "Encoding is not given for src-dst type conversion:" + binColumnDefs.get(i));
                    }

                    //check for valid encoding
                    if (binColumnDefs.get(i).srcType.equals(SrcColumnType.BLOB)
                            && !binColumnDefs.get(i).encoding.equals(Constants.HEX_ENCODING)) {
                        throw new Exception("Wrong encoding for blob data:" + binColumnDefs.get(i));
                    }
                }

                //Check static bin name mapped to dynamic bin value
                if ((binColumnDefs.get(i).binNamePos == binColumnDefs.get(i).binValuePos)
                        && (binColumnDefs.get(i).binNamePos != -1)) {
                    throw new Exception("Static bin name mapped to dynamic bin value:" + binColumnDefs.get(i));
                }

                //check for missing entries in config file
                if (binColumnDefs.get(i).binNameHeader == null
                        && binColumnDefs.get(i).binNameHeader.length() > Constants.BIN_NAME_LENGTH) {
                    throw new Exception("Information missing binName or large binName in config file:"
                            + binColumnDefs.get(i));
                }
            }
        }

        log.info(params.toString());
        log.debug("MetadataConfig:" + metadataColumnDefs);
        log.debug("BinColumnDefs:" + binColumnDefs);

        // Start PrintStat thread
        statPrinter.start();

        // Reader pool size
        ExecutorService readerPool = Executors.newFixedThreadPool(
                nReaderThreads > allFileNames.size() ? allFileNames.size() : nReaderThreads);
        log.info("Reader pool size : " + nReaderThreads);

        // Submit all tasks to writer threadpool.
        for (String aFile : allFileNames) {
            log.debug("Submitting task for: " + aFile);
            readerPool.submit(new AerospikeLoad(aFile, client, params));
        }

        // Wait for reader pool to complete
        readerPool.shutdown();
        log.info("Shutdown down reader thread pool");

        while (!readerPool.isTerminated())
            ;
        //readerPool.awaitTermination(20, TimeUnit.MINUTES);
        log.info("Reader thread pool terminated");

        // Wait for writer pool to complete after getting all tasks from reader pool
        writerPool.shutdown();
        log.info("Shutdown down writer thread pool");

        while (!writerPool.isTerminated())
            ;
        log.info("Writer thread pool terminated");

        // Print final statistic of aerospike-loader.
        log.info("Final Statistics of importer: (Succesfull Writes = " + counters.write.writeCount.get() + ", "
                + "Errors="
                + (counters.write.writeErrors.get() + counters.write.readErrors.get()
                        + counters.write.processingErrors.get())
                + "(" + (counters.write.writeErrors.get()) + "-Write," + counters.write.readErrors.get()
                + "-Read," + counters.write.processingErrors.get() + "-Processing)");
    } catch (Exception e) {
        log.error(e);
        if (log.isDebugEnabled()) {
            e.printStackTrace();
        }
    } finally {
        // Stop statistic printer thread.
        statPrinter.interrupt();
        log.info("Aerospike loader completed");
    }
}

From source file:in.raster.oviyam.util.core.DcmRcv.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);// w ww.  j  av  a  2  s.  co  m
    DcmRcv dcmrcv = new DcmRcv(cl.hasOption("device") ? cl.getOptionValue("device") : "DCMRCV");
    final List<String> argList = cl.getArgList();
    String port = argList.get(0);
    String[] aetPort = split(port, ':', 1);
    dcmrcv.setPort(parseInt(aetPort[1], "illegal port number", 1, 0xffff));
    if (aetPort[0] != null) {
        String[] aetHost = split(aetPort[0], '@', 0);
        dcmrcv.setAEtitle(aetHost[0]);
        if (aetHost[1] != null) {
            dcmrcv.setHostname(aetHost[1]);
        }
    }

    if (cl.hasOption("dest")) {
        dcmrcv.setDestination(cl.getOptionValue("dest"));
    }
    if (cl.hasOption("calling2dir")) {
        dcmrcv.setCalling2Dir(loadProperties(cl.getOptionValue("calling2dir")));
    }
    if (cl.hasOption("called2dir")) {
        dcmrcv.setCalled2Dir(loadProperties(cl.getOptionValue("called2dir")));
    }
    if (cl.hasOption("callingdefdir")) {
        dcmrcv.setCallingDefDir(cl.getOptionValue("callingdefdir"));
    }
    if (cl.hasOption("calleddefdir")) {
        dcmrcv.setCalledDefDir(cl.getOptionValue("calleddefdir"));
    }
    if (cl.hasOption("journal")) {
        dcmrcv.setJournal(cl.getOptionValue("journal"));
    }
    if (cl.hasOption("journalfilepath")) {
        dcmrcv.setJournalFilePathFormat(cl.getOptionValue("journalfilepath"));
    }

    if (cl.hasOption("defts")) {
        dcmrcv.setTransferSyntax(ONLY_DEF_TS);
    } else if (cl.hasOption("native")) {
        dcmrcv.setTransferSyntax(cl.hasOption("bigendian") ? NATIVE_TS : NATIVE_LE_TS);
    } else if (cl.hasOption("bigendian")) {
        dcmrcv.setTransferSyntax(NON_RETIRED_TS);
    }
    if (cl.hasOption("scretraets")) {
        dcmrcv.setStgCmtRetrieveAETs(cl.getOptionValue("scretraets"));
    }
    if (cl.hasOption("scretraet")) {
        dcmrcv.setStgCmtRetrieveAET(cl.getOptionValue("scretraet"));
    }
    dcmrcv.setStgCmtReuseFrom(cl.hasOption("screusefrom"));
    dcmrcv.setStgCmtReuseTo(cl.hasOption("screuseto"));
    if (cl.hasOption("scport")) {
        dcmrcv.setStgCmtPort(parseInt(cl.getOptionValue("scport"), "illegal port number", 1, 0xffff));
    }
    if (cl.hasOption("scdelay")) {
        dcmrcv.setStgCmtDelay(parseInt(cl.getOptionValue("scdelay"), "illegal argument of option -scdelay", 0,
                Integer.MAX_VALUE));
    }
    if (cl.hasOption("scretry")) {
        dcmrcv.setStgCmtRetry(parseInt(cl.getOptionValue("scretry"), "illegal argument of option -scretry", 0,
                Integer.MAX_VALUE));
    }
    if (cl.hasOption("scretryperiod")) {
        dcmrcv.setStgCmtRetryPeriod(parseInt(cl.getOptionValue("scretryperiod"),
                "illegal argument of option -scretryperiod", 1000, Integer.MAX_VALUE));
    }
    if (cl.hasOption("connectTO")) {
        dcmrcv.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("reaper")) {
        dcmrcv.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("rspTO")) {
        dcmrcv.setDimseRspTimeout(parseInt(cl.getOptionValue("rspTO"), "illegal argument of option -rspTO", 1,
                Integer.MAX_VALUE));
    }
    if (cl.hasOption("acceptTO")) {
        dcmrcv.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO",
                1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("idleTO")) {
        dcmrcv.setIdleTimeout(parseInt(cl.getOptionValue("idleTO"), "illegal argument of option -idleTO", 1,
                Integer.MAX_VALUE));
    }
    if (cl.hasOption("requestTO")) {
        dcmrcv.setRequestTimeout(parseInt(cl.getOptionValue("requestTO"),
                "illegal argument of option -requestTO", 1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("releaseTO")) {
        dcmrcv.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    }
    if (cl.hasOption("soclosedelay")) {
        dcmrcv.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    }
    if (cl.hasOption("rspdelay")) {
        dcmrcv.setDimseRspDelay(
                parseInt(cl.getOptionValue("rspdelay"), "illegal argument of option -rspdelay", 0, 10000));
    }
    if (cl.hasOption("rcvpdulen")) {
        dcmrcv.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    }
    if (cl.hasOption("sndpdulen")) {
        dcmrcv.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    }
    if (cl.hasOption("sosndbuf")) {
        dcmrcv.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    }
    if (cl.hasOption("sorcvbuf")) {
        dcmrcv.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    }
    if (cl.hasOption("bufsize")) {
        dcmrcv.setFileBufferSize(
                parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB);
    }

    dcmrcv.setPackPDV(!cl.hasOption("pdv1"));
    dcmrcv.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    if (cl.hasOption("async")) {
        dcmrcv.setMaxOpsPerformed(
                parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
    }
    dcmrcv.initTransferCapability();
    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmrcv.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmrcv.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmrcv.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }
        if (cl.hasOption("tls1")) {
            dcmrcv.setTlsProtocol(TLS1);
        } else if (cl.hasOption("ssl3")) {
            dcmrcv.setTlsProtocol(SSL3);
        } else if (cl.hasOption("no_tls1")) {
            dcmrcv.setTlsProtocol(NO_TLS1);
        } else if (cl.hasOption("no_ssl3")) {
            dcmrcv.setTlsProtocol(NO_SSL3);
        } else if (cl.hasOption("no_ssl2")) {
            dcmrcv.setTlsProtocol(NO_SSL2);
        }
        dcmrcv.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

        if (cl.hasOption("keystore")) {
            dcmrcv.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmrcv.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmrcv.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmrcv.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmrcv.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        try {
            dcmrcv.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            System.exit(2);
        }
    }
    try {
        dcmrcv.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.openimaj.demos.sandbox.flickr.geo.PlotFlickrGeo.java

public static void main(String[] args) throws IOException {
    final File inputcsv = new File("/Volumes/SSD/training_latlng");
    final List<double[]> data = new ArrayList<double[]>(10000000);

    // read in images
    final BufferedReader br = new BufferedReader(new FileReader(inputcsv));
    String line;//  ww  w.  j av  a2s  .  c o m
    int i = 0;
    br.readLine();
    while ((line = br.readLine()) != null) {
        final String[] parts = line.split(" ");

        final double longitude = Double.parseDouble(parts[2]);
        final double latitude = Double.parseDouble(parts[1]);

        data.add(new double[] { longitude, latitude });

        if (longitude >= -0.1 && longitude < 0 && latitude > 50 && latitude < 54)
            System.out.println(parts[0] + " " + latitude + " " + longitude);

        // if (i++ % 10000 == 0)
        // System.out.println(i);
    }
    br.close();

    System.out.println("Done reading");

    final float[][] dataArr = new float[2][data.size()];
    for (i = 0; i < data.size(); i++) {
        dataArr[0][i] = (float) data.get(i)[0];
        dataArr[1][i] = (float) data.get(i)[1];
    }

    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setRange(-180, 180);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setRange(-90, 90);
    final FastScatterPlot plot = new FastScatterPlot(dataArr, domainAxis, rangeAxis);

    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    final ApplicationFrame frame = new ApplicationFrame("Title");
    frame.setContentPane(chartPanel);
    frame.pack();
    frame.setVisible(true);
}

From source file:com.samtech.piv.ChinaNameTool.java

public static void main(String[] args) {
    ChinaNameTool tool = ChinaNameTool.getInstance();
    System.out.println(tool.containSurName(""));
    List ls = new ArrayList();
    ls.add("1  12344  11111");
    ls.add("2vds");
    ls.add("3vds");
    ls.add("41111");
    ls.add("5sdfs");
    ls.add("6-");
    ls.add("7,");
    ls.add("8*");
    ls.add("9");// w  w  w.  ja  v a 2  s  .  co  m
    ls.add("10!");

    ls.add("test");
    ls.add("");
    ls.add("??");
    ls.add("??");
    ls.add("????123456789");
    ls.add("????123456789");
    ls.add("YZ??,7842423921250");
    ls.add("????7842423461567??");
    ls.add("YZ?");
    ls.add("YZC0906090012009");

    for (int i = 0; i < ls.size(); i++) {
        String input = (String) ls.get(i);
        System.out.println(input + "=====" + tool.findChinaName(input));
    }
    System.out.println("*************************");
    for (int i = 0; i < ls.size(); i++) {
        String input = (String) ls.get(i);
        String[] names = tool.findChinaNames(input);
        if (names != null && names.length > 0) {
            String r = input + "=====";
            for (int j = 0; j < names.length; j++) {
                r = r + "," + names[j];
            }
            System.out.println(r);
        } else {
            System.out.println(input + "=====null");
        }

    }
}

From source file:com.fluidops.iwb.tools.RepositoryTool.java

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

    // Configure logging
    Log4JHandler.initLogging();/*from w  w w . j  a  va 2 s . co m*/
    Config.getConfigWithOverride();

    try {

        CommandLineParser parser = new BasicParser();
        Options options = buildOptions();

        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        // print the help
        if (line.getOptions().length == 0 || line.hasOption("help")) {
            printHelp(options);
            return;
        }

        @SuppressWarnings("unchecked")
        List<String> lArgs = line.getArgList();
        File source = null, target = null;
        if (lArgs.size() == 0) {
            source = IWBFileUtil.getFileInDataFolder(Config.getConfig().getRepositoryName());
            target = source;
        } else if (lArgs.size() == 1) {
            source = new File(lArgs.get(0));
            target = source;
        } else if (lArgs.size() == 2) {
            source = new File(lArgs.get(0));
            target = new File(lArgs.get(1));
        } else {
            System.out.println("Unrecognized arguments.");
            printHelp(options);
            System.exit(1);
        }

        // handle different options
        boolean checkGhosts = line.hasOption("g");
        String indices = line.hasOption("i") ? line.getOptionValue("i") : getDefaultNativeStoreIndices();
        if (line.hasOption("a")) {
            analyze(source, checkGhosts, indices);
            System.exit(0);
        }

        if (line.hasOption("f")) {
            analyzeAndFix(source, target, checkGhosts, indices);
            System.exit(0);
        }

        if (line.hasOption("c")) {
            cleanupRepository(source, target, indices);
            System.exit(0);
        }

        if (line.hasOption("u")) {
            copyUserData(source, target, indices);
            System.exit(0);
        }

    } catch (Exception exp) {
        System.out.println("Unexpected error: " + exp.getMessage());
        System.exit(1);
    }

}

From source file:com.cyberway.issue.io.Warc2Arc.java

/**
 * Command-line interface to Arc2Warc./*  w w w .  j a v  a 2s. c o  m*/
 *
 * @param args Command-line arguments.
 * @throws ParseException Failed parse of the command line.
 * @throws IOException
 * @throws java.text.ParseException
 */
public static void main(String[] args) throws ParseException, IOException, java.text.ParseException {
    Options options = new Options();
    options.addOption(new Option("h", "help", false, "Prints this message and exits."));
    options.addOption(new Option("f", "force", false, "Force overwrite of target file."));
    options.addOption(
            new Option("p", "prefix", true, "Prefix to use on created ARC files, else uses default."));
    options.addOption(
            new Option("s", "suffix", true, "Suffix to use on created ARC files, else uses default."));
    PosixParser parser = new PosixParser();
    CommandLine cmdline = parser.parse(options, args, false);
    List cmdlineArgs = cmdline.getArgList();
    Option[] cmdlineOptions = cmdline.getOptions();
    HelpFormatter formatter = new HelpFormatter();

    // If no args, print help.
    if (cmdlineArgs.size() < 0) {
        usage(formatter, options, 0);
    }

    // Now look at options passed.
    boolean force = false;
    String prefix = "WARC2ARC";
    String suffix = null;
    for (int i = 0; i < cmdlineOptions.length; i++) {
        switch (cmdlineOptions[i].getId()) {
        case 'h':
            usage(formatter, options, 0);
            break;

        case 'f':
            force = true;
            break;

        case 'p':
            prefix = cmdlineOptions[i].getValue();
            break;

        case 's':
            suffix = cmdlineOptions[i].getValue();
            break;

        default:
            throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId());
        }
    }

    // If no args, print help.
    if (cmdlineArgs.size() != 2) {
        usage(formatter, options, 0);
    }
    (new Warc2Arc()).transform(new File(cmdlineArgs.get(0).toString()), new File(cmdlineArgs.get(1).toString()),
            prefix, suffix, force);
}

From source file:com.glaf.core.util.StringTools.java

public static void main(String[] args) {
    String text = "123,234,345,567,789";
    List<String> rows = StringTools.split(text, ",");
    System.out.println(rows.get(2));
    System.out.println(rows);//from w  w  w  .  j  a  v  a 2 s.c  o  m
    for (int i = 0, len = rows.size(); i < len; i++) {
        System.out.println(rows.get(i));
    }

    Set<String> x = new HashSet<String>();
    for (int i = 0; i < 9999; i++) {
        String str = StringTools.random();
        x.add(str);
        System.out.println(str);
    }
    System.out.println("size=" + x.size());

    Random random = new Random();

    for (int i = 1; i < 100; i++) {
        int k = Math.abs(random.nextInt(9999));
        int a = String.valueOf(k).length();
        int b = String.valueOf(9999).length();
        System.out.println("a=" + a);
        System.out.println("b=" + b);
        String xx = "";
        if (a != b) {
            for (int j = 0; j < (b - a); j++) {
                xx = "0" + xx;
            }
        }
        xx = xx + k;
        System.out.println(xx);
    }

    System.out.println(toUnderLineName("ISOCertifiedStaff"));
    System.out.println(toUnderLineName("CertifiedStaff"));
    System.out.println(toUnderLineName("UserID"));
    System.out.println(toCamelCase("iso_certified_staff"));
    System.out.println(toCamelCase("certified_staff"));
    System.out.println(toCamelCase("user_id"));
}

From source file:DcmSnd.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = parse(args);//  www .  j  ava  2  s  .c  o  m
    DcmSnd dcmsnd = new DcmSnd();
    final List<String> argList = cl.getArgList();
    String remoteAE = argList.get(0);
    String[] calledAETAddress = split(remoteAE, '@');
    dcmsnd.setCalledAET(calledAETAddress[0]);
    if (calledAETAddress[1] == null) {
        dcmsnd.setRemoteHost("127.0.0.1");
        dcmsnd.setRemotePort(104);
    } else {
        String[] hostPort = split(calledAETAddress[1], ':');
        dcmsnd.setRemoteHost(hostPort[0]);
        dcmsnd.setRemotePort(toPort(hostPort[1]));
    }
    if (cl.hasOption("L")) {
        String localAE = cl.getOptionValue("L");
        String[] localPort = split(localAE, ':');
        if (localPort[1] != null) {
            dcmsnd.setLocalPort(toPort(localPort[1]));
        }
        String[] callingAETHost = split(localPort[0], '@');
        dcmsnd.setCalling(callingAETHost[0]);
        if (callingAETHost[1] != null) {
            dcmsnd.setLocalHost(callingAETHost[1]);
        }
    }
    dcmsnd.setOfferDefaultTransferSyntaxInSeparatePresentationContext(cl.hasOption("ts1"));
    dcmsnd.setSendFileRef(cl.hasOption("fileref"));
    if (cl.hasOption("username")) {
        String username = cl.getOptionValue("username");
        UserIdentity userId;
        if (cl.hasOption("passcode")) {
            String passcode = cl.getOptionValue("passcode");
            userId = new UserIdentity.UsernamePasscode(username, passcode.toCharArray());
        } else {
            userId = new UserIdentity.Username(username);
        }
        userId.setPositiveResponseRequested(cl.hasOption("uidnegrsp"));
        dcmsnd.setUserIdentity(userId);
    }
    dcmsnd.setStorageCommitment(cl.hasOption("stgcmt"));
    String remoteStgCmtAE = null;
    if (cl.hasOption("stgcmtae")) {
        try {
            remoteStgCmtAE = cl.getOptionValue("stgcmtae");
            String[] aet_hostport = split(remoteStgCmtAE, '@');
            String[] host_port = split(aet_hostport[1], ':');
            dcmsnd.setStgcmtCalledAET(aet_hostport[0]);
            dcmsnd.setRemoteStgcmtHost(host_port[0]);
            dcmsnd.setRemoteStgcmtPort(toPort(host_port[1]));
        } catch (Exception e) {
            exit("illegal argument of option -stgcmtae");
        }
    }
    if (cl.hasOption("connectTO"))
        dcmsnd.setConnectTimeout(parseInt(cl.getOptionValue("connectTO"),
                "illegal argument of option -connectTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("reaper"))
        dcmsnd.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"),
                "illegal argument of option -reaper", 1, Integer.MAX_VALUE));
    if (cl.hasOption("rspTO"))
        dcmsnd.setDimseRspTimeout(parseInt(cl.getOptionValue("rspTO"), "illegal argument of option -rspTO", 1,
                Integer.MAX_VALUE));
    if (cl.hasOption("acceptTO"))
        dcmsnd.setAcceptTimeout(parseInt(cl.getOptionValue("acceptTO"), "illegal argument of option -acceptTO",
                1, Integer.MAX_VALUE));
    if (cl.hasOption("releaseTO"))
        dcmsnd.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"),
                "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE));
    if (cl.hasOption("soclosedelay"))
        dcmsnd.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"),
                "illegal argument of option -soclosedelay", 1, 10000));
    if (cl.hasOption("shutdowndelay"))
        dcmsnd.setShutdownDelay(parseInt(cl.getOptionValue("shutdowndelay"),
                "illegal argument of option -shutdowndelay", 1, 10000));
    if (cl.hasOption("rcvpdulen"))
        dcmsnd.setMaxPDULengthReceive(
                parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sndpdulen"))
        dcmsnd.setMaxPDULengthSend(
                parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000)
                        * KB);
    if (cl.hasOption("sosndbuf"))
        dcmsnd.setSendBufferSize(
                parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB);
    if (cl.hasOption("sorcvbuf"))
        dcmsnd.setReceiveBufferSize(
                parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB);
    if (cl.hasOption("bufsize"))
        dcmsnd.setTranscoderBufferSize(
                parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB);
    dcmsnd.setPackPDV(!cl.hasOption("pdv1"));
    dcmsnd.setTcpNoDelay(!cl.hasOption("tcpdelay"));
    if (cl.hasOption("async"))
        dcmsnd.setMaxOpsInvoked(
                parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff));
    if (cl.hasOption("lowprior"))
        dcmsnd.setPriority(CommandUtils.LOW);
    if (cl.hasOption("highprior"))
        dcmsnd.setPriority(CommandUtils.HIGH);
    System.out.println("Scanning files to send");
    long t1 = System.currentTimeMillis();
    for (int i = 1, n = argList.size(); i < n; ++i)
        dcmsnd.addFile(new File(argList.get(i)));
    long t2 = System.currentTimeMillis();
    if (dcmsnd.getNumberOfFilesToSend() == 0) {
        System.exit(2);
    }
    System.out.println("\nScanned " + dcmsnd.getNumberOfFilesToSend() + " files in " + ((t2 - t1) / 1000F)
            + "s (=" + ((t2 - t1) / dcmsnd.getNumberOfFilesToSend()) + "ms/file)");
    dcmsnd.configureTransferCapability();
    if (cl.hasOption("tls")) {
        String cipher = cl.getOptionValue("tls");
        if ("NULL".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsWithoutEncyrption();
        } else if ("3DES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTls3DES_EDE_CBC();
        } else if ("AES".equalsIgnoreCase(cipher)) {
            dcmsnd.setTlsAES_128_CBC();
        } else {
            exit("Invalid parameter for option -tls: " + cipher);
        }
        if (cl.hasOption("nossl2")) {
            dcmsnd.disableSSLv2Hello();
        }
        dcmsnd.setTlsNeedClientAuth(!cl.hasOption("noclientauth"));

        if (cl.hasOption("keystore")) {
            dcmsnd.setKeyStoreURL(cl.getOptionValue("keystore"));
        }
        if (cl.hasOption("keystorepw")) {
            dcmsnd.setKeyStorePassword(cl.getOptionValue("keystorepw"));
        }
        if (cl.hasOption("keypw")) {
            dcmsnd.setKeyPassword(cl.getOptionValue("keypw"));
        }
        if (cl.hasOption("truststore")) {
            dcmsnd.setTrustStoreURL(cl.getOptionValue("truststore"));
        }
        if (cl.hasOption("truststorepw")) {
            dcmsnd.setTrustStorePassword(cl.getOptionValue("truststorepw"));
        }
        try {
            dcmsnd.initTLS();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage());
            System.exit(2);
        }
    }
    try {
        dcmsnd.start();
    } catch (Exception e) {
        System.err.println("ERROR: Failed to start server for receiving " + "Storage Commitment results:"
                + e.getMessage());
        System.exit(2);
    }
    try {
        t1 = System.currentTimeMillis();
        try {
            dcmsnd.open();
        } catch (Exception e) {
            System.err.println("ERROR: Failed to establish association:" + e.getMessage());
            System.exit(2);
        }
        t2 = System.currentTimeMillis();
        System.out.println("Connected to " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");

        t1 = System.currentTimeMillis();
        dcmsnd.send();
        t2 = System.currentTimeMillis();
        prompt(dcmsnd, (t2 - t1) / 1000F);
        if (dcmsnd.isStorageCommitment()) {
            t1 = System.currentTimeMillis();
            if (dcmsnd.commit()) {
                t2 = System.currentTimeMillis();
                System.out.println(
                        "Request Storage Commitment from " + remoteAE + " in " + ((t2 - t1) / 1000F) + "s");
                System.out.println("Waiting for Storage Commitment Result..");
                try {
                    DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                    t1 = System.currentTimeMillis();
                    promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                } catch (InterruptedException e) {
                    System.err.println("ERROR:" + e.getMessage());
                }
            }
        }
        dcmsnd.close();
        System.out.println("Released connection to " + remoteAE);
        if (remoteStgCmtAE != null) {
            t1 = System.currentTimeMillis();
            try {
                dcmsnd.openToStgcmtAE();
            } catch (Exception e) {
                System.err.println("ERROR: Failed to establish association:" + e.getMessage());
                System.exit(2);
            }
            t2 = System.currentTimeMillis();
            System.out.println("Connected to " + remoteStgCmtAE + " in " + ((t2 - t1) / 1000F) + "s");
            t1 = System.currentTimeMillis();
            if (dcmsnd.commit()) {
                t2 = System.currentTimeMillis();
                System.out.println("Request Storage Commitment from " + remoteStgCmtAE + " in "
                        + ((t2 - t1) / 1000F) + "s");
                System.out.println("Waiting for Storage Commitment Result..");
                try {
                    DicomObject cmtrslt = dcmsnd.waitForStgCmtResult();
                    t1 = System.currentTimeMillis();
                    promptStgCmt(cmtrslt, ((t1 - t2) / 1000F));
                } catch (InterruptedException e) {
                    System.err.println("ERROR:" + e.getMessage());
                }
            }
            dcmsnd.close();
            System.out.println("Released connection to " + remoteStgCmtAE);
        }
    } finally {
        dcmsnd.stop();
    }
}

From source file:com.yobidrive.diskmap.DiskMapManager.java

public static void main(String[] args) {

    try {//from ww  w. java 2  s. c om
        BasicConfigurator.configure();
        //   (String storeName, String logPath, String keyPath, long ckeckPointPeriod, long logSize, int keySize,
        //      long mapSize, int packInterval, int readThreads, long needleCachedEntries, long bucketCachedBytes, short nodeId)

        /* String path = "/Users/david/Documents/NEEDLES";
        if ( args.length > 0) {
           path = args[0];
        }
        System.out.println("Using directory:" + path);
        */
        DiskMapManager dmm = new DiskMapManager("TestStore", "/drive_hd1", "/drive_ssd/storage_indexes", 1000, // Synching period
                60000 * 5, // Checkpointing period
                2000000000L, // Log file size
                100, // Key max size
                2048, // Nb of buffers
                32768, // Nb of entries (buckets) per buffer
                60, // Compact interval
                8, // Read threads
                TEST_COUNT / 3 * 2 * 140, // NeedleHeaderCachedEntries (1/20 in cache, 1/2 of typical data set)
                TEST_COUNT / 3 * 2 * 140, // NeedleCachedBytes (3% of Map, weights 120 bytes/entry)
                true, // Use needle average age instead of needle yougest age
                (short) 0, (short) 0, 0, new TokenSynchronizer(1), new TokenSynchronizer(1), null);
        // dmm.getBtm().getCheckPoint().copyFrom(new NeedlePointer()) ; // Removes checkpoint

        // System.out.println("Start read for "+TEST_COUNT+" pointers") ;
        Date startDate = new Date();
        Date lapDate = new Date();
        System.out.println("Start read test for " + TEST_COUNT + " pointers");
        long counter = 0;
        long lapCounter = 0;
        startDate = new Date();
        lapDate = new Date();
        long failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dmm.get(key.getBytes("UTF-8"));
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        long timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        startDate = new Date();
        lapDate = new Date();
        System.out.println("Start write test for " + TEST_COUNT + " pointers");
        counter = 0;
        lapCounter = 0;

        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            byte[] value = new byte[128000];
            value[0] = (byte) ((short) counter % 128);
            long chaseDurer = new Date().getTime();
            List<Versioned<byte[]>> previousValues = dmm.get(key.getBytes("UTF-8"));
            long chaseDurer2 = new Date().getTime();
            // System.out.println("Get in "+(chaseDurer2 -chaseDurer)+"ms") ;
            chaseDurer = chaseDurer2;
            Version newVersion = null;
            if (previousValues.size() <= 0) {
                newVersion = new VectorClock();
            } else {
                // Gets previous version
                newVersion = previousValues.get(0).cloneVersioned().getVersion();
            }
            // Increment version before writing
            ((VectorClock) newVersion).incrementVersion(dmm.getNodeId(), new Date().getTime());
            dmm.put(key.getBytes("UTF-8"), value, newVersion);
            chaseDurer2 = new Date().getTime();
            // System.out.println("Put in "+(chaseDurer2 -chaseDurer)+"ms") ;
            // dmm.putValue(key.getBytes("UTF-8"), value) ;
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print("("+counter+")") ;
                } else
                    // System.out.print("["+counter+"]") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }

        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n"
                + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: "
                + (TEST_COUNT * 1000 / timeSpent) + " tps");

        System.out.println("Start read for " + TEST_COUNT + " pointers");
        startDate = new Date();
        lapDate = new Date();
        failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dmm.get(key.getBytes("UTF-8"));
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        dmm.stopService();
        System.out.println("Max cycle time = "
                + (dmm.getBtm().getMaxCycleTimePass1() + dmm.getBtm().getMaxCycleTimePass2()));

    } catch (Throwable th) {
        th.printStackTrace();
    }

}

From source file:com.g2inc.scap.library.domain.SCAPContentManager.java

/**
 * A main method only used for testing/*from ww  w  .  j ava  2 s .  c o  m*/
 *
 * @param args Command-line arguments
 * 
*/
public static void main(String[] args) throws Exception {
    BasicConfigurator.configure();
    LOG.trace("SchemaParser starting, schemaVersion =" + args[0] + ", xsd File=" + args[1]);
    File xsdFile = new File(args[1]);
    if (!xsdFile.exists()) {
        LOG.error("Usage: java SchemaParser <name of xsd file>");
    }
    SCAPDocumentTypeEnum version = SCAPDocumentTypeEnum.valueOf(args[0]);
    SCAPContentManager mgr = SCAPContentManager.getInstance(new File(args[1]));

    // schema-related data should now be populated
    List<String> platformTypes = mgr.getValidPlatforms(version);
    LOG.trace("STARTING PLATFORMS");
    for (int i = 0; i < platformTypes.size(); i++) {
        LOG.trace(platformTypes.get(i));
    }

    String[] platforms = { "windows", "independent" };

    List<NameDoc> list = null;
    Iterator<NameDoc> iter = null;
    LOG.trace("STARTING TESTS");
    list = mgr.getValidTestTypes(version, platforms);
    iter = list.iterator();
    while (iter.hasNext()) {
        NameDoc testName = iter.next();
        LOG.trace("\t" + testName);
    }
    LOG.trace("STARTING OBJECTS");
    list = mgr.getValidObjectTypes(version, platforms);
    iter = list.iterator();
    while (iter.hasNext()) {
        NameDoc objName = iter.next();
        LOG.trace("\t" + objName);
        LOG.trace("STARTING OBJECT ENTITIES FOR " + objName.getName());
        List<OvalEntity> entityList = mgr.getValidObjectEntityTypes(version, "windows", objName.getName());
        if (entityList != null && entityList.size() > 0) {
            for (int i = 0; i < entityList.size(); i++) {
                LOG.trace("\t\t" + entityList.get(i).toString());
            }
        }
    }

    LOG.trace("STARTING STATES");
    list = mgr.getValidStateTypes(version, platforms);
    iter = list.iterator();
    while (iter.hasNext()) {
        NameDoc stateName = iter.next();
        LOG.trace("\t" + stateName);
        LOG.trace("STARTING STATE ENTITIES FOR " + stateName.getName());
        List<OvalEntity> entityList = mgr.getValidStateEntityTypes(version, "windows", stateName.getName());
        if (entityList != null && entityList.size() > 0) {
            for (int i = 0; i < entityList.size(); i++) {
                LOG.trace("\t\t" + entityList.get(i).toString());
            }
        }
    }
}