Example usage for org.springframework.util StopWatch stop

List of usage examples for org.springframework.util StopWatch stop

Introduction

In this page you can find the example usage for org.springframework.util StopWatch stop.

Prototype

public void stop() throws IllegalStateException 

Source Link

Document

Stop the current task.

Usage

From source file:test.buddhabrot.BuddhabrotApp.java

public static void main(String[] args) {

    log.info("GridNode Starting...");
    StopWatch sw = new StopWatch();
    sw.start();// w  w  w  . j  a  va2  s  .  c  o m

    GridNode node = Grid.startLightGridNode();

    log.info("GridNode ID : " + node.getId());

    log.info("Registered in Cluster : " + node.getNodeRegistrationService().getRegistration().getClusterId());

    sw.stop();

    log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]");

    // Create App Instance
    final BuddhabrotApp app = new BuddhabrotApp(node);

    app.requestFocus();

    // Create Buddhabrot Job
    BuddhabrotJob buddhabrotJob = new BuddhabrotJob(WIDTH, HEIGHT);

    // Start Job Submission
    sw.start();

    System.err.println(new Date());

    GridJobFuture future = node.getJobSubmissionService().submitJob(buddhabrotJob, new ResultCallback() {

        public void onResult(Serializable result) {

            log.debug("CALLBACK");

            if (result == null)
                return;
            if (result instanceof int[][]) {
                app.onResult((int[][]) result);
            }
        }

    });

    app.setFuture(future);

}

From source file:edu.isistan.carcha.CarchaPipeline.java

/**
 * The main method.// w w w .j ava 2  s . c  o  m
 *
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {
    String inputDirectory = args[0];
    String output = args[1];

    CarchaPipeline carcha = new CarchaPipeline();
    StopWatch sw = new StopWatch();
    sw.start("executeStanfordAnnotators");
    if (args.length > 2 && args[2].equals("write")) {
        logger.info("Write Design Decision to file");
        carcha.writeAnnotations(inputDirectory, output);
    } else if (args.length > 2 && args[2].equals("sentence"))
        carcha.writeSentences(inputDirectory, output);
    else if (args.length > 2 && args[2].equals("sentence-annotator"))
        carcha.executeSentenceAnnotator(inputDirectory, output);
    else
        carcha.executeUIMAAnnotator(inputDirectory, output);
    sw.stop();
    logger.info(sw.prettyPrint());
}

From source file:org.tommy.stationery.moracle.core.client.load.StompWebSocketLoadTestClient.java

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

    // Modify host and port below to match wherever StompWebSocketServer.java is running!!
    // When StompWebSocketServer starts it prints the selected available

    String host = "localhost";
    if (args.length > 0) {
        host = args[0];/*from  w  w w .  j  ava 2 s .  co  m*/
    }

    int port = 59984;
    if (args.length > 1) {
        port = Integer.valueOf(args[1]);
    }

    String url = "http://" + host + ":" + port + "/home";
    logger.debug("Sending warm-up HTTP request to " + url);
    HttpStatus status = new RestTemplate().getForEntity(url, Void.class).getStatusCode();
    Assert.state(status == HttpStatus.OK);

    final CountDownLatch connectLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch subscribeLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch messageLatch = new CountDownLatch(NUMBER_OF_USERS);
    final CountDownLatch disconnectLatch = new CountDownLatch(NUMBER_OF_USERS);

    final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();

    Executor executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    org.eclipse.jetty.websocket.client.WebSocketClient jettyClient = new WebSocketClient(executor);
    JettyWebSocketClient webSocketClient = new JettyWebSocketClient(jettyClient);
    webSocketClient.start();

    HttpClient jettyHttpClient = new HttpClient();
    jettyHttpClient.setMaxConnectionsPerDestination(1000);
    jettyHttpClient.setExecutor(new QueuedThreadPool(1000));
    jettyHttpClient.start();

    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    transports.add(new JettyXhrTransport(jettyHttpClient));

    SockJsClient sockJsClient = new SockJsClient(transports);

    try {
        URI uri = new URI("ws://" + host + ":" + port + "/stomp");
        WebSocketStompClient stompClient = new WebSocketStompClient(uri, null, sockJsClient);
        stompClient.setMessageConverter(new StringMessageConverter());

        logger.debug("Connecting and subscribing " + NUMBER_OF_USERS + " users ");
        StopWatch stopWatch = new StopWatch("STOMP Broker Relay WebSocket Load Tests");
        stopWatch.start();

        List<ConsumerStompMessageHandler> consumers = new ArrayList<>();
        for (int i = 0; i < NUMBER_OF_USERS; i++) {
            consumers.add(new ConsumerStompMessageHandler(BROADCAST_MESSAGE_COUNT, connectLatch, subscribeLatch,
                    messageLatch, disconnectLatch, failure));
            stompClient.connect(consumers.get(i));
        }

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!connectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users connected, remaining: " + connectLatch.getCount());
        }
        if (!subscribeLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all users subscribed, remaining: " + subscribeLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        logger.debug("Broadcasting " + BROADCAST_MESSAGE_COUNT + " messages to " + NUMBER_OF_USERS + " users ");
        stopWatch.start();

        ProducerStompMessageHandler producer = new ProducerStompMessageHandler(BROADCAST_MESSAGE_COUNT,
                failure);
        stompClient.connect(producer);

        if (failure.get() != null) {
            throw new AssertionError("Test failed", failure.get());
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            for (ConsumerStompMessageHandler consumer : consumers) {
                if (consumer.messageCount.get() < consumer.expectedMessageCount) {
                    logger.debug(consumer);
                }
            }
        }
        if (!messageLatch.await(1 * 60 * 1000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all handlers received every message, remaining: " + messageLatch.getCount());
        }

        producer.session.disconnect();
        if (!disconnectLatch.await(5000, TimeUnit.MILLISECONDS)) {
            logger.info("Not all disconnects completed, remaining: " + disconnectLatch.getCount());
        }

        stopWatch.stop();
        logger.debug("Finished: " + stopWatch.getLastTaskTimeMillis() + " millis");

        System.out.println("\nPress any key to exit...");
        System.in.read();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        webSocketClient.stop();
        jettyHttpClient.stop();
    }

    logger.debug("Exiting");
    System.exit(0);
}

From source file:gda.device.detector.mythen.data.DataLoadAlgorithmExperiment.java

public static void main(String args[]) throws Exception {
    final File dataFile = TestUtils.getResourceAsFile(DataLoadAlgorithmExperiment.class, TEST_FILE);
    final String filename = dataFile.getAbsolutePath();

    StopWatch sw = new StopWatch(DataLoadAlgorithmExperiment.class.getSimpleName());

    Algorithm loadUsingCurrentAlgorithm = new Algorithm("loadUsingCurrentAlgorithm") {
        @Override/*from www .ja  v  a2 s.  co  m*/
        public void run() throws Exception {
            MythenDataFileUtils.readMythenProcessedDataFile(filename, false);
        }
    };

    Algorithm loadByUsingSplit = new Algorithm("loadByUsingSplit") {
        @Override
        public void run() throws Exception {
            MythenDataFileUtils.loadByUsingSplit(filename);
        }
    };

    Algorithm loadByUsingStreamTokenizer = new Algorithm("loadByUsingStreamTokenizer") {
        @Override
        public void run() throws Exception {
            MythenDataFileUtils.loadByUsingStreamTokenizer(filename, FileType.PROCESSED);
        }
    };

    Algorithm loadByReadingFileContentAndUsingSplit = new Algorithm("loadByReadingFileContentAndUsingSplit") {
        @Override
        public void run() throws Exception {
            MythenDataFileUtils.loadByReadingFileContentAndUsingSplit(filename);
        }
    };

    Algorithm loadByReadingFileContentAndUsingStreamTokenizer = new Algorithm(
            "loadByReadingFileContentAndUsingStreamTokenizer") {
        @Override
        public void run() throws Exception {
            MythenDataFileUtils.loadByReadingFileContentAndUsingStreamTokenizer(filename, FileType.PROCESSED);
        }
    };

    Algorithm[] algorithms = new Algorithm[] { loadUsingCurrentAlgorithm, loadByUsingSplit,
            loadByUsingStreamTokenizer, loadByReadingFileContentAndUsingSplit,
            loadByReadingFileContentAndUsingStreamTokenizer };

    for (Algorithm a : algorithms) {
        System.out.printf("Testing '%s' algorithm...\n", a.name);

        // warm-up
        for (int i = 0; i < 1000; i++) {
            a.run();
        }

        // timing
        sw.start(a.name);
        for (int i = 0; i < 1000; i++) {
            a.run();
        }
        sw.stop();
    }

    // display results
    System.out.println(sw.prettyPrint());
}

From source file:example.springdata.redis.sentinel.RedisSentinelApplication.java

private static void printBackFromErrorStateInfoIfStopWatchIsRunning(StopWatch stopWatch) {

    if (stopWatch.isRunning()) {
        stopWatch.stop();
        System.err.println("INFO: Recovered after: " + stopWatch.getLastTaskInfo().getTimeSeconds());
    }//from   ww  w  .ja  v a2 s  . co m
}

From source file:camel.Main.java

private static void testBatchOfMessages(final ProducerTemplate template, int number, int batch)
        throws Exception {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//ww w.  ja va  2 s  . c o m
    for (int i = 0; i < number; i++) {
        template.requestBody(String.valueOf(i));
    }
    stopWatch.stop();
    System.out.println(batch + ". Exchanged " + number + "  messages in " + stopWatch.getTotalTimeMillis());
}

From source file:com.home.ln_spring.ch4.mi.MethodReplacementExample.java

private static void displayInfo(ReplacementTarget target) {
    System.out.println(target.formatMessage("Hello World!"));

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("perfTest");

    for (int x = 0; x < 1000000; x++) {
        String out = target.formatMessage("foo");
    }//from   ww w.  ja  va  2s.c o  m
    stopWatch.stop();

    System.out.println("1000000 invocations took: " + stopWatch.getTotalTimeMillis() + " ms.");
}

From source file:com.home.ln_spring.ch4.mi.lookupDemo.java

public static void displayInfo(DemoBean bean) {
    MyHelper helper1 = bean.getMyHelper();
    MyHelper helper2 = bean.getMyHelper();

    System.out.println("Helper Instances the Same?: " + (helper1 == helper2));

    StopWatch stopWatch = new StopWatch();
    stopWatch.start("lookupDemo");
    for (int x = 0; x < 100000; x++) {
        MyHelper helper = bean.getMyHelper();
        helper.doSomethingHelpful();//from w w  w  .j a v  a2s .  com
    }
    stopWatch.stop();
    System.out.println("100000 gets took " + stopWatch.getTotalTimeMillis() + " ms");
}

From source file:com.cedarsoft.history.core.GlazedPerformanceTest.java

private static StopWatch checkPerformance(@Nonnull List<String> list) {
    StopWatch stopWatch = new StopWatch();

    stopWatch.start("adding to " + list.getClass().getName());
    for (int i = 0; i < 100000; i++) {
        list.add(String.valueOf(i));
    }/*from   ww  w. j a va2s .  c o  m*/
    stopWatch.stop();

    stopWatch.start("iterating through " + list.getClass().getName());
    for (String currentEntry : list) {
        assertNotNull(currentEntry);
    }
    stopWatch.stop();

    assertNotNull(stopWatch);
    return stopWatch;
}

From source file:com.auditbucket.client.Importer.java

private static long endProcess(StopWatch watch, long rows) {
    watch.stop();
    double mins = watch.getTotalTimeSeconds() / 60;
    logger.info("Processed {} rows in {} secs. rpm = {}", rows, f.format(watch.getTotalTimeSeconds()),
            f.format(rows / mins));//w w w.jav  a  2 s. co  m
    return rows;
}