Example usage for java.lang System currentTimeMillis

List of usage examples for java.lang System currentTimeMillis

Introduction

In this page you can find the example usage for java.lang System currentTimeMillis.

Prototype

@HotSpotIntrinsicCandidate
public static native long currentTimeMillis();

Source Link

Document

Returns the current time in milliseconds.

Usage

From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java

/**
 * @param args/*from   w  ww .j  a v  a  2  s.co  m*/
 */
@SuppressWarnings("unused")
public static void main(String[] args) {
    if (args.length > 2) {
        WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(WaarpLogLevel.DEBUG));
    } else {
        WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(null));
    }
    logger = WaarpLoggerFactory.getLogger(HttpTestRestR66Client.class);
    Configuration.configuration.HOST_ID = hostid;
    if (args.length > 0) {
        NB = Integer.parseInt(args[0]);
        if (Configuration.configuration.CLIENT_THREAD < NB) {
            Configuration.configuration.CLIENT_THREAD = NB + 1;
        }
        if (args.length > 1) {
            NBPERTHREAD = Integer.parseInt(args[1]);
        }
    }
    if (NB == 1 && NBPERTHREAD == 1) {
        DEBUG = true;
    }

    try {
        HttpTestR66PseudoMain.config = HttpTestR66PseudoMain.getTestConfiguration();
    } catch (CryptoException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        return;
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        return;
    }
    if (HttpTestR66PseudoMain.config.REST_ADDRESS != null) {
        host = HttpTestR66PseudoMain.config.REST_ADDRESS;
    }
    String filename = keydesfilename;
    Configuration.configuration.cryptoFile = filename;
    File keyfile = new File(filename);
    Des des = new Des();
    try {
        des.setSecretKey(keyfile);
    } catch (CryptoException e) {
        logger.error("Unable to load CryptoKey from Config file");
        return;
    } catch (IOException e) {
        logger.error("Unable to load CryptoKey from Config file");
        return;
    }
    Configuration.configuration.cryptoKey = des;
    HttpRestR66Handler.instantiateHandlers(HttpTestR66PseudoMain.config);
    // Configure the client.
    clientHelper = new HttpRestR66Client(baseURI, new HttpTestRestClientInitializer(null),
            Configuration.configuration.CLIENT_THREAD, Configuration.configuration.TIMEOUTCON);
    logger.warn("ClientHelper created");
    try {
        try {
            long start = System.currentTimeMillis();
            for (int i = 0; i < NBPERTHREAD; i++) {
                options(null);
            }
            long stop = System.currentTimeMillis();
            long diff = stop - start == 0 ? 1 : stop - start;
            logger.warn("Options: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        } catch (HttpInvalidAuthenticationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        count.set(0);
        long start = System.currentTimeMillis();
        if (false) {
            for (RESTHANDLERS handler : HttpRestR66Handler.RESTHANDLERS.values()) {
                try {
                    deleteData(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        long stop = System.currentTimeMillis();
        long diff = stop - start == 0 ? 1 : stop - start;
        if (false) {
            logger.warn("Delete: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        }
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    multiDataRequests(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("Create: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    realAllData(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("ReadAll: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        for (int i = 0; i < NBPERTHREAD; i++) {
            try {
                multiDataRequests(RESTHANDLERS.DbTaskRunner);
            } catch (HttpInvalidAuthenticationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn(
                "CreateMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        launchThreads();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("CreateMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?"
                + count.get());

        // Set usefull item first
        if (RestConfiguration.CRUD.UPDATE.isValid(
                HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) {
            String key = null, value = null;
            Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                String buz = null;
                if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) {
                    key = userAuthent;
                    value = keyAuthent;
                    // Need business
                    buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                            + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>"
                            + "<businessid>" + userAuthent + "</businessid></business>";
                } else {
                    // Need business
                    buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                            + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>"
                            + "<businessid>monadmin</businessid></business>";
                }
                ObjectNode node = JsonHandler.createObjectNode();
                node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz);
                logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null,
                        JsonHandler.writeAsString(node));
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Need Hostzz
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                AbstractDbData dbData;
                dbData = new DbHostAuth(null, hostid, address, HttpTestR66PseudoMain.config.REST_PORT, false,
                        hostkey.getBytes(), true, false);
                logger.warn("Send query: " + RESTHANDLERS.DbHostAuth.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.POST, host, RESTHANDLERS.DbHostAuth.uri, key, value, null, dbData.asJson());
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
        }

        // Other Command as actions
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    action(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        getStatus();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn(
                "Commands: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        for (int i = 0; i < NBPERTHREAD; i++) {
            getStatus();
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("GetStatusMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?"
                + count.get());

        count.set(0);
        isStatus = true;
        start = System.currentTimeMillis();
        launchThreads();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("GetStatusMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB
                + "=?" + count.get());

        // Clean
        if (RestConfiguration.CRUD.UPDATE.isValid(
                HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) {
            String key = null, value = null;
            Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) {
                    key = userAuthent;
                    value = keyAuthent;
                }
                // Reset business
                String buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                        + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid></business>";
                ObjectNode node = JsonHandler.createObjectNode();
                node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz);
                logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null,
                        JsonHandler.writeAsString(node));
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Remove Hostzz
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                try {
                    RestFuture future = deleteData(channel, RESTHANDLERS.DbHostAuth);
                    try {
                        future.await();
                    } catch (InterruptedException e) {
                    }
                } catch (HttpInvalidAuthenticationException e1) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Shutdown
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                ShutdownOrBlockJsonPacket shutd = new ShutdownOrBlockJsonPacket();
                shutd.setRestartOrBlock(false);
                shutd.setShutdownOrBlock(true);
                shutd.setRequestUserPacket(LocalPacketFactory.SHUTDOWNPACKET);
                String pwd = "pwdhttp";
                byte[] bpwd = FilesystemBasedDigest.passwdCrypt(pwd.getBytes(WaarpStringUtils.UTF8));
                shutd.setKey(bpwd);
                logger.warn("Send query: " + RESTHANDLERS.Server.uri);
                RestFuture future = action(channel, HttpMethod.PUT, RESTHANDLERS.Server.uri, shutd);
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) {
        }
    } finally {
        logger.debug("ClientHelper closing");
        clientHelper.closeAll();
        logger.warn("ClientHelper closed");
    }
}

From source file:geva.Operator.Operations.SinglePointCrossover.java

public static void main(String[] args) {
    SinglePointCrossover cop = new SinglePointCrossover(new MersenneTwisterFast(), 1);
    cop.setFixedCrossoverPoint(false);//from  w  w  w .j a v  a2s. co m
    GEChromosome c1 = new GEChromosome(10);
    GEChromosome c2 = new GEChromosome(10);

    for (int i = 0; i < 20; i++) {
        c1.add(1);

        c2.add(2);

    }

    cop.makeNewChromosome(c1, c2, c1.size(), c2.size());

    System.out.println(c1.toString());
    System.out.println(c2.toString());

    Genotype g1 = new Genotype();
    Genotype g2 = new Genotype();
    g1.add(c1);
    g2.add(c2);
    GEIndividual i1 = new GEIndividual();
    GEIndividual i2 = new GEIndividual();
    i1.setMapper(new GEGrammar());
    i1.setGenotype(g1);
    i2.setMapper(new GEGrammar());
    i2.setGenotype(g2);

    ArrayList<Individual> aI = new ArrayList<Individual>(2);
    aI.add(i1);
    aI.add(i2);

    cop.doOperation(aI);

    System.out.println();
    System.out.println("Testing operation crossover");
    System.out.println();
    c1 = (GEChromosome) i1.getGenotype().get(0);
    c2 = (GEChromosome) i2.getGenotype().get(0);

    System.out.println(c1.toString());
    System.out.println(c2.toString());

    CrossoverModule cm = new CrossoverModule(new MersenneTwisterFast(), cop);

    SimplePopulation p = new SimplePopulation();
    p.add(i1);
    p.add(i2);
    cm.setPopulation(p);
    long st = System.currentTimeMillis();
    for (int i = 1; i < 100000000; i += 20) {

        cm.perform();

    }
    long et = System.currentTimeMillis();
    System.out.println("Done running: Total time(Ms) for " + 100000000 + " generations was" + (et - st));
    System.out.println();
    System.out.println("Testing module crossover");
    System.out.println();

    c1 = (GEChromosome) i1.getGenotype().get(0);
    c2 = (GEChromosome) i2.getGenotype().get(0);

    System.out.println(c1.toString());
    System.out.println(c2.toString());

}

From source file:apps.LuceneQuery.java

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

    options.addOption("d", null, true, "index directory");
    options.addOption("i", null, true, "input file");
    options.addOption("s", null, true, "stop word file");
    options.addOption("n", null, true, "max # of results");
    options.addOption("o", null, true, "a TREC-style output file");
    options.addOption("r", null, true, "an optional QREL file, if specified,"
            + "we save results only for queries for which we find at least one relevant entry.");

    options.addOption("prob", null, true, "question sampling probability");
    options.addOption("max_query_qty", null, true, "a maximum number of queries to run");
    options.addOption("bm25_b", null, true, "BM25 parameter: b");
    options.addOption("bm25_k1", null, true, "BM25 parameter: k1");
    options.addOption("bm25fixed", null, false, "use the fixed BM25 similarity");

    options.addOption("seed", null, true, "random seed");

    Joiner commaJoin = Joiner.on(',');
    Joiner spaceJoin = Joiner.on(' ');

    options.addOption("source_type", null, true,
            "query source type: " + commaJoin.join(SourceFactory.getQuerySourceList()));

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

    QrelReader qrels = null;//from ww w .  j ava2  s  .  co m

    try {

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

        String indexDir = null;

        if (cmd.hasOption("d")) {
            indexDir = cmd.getOptionValue("d");
        } else {
            Usage("Specify 'index directory'", options);
        }

        String inputFileName = null;

        if (cmd.hasOption("i")) {
            inputFileName = cmd.getOptionValue("i");
        } else {
            Usage("Specify 'input file'", options);
        }

        DictNoComments stopWords = null;

        if (cmd.hasOption("s")) {
            String stopWordFileName = cmd.getOptionValue("s");
            stopWords = new DictNoComments(new File(stopWordFileName), true /* lowercasing */);
            System.out.println("Using the stopword file: " + stopWordFileName);
        }

        String sourceName = cmd.getOptionValue("source_type");

        if (sourceName == null)
            Usage("Specify document source type", options);

        int numRet = 100;

        if (cmd.hasOption("n")) {
            numRet = Integer.parseInt(cmd.getOptionValue("n"));
            System.out.println("Retrieving at most " + numRet + " candidate entries.");
        }

        String trecOutFileName = null;

        if (cmd.hasOption("o")) {
            trecOutFileName = cmd.getOptionValue("o");
        } else {
            Usage("Specify 'a TREC-style output file'", options);
        }

        double fProb = 1.0f;

        if (cmd.hasOption("prob")) {
            try {
                fProb = Double.parseDouble(cmd.getOptionValue("prob"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'question sampling probability'", options);
            }
        }

        if (fProb <= 0 || fProb > 1) {
            Usage("Question sampling probability should be >0 and <=1", options);
        }

        System.out.println("Sample the following fraction of questions: " + fProb);

        float bm25_k1 = UtilConst.BM25_K1_DEFAULT, bm25_b = UtilConst.BM25_B_DEFAULT;

        if (cmd.hasOption("bm25_k1")) {
            try {
                bm25_k1 = Float.parseFloat(cmd.getOptionValue("bm25_k1"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'bm25_k1'", options);
            }
        }

        if (cmd.hasOption("bm25_b")) {
            try {
                bm25_b = Float.parseFloat(cmd.getOptionValue("bm25_b"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'bm25_b'", options);
            }
        }

        long seed = 0;

        String tmpl = cmd.getOptionValue("seed");

        if (tmpl != null)
            seed = Long.parseLong(tmpl);

        System.out.println("Using seed: " + seed);

        Random randGen = new Random(seed);

        System.out.println(String.format("BM25 parameters k1=%f b=%f ", bm25_k1, bm25_b));

        boolean useFixedBM25 = cmd.hasOption("bm25fixed");

        EnglishAnalyzer analyzer = new EnglishAnalyzer();
        Similarity similarity = null;

        if (useFixedBM25) {
            System.out.println(String.format("Using fixed BM25Simlarity, k1=%f b=%f", bm25_k1, bm25_b));
            similarity = new BM25SimilarityFix(bm25_k1, bm25_b);
        } else {
            System.out.println(String.format("Using Lucene BM25Similarity, k1=%f b=%f", bm25_k1, bm25_b));
            similarity = new BM25Similarity(bm25_k1, bm25_b);
        }

        int maxQueryQty = Integer.MAX_VALUE;

        if (cmd.hasOption("max_query_qty")) {
            try {
                maxQueryQty = Integer.parseInt(cmd.getOptionValue("max_query_qty"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'max_query_qty'", options);
            }
        }

        System.out.println(String.format("Executing at most %d queries", maxQueryQty));

        if (cmd.hasOption("r")) {
            String qrelFile = cmd.getOptionValue("r");
            System.out.println("Using the qrel file: '" + qrelFile
                    + "', queries not returning a relevant entry will be ignored.");
            qrels = new QrelReader(qrelFile);
        }

        System.out.println(String.format("Using indexing directory %s", indexDir));

        LuceneCandidateProvider candProvider = new LuceneCandidateProvider(indexDir, analyzer, similarity);
        TextCleaner textCleaner = new TextCleaner(stopWords);

        QuerySource inpQuerySource = SourceFactory.createQuerySource(sourceName, inputFileName);
        QueryEntry inpQuery = null;

        BufferedWriter trecOutFile = new BufferedWriter(new FileWriter(new File(trecOutFileName)));

        int questNum = 0, questQty = 0;

        long totalTimeMS = 0;

        while ((inpQuery = inpQuerySource.next()) != null) {
            if (questQty >= maxQueryQty)
                break;
            ++questNum;

            String queryID = inpQuery.mQueryId;

            if (randGen.nextDouble() <= fProb) {
                ++questQty;

                String tokQuery = spaceJoin.join(textCleaner.cleanUp(inpQuery.mQueryText));
                String query = TextCleaner.luceneSafeCleanUp(tokQuery).trim();

                ResEntry[] results = null;

                if (query.isEmpty()) {
                    results = new ResEntry[0];
                    System.out.println(String.format("WARNING, empty query id = '%s'", inpQuery.mQueryId));
                } else {

                    try {
                        long start = System.currentTimeMillis();

                        results = candProvider.getCandidates(questNum, query, numRet);

                        long end = System.currentTimeMillis();
                        long searchTimeMS = end - start;
                        totalTimeMS += searchTimeMS;

                        System.out.println(String.format(
                                "Obtained results for the query # %d (answered %d queries), queryID %s the search took %d ms, we asked for max %d entries got %d",
                                questNum, questQty, queryID, searchTimeMS, numRet, results.length));

                    } catch (ParseException e) {
                        e.printStackTrace();
                        System.err.println(
                                "Error parsing query: " + query + " orig question is :" + inpQuery.mQueryText);
                        System.exit(1);
                    }
                }

                boolean bSave = true;

                if (qrels != null) {
                    boolean bOk = false;
                    for (ResEntry r : results) {
                        String label = qrels.get(queryID, r.mDocId);
                        if (candProvider.isRelevLabel(label, 1)) {
                            bOk = true;
                            break;
                        }
                    }
                    if (!bOk)
                        bSave = false;
                }

                //            System.out.println(String.format("Ranking results the query # %d queryId='%s' save results? %b", 
                //                                              questNum, queryID, bSave));          
                if (bSave) {
                    saveTrecResults(queryID, results, trecOutFile, TREC_RUN, numRet);
                }
            }

            if (questNum % 1000 == 0)
                System.out.println(String.format("Proccessed %d questions", questNum));

        }

        System.out.println(String.format("Proccessed %d questions, the search took %f MS on average", questQty,
                (float) totalTimeMS / questQty));

        trecOutFile.close();

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

From source file:org.pegadi.client.ApplicationLauncher.java

public static void main(String[] args) {
    com.sun.net.ssl.internal.ssl.Provider provider = new com.sun.net.ssl.internal.ssl.Provider();
    java.security.Security.addProvider(provider);
    setAllPermissions();/*  ww w . j a va 2 s . com*/
    /**
     * If we are on Apples operating system, we would like to use the screen
     * menu bar It is the first property we set in our main method. This is
     * to make sure that the property is set before awt is loaded.
     */
    if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
    }
    Logger log = LoggerFactory.getLogger(ApplicationLauncher.class);
    /**
     * Making sure default L&F is System
     */
    if (!UIManager.getLookAndFeel().getName().equals(UIManager.getSystemLookAndFeelClassName())) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            log.warn("Unable to change L&F to System", e);
        }
    }

    long start = System.currentTimeMillis();

    // Splash
    Splash splash = new Splash("/images/splash.png");
    splash.setVisible(true);

    splash.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "org/pegadi/client/client-context.xml");
    closeContextOnShutdown(context);

    long timeToLogin = System.currentTimeMillis() - start;
    log.info("Connected OK after {} ms", timeToLogin);
    log.info("Java Version {}", System.getProperty("java.version"));

    splash.dispose();
}

From source file:com.glaf.core.security.SecurityUtils.java

public static void main(String[] args) {
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
        String key = UUID32.getUUID();
        String data = "glaf_product_" + i;
        String enc_data = SecurityUtils.encode(key, data);
        // System.out.println(enc_data);
        System.out.println(SecurityUtils.decode(key, enc_data));
    }/*ww  w  . j a  va  2 s. c  o  m*/
    long times = System.currentTimeMillis() - start;
    System.out.println("():" + times);
    System.out.println(SecurityUtils.hash("12345678"));
    System.out.println(SecurityUtils.hash("111111"));
    System.out.println(SecurityUtils.genKey2048());
}

From source file:edu.southampton.wais.crowd.terrier.applications.Indexing.java

/** 
 * Used for testing purposes.//  w  ww  . j a v a2 s.c  o  m
 * @param args the command line arguments.
 */
public static void main(String[] args) {
    long startTime = System.currentTimeMillis();

    Indexing t = new Indexing();

    t.setTRECIndexing(t.terrierIndexPath, t.terrierIndexPrefix);

    logger.info("Cleaning the dirs with previous index..");

    try {

        FileUtils.cleanDirectory(new File(t.terrierIndexPath));

    } catch (IOException e) {
        // TODO Auto-generated catch block

        e.printStackTrace();

        logger.info("Exception : " + e.getMessage());

    }

    logger.info("Cleaning done");

    t.index();

    long endTime = System.currentTimeMillis();

    if (logger.isInfoEnabled())

        logger.info("Elapsed time=" + ((endTime - startTime) / 1000.0D));

}

From source file:com.maxl.java.aips2xml.Aips2Xml.java

public static void main(String[] args) {
    Options options = new Options();
    addOption(options, "help", "print this message", false, false);
    addOption(options, "version", "print the version information and exit", false, false);
    addOption(options, "quiet", "be extra quiet", false, false);
    addOption(options, "verbose", "be extra verbose", false, false);
    addOption(options, "zip", "generate zip file", false, false);
    addOption(options, "lang", "use given language", true, false);
    addOption(options, "alpha", "only include titles which start with option value", true, false);
    addOption(options, "nodown", "no download, parse only", false, false);

    commandLineParse(options, args);/*  www  .java 2 s.c  o  m*/

    // Download all files and save them in appropriate directories
    if (DOWNLOAD_ALL) {
        System.out.println("");
        allDown();
    }

    DateFormat df = new SimpleDateFormat("ddMMyy");
    String date_str = df.format(new Date());

    System.out.println("");
    if (!DB_LANGUAGE.isEmpty()) {
        extractPackageInfo();

        List<MedicalInformations.MedicalInformation> med_list = readAipsFile();

        if (SHOW_LOGS) {
            System.out.println("");
            System.out.println("- Generating xml and html files ... ");
        }
        long startTime = System.currentTimeMillis();
        int counter = 0;
        String fi_complete_xml = "";
        for (MedicalInformations.MedicalInformation m : med_list) {
            if (m.getLang().equals(DB_LANGUAGE) && m.getType().equals("fi")) {
                if (m.getTitle().startsWith(MED_TITLE)) {
                    if (SHOW_LOGS)
                        System.out.println(++counter + ": " + m.getTitle());
                    String[] html_str = extractHtmlSection(m);
                    // html_str[0] -> registration numbers
                    // html_str[1] -> content string
                    String xml_str = convertHtmlToXml(m.getTitle(), html_str[1], html_str[0]);
                    if (DB_LANGUAGE.equals("de")) {
                        if (!html_str[0].isEmpty()) {
                            String name = m.getTitle();
                            // Replace all "Sonderzeichen"
                            name = name.replaceAll("[/%:]", "_");
                            writeToFile(html_str[1], "./fis/fi_de_html/", name + "_fi_de.html");
                            writeToFile(xml_str, "./fis/fi_de_xml/", name + "_fi_de.xml");
                            fi_complete_xml += (xml_str + "\n");
                        }
                    } else if (DB_LANGUAGE.equals("fr")) {
                        if (!html_str[0].isEmpty()) {
                            String name = m.getTitle();
                            // Replace all "Sonderzeichen"
                            name = name.replaceAll("[/%:]", "_");
                            writeToFile(html_str[1], "./fis/fi_fr_html/", name + "_fi_fr.html");
                            writeToFile(xml_str, "./fis/fi_fr_xml/", name + "_fi_fr.xml");
                            fi_complete_xml += (xml_str + "\n");
                        }
                    }
                }
            }
        }

        // Add header to huge xml
        fi_complete_xml = addHeaderToXml(fi_complete_xml);
        // Dump to file
        if (DB_LANGUAGE.equals("de")) {
            writeToFile(fi_complete_xml, "./fis/", "fi_de.xml");
            if (ZIP_XML)
                zipToFile("./fis/", "fi_de.xml");
        } else if (DB_LANGUAGE.equals("fr")) {
            writeToFile(fi_complete_xml, "./fis/", "fi_fr.xml");
            if (ZIP_XML)
                zipToFile("./fis/", "fi_fr.xml");
        }

        // Move stylesheet file to ./fis/ folders
        try {
            File src = new File("./css/amiko_stylesheet.css");
            File dst_de = new File("./fis/fi_de_html/");
            File dst_fr = new File("./fis/fi_fr_html/");
            if (src.exists()) {
                if (dst_de.exists())
                    FileUtils.copyFileToDirectory(src, dst_de);
                if (dst_fr.exists())
                    FileUtils.copyFileToDirectory(src, dst_fr);
            }
        } catch (IOException e) {
            // Unhandled!
        }

        if (SHOW_LOGS) {
            long stopTime = System.currentTimeMillis();
            System.out.println("- Generated " + counter + " xml and html files in "
                    + (stopTime - startTime) / 1000.0f + " sec");
        }
    }

    System.exit(0);
}

From source file:edu.umn.cs.spatialHadoop.operations.RangeQuery.java

public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
    final OperationsParams params = new OperationsParams(new GenericOptionsParser(args));

    final Path[] paths = params.getPaths();
    if (paths.length <= 1 && !params.checkInput()) {
        printUsage();/* w  w w  .  ja v a  2s  .  c o  m*/
        System.exit(1);
    }
    if (paths.length >= 2 && !params.checkInputOutput()) {
        printUsage();
        System.exit(1);
    }
    if (params.get("rect") == null) {
        System.err.println("You must provide a query range");
        printUsage();
        System.exit(1);
    }
    final Path inPath = params.getInputPath();
    final Path outPath = params.getOutputPath();
    final Rectangle[] queryRanges = params.getShapes("rect", new Rectangle());

    // All running jobs
    final Vector<Long> resultsCounts = new Vector<Long>();
    Vector<Job> jobs = new Vector<Job>();
    Vector<Thread> threads = new Vector<Thread>();

    long t1 = System.currentTimeMillis();
    for (int i = 0; i < queryRanges.length; i++) {
        final OperationsParams queryParams = new OperationsParams(params);
        OperationsParams.setShape(queryParams, "rect", queryRanges[i]);
        if (OperationsParams.isLocal(new JobConf(queryParams), inPath)) {
            // Run in local mode
            final Rectangle queryRange = queryRanges[i];
            final Shape shape = queryParams.getShape("shape");
            final Path output = outPath == null ? null
                    : (queryRanges.length == 1 ? outPath : new Path(outPath, String.format("%05d", i)));
            Thread thread = new Thread() {
                @Override
                public void run() {
                    FSDataOutputStream outFile = null;
                    final byte[] newLine = System.getProperty("line.separator", "\n").getBytes();
                    try {
                        ResultCollector<Shape> collector = null;
                        if (output != null) {
                            FileSystem outFS = output.getFileSystem(queryParams);
                            final FSDataOutputStream foutFile = outFile = outFS.create(output);
                            collector = new ResultCollector<Shape>() {
                                final Text tempText = new Text2();

                                @Override
                                public synchronized void collect(Shape r) {
                                    try {
                                        tempText.clear();
                                        r.toText(tempText);
                                        foutFile.write(tempText.getBytes(), 0, tempText.getLength());
                                        foutFile.write(newLine);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            };
                        } else {
                            outFile = null;
                        }
                        long resultCount = rangeQueryLocal(inPath, queryRange, shape, queryParams, collector);
                        resultsCounts.add(resultCount);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            if (outFile != null)
                                outFile.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            };
            thread.start();
            threads.add(thread);
        } else {
            // Run in MapReduce mode
            queryParams.setBoolean("background", true);
            Job job = rangeQueryMapReduce(inPath, outPath, queryParams);
            jobs.add(job);
        }
    }

    while (!jobs.isEmpty()) {
        Job firstJob = jobs.firstElement();
        firstJob.waitForCompletion(false);
        if (!firstJob.isSuccessful()) {
            System.err.println("Error running job " + firstJob);
            System.err.println("Killing all remaining jobs");
            for (int j = 1; j < jobs.size(); j++)
                jobs.get(j).killJob();
            System.exit(1);
        }
        Counters counters = firstJob.getCounters();
        Counter outputRecordCounter = counters.findCounter(Task.Counter.MAP_OUTPUT_RECORDS);
        resultsCounts.add(outputRecordCounter.getValue());
        jobs.remove(0);
    }
    while (!threads.isEmpty()) {
        try {
            Thread thread = threads.firstElement();
            thread.join();
            threads.remove(0);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    long t2 = System.currentTimeMillis();

    System.out.println("Time for " + queryRanges.length + " jobs is " + (t2 - t1) + " millis");
    System.out.println("Results counts: " + resultsCounts);
}

From source file:de.codesourcery.geoip.Main.java

public static void main(String[] args) throws Exception {
    final IGeoLocator<StringSubject> locator = createGeoLocator();

    final JFrame frame = new JFrame("GeoIP");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) {
            try {
                locator.dispose();//  w  w w  .ja  v a  2 s. c o m
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        };
    });

    final MapImage image = MapImage.getRobinsonWorldMap(); // MapImage.getMillerWorldMap();      
    final MapCanvas canvas = new MapCanvas(image);

    for (GeoLocation<StringSubject> loc : locator.locate(getSpammers())) {
        if (loc.hasValidCoordinates()) {
            canvas.addCoordinate(PointRenderer.createPoint(loc, Color.YELLOW));
        }
    }

    //      canvas.addCoordinate( PointRenderer.createPoint( ZERO , Color.YELLOW ) );
    //      canvas.addCoordinate( PointRenderer.createPoint( WELLINGTON , Color.RED ) );
    //      canvas.addCoordinate( PointRenderer.createPoint( MELBOURNE , Color.RED ) );
    //      canvas.addCoordinate( PointRenderer.createPoint( HAMBURG , Color.RED ) );

    final double heightToWidth = image.height() / (double) image.width(); // preserve aspect ratio of map
    canvas.setPreferredSize(new Dimension(640, (int) Math.round(640 * heightToWidth)));

    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());

    panel.add(new JLabel("Scale-X"));
    final JTextField scaleX = new JTextField(Double.toString(image.getScaleX()));
    scaleX.setColumns(5);

    final JTextField scaleY = new JTextField(Double.toString(image.getScaleY()));
    scaleY.setColumns(5);

    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            double x = Double.parseDouble(scaleX.getText());
            double y = Double.parseDouble(scaleY.getText());
            image.setScale(x, y);
            canvas.repaint();
        }
    };
    scaleX.addActionListener(listener);
    scaleY.addActionListener(listener);

    panel.add(new JLabel("Scale-X"));
    panel.add(scaleX);

    panel.add(new JLabel("Scale-Y"));
    panel.add(scaleY);

    final JTextField ipAddress = new JTextField("www.kickstarter.com");
    ipAddress.setColumns(20);

    final ActionListener ipListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String destinationIP = ipAddress.getText();
            if (StringUtils.isBlank(destinationIP)) {
                return;
            }

            /*
             * Perform traceroute.
             */
            final List<String> hops;
            try {
                if (TracePath.isPathTracingAvailable()) {
                    hops = TracePath.trace(destinationIP);
                } else {
                    System.err.println("tracepath not available.");
                    if (TracePath.isValidAddress(destinationIP)) {
                        hops = new ArrayList<>();
                        hops.add(destinationIP);
                    } else {
                        System.err.println(destinationIP + " is no valid IP");
                        return;
                    }
                }
            } catch (Exception ex) {
                System.err.println("Failed to trace " + destinationIP);
                ex.printStackTrace();
                return;
            }

            System.out.println("Trace contains " + hops.size() + " IPs");

            /*
             * Gather locations.
             */
            final List<StringSubject> subjects = new ArrayList<>();
            for (String ip : hops) {
                subjects.add(new StringSubject(ip));
            }

            final List<GeoLocation<StringSubject>> locations;
            try {
                long time = -System.currentTimeMillis();
                locations = locator.locate(subjects);
                time += System.currentTimeMillis();

                System.out.println("Locating hops for " + destinationIP + " returned " + locations.size()
                        + " valid locations ( time: " + time + " ms)");
                System.out.flush();

            } catch (Exception e2) {
                e2.printStackTrace();
                return;
            }

            /*
             * Weed-out invalid/unknown locations.
             */
            {
                GeoLocation<StringSubject> previous = null;
                for (Iterator<GeoLocation<StringSubject>> it = locations.iterator(); it.hasNext();) {
                    final GeoLocation<StringSubject> location = it.next();
                    if (!location.hasValidCoordinates()
                            || (previous != null && previous.coordinate().equals(location.coordinate()))) {
                        it.remove();
                        System.err.println("Ignoring invalid/duplicate location for " + location);
                    } else {
                        previous = location;
                    }
                }
            }

            /*
             * Populate chart.
             */

            System.out.println("Adding " + locations.size() + " hops to chart");
            System.out.flush();

            canvas.removeAllCoordinates();

            if (locations.size() == 1) {
                canvas.addCoordinate(
                        PointRenderer.createPoint(locations.get(0), getLabel(locations.get(0)), Color.BLACK));
            } else if (locations.size() > 1) {
                GeoLocation<StringSubject> previous = locations.get(0);
                MapPoint previousPoint = PointRenderer.createPoint(previous, getLabel(previous), Color.BLACK);
                final int len = locations.size();
                for (int i = 1; i < len; i++) {
                    final GeoLocation<StringSubject> current = locations.get(i);
                    //                  final MapPoint currentPoint = PointRenderer.createPoint( current , getLabel( current ) , Color.BLACK );
                    final MapPoint currentPoint = PointRenderer.createPoint(current, Color.BLACK);

                    //                  canvas.addCoordinate( LineRenderer.createLine( previousPoint , currentPoint , Color.RED ) );
                    canvas.addCoordinate(CurvedLineRenderer.createLine(previousPoint, currentPoint, Color.RED));

                    previous = locations.get(i);
                    previousPoint = currentPoint;
                }
            }
            System.out.println("Finished adding");
            System.out.flush();
            canvas.repaint();
        }
    };
    ipAddress.addActionListener(ipListener);

    panel.add(new JLabel("IP"));
    panel.add(ipAddress);

    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(panel, BorderLayout.NORTH);
    frame.getContentPane().add(canvas, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
}

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

public static void main(String[] args) {
    long start = System.currentTimeMillis();
    System.out.println(org.apache.commons.codec.digest.DigestUtils
            .md5Hex("jdbc:sqlserver://127.0.0.1:1433;databaseName=yz"));
    for (int i = 0; i < 10000; i++) {
        System.out.println(org.apache.commons.codec.digest.DigestUtils
                .md5Hex("jdbc:sqlserver://127.0.0.1:1433;databaseName=yz" + i));
    }//w ww .j a v  a  2  s  .  c  o  m
    long times = System.currentTimeMillis() - start;
    System.out.println("():" + times);
}