Example usage for org.apache.commons.lang.time StopWatch StopWatch

List of usage examples for org.apache.commons.lang.time StopWatch StopWatch

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Constructor.

Usage

From source file:org.eurekastreams.server.service.tasks.GadgetDefinitionReindexTask.java

/**
 * Constructor needed for injecting the correct mapper.
 *
 * @param inGadgetDefMapper/*  w  w w  . j  a  va  2  s .  c o  m*/
 *            - instance of the GadgetDefinitionMapper that this task will use to refresh user counts.
 * @param inPopulator
 *            the gadget definition populator.
 */
public GadgetDefinitionReindexTask(final GadgetDefinitionMapper inGadgetDefMapper,
        final GadgetDefinitionPopulator inPopulator) {
    gadgetDefMapper = inGadgetDefMapper;
    stopWatch = new StopWatch();
    populator = inPopulator;
}

From source file:org.eurekastreams.server.service.tasks.PluginDefinitionMetaUpdateTask.java

/**
 * Constructor needed for injecting the correct mapper.
 * //  w  w  w .j a va 2  s .c o m
 * @param inPluginDefMapper
 *            - instance of the GadgetDefinitionMapper that this task will use to refresh user counts.
 * @param inPopulator
 *            the Plugin definition populator.
 */
public PluginDefinitionMetaUpdateTask(final PluginDefinitionMapper inPluginDefMapper,
        final PluginDefinitionPopulator inPopulator) {
    pluginDefMapper = inPluginDefMapper;
    stopWatch = new StopWatch();
    populator = inPopulator;
}

From source file:org.examproject.batch.core.WorkerFacade.java

public void work() {
    LOG.debug("called.");
    try {/*from w  w  w .j ava  2s  .  c  o  m*/
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> run a job begin.");

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

        // create the jobparameter.
        JobParameter parameter = new JobParameter(new Date());

        Map<String, JobParameter> map = new HashMap<String, JobParameter>();
        map.put("date", parameter);

        // run the job.
        jobLauncher.run(job, new JobParameters(map));

        stopWatch.stop();
        LOG.info("execute time: " + stopWatch.getTime() + " msec");

        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< run a job end.");

    } catch (Exception e) {
        LOG.fatal("fatal: " + e.getMessage());
    }
}

From source file:org.examproject.task.core.Facade.java

@Override
public void run() {
    LOG.debug("called.");

    try {//from  w w  w .  ja v a2s . c  o m
        LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> facade begin.");
        LOG.info("processing at " + new Date());

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

        // initialize the content object for this run.
        init();

        // set the param for the worker object of the list.
        List<Runnable> workerList = new CopyOnWriteArrayList<Runnable>();
        for (int i = 0; i < contentList.size(); i++) {

            // create the beans of result for the worker. 
            DynaBean result = (DynaBean) resultBeanFactory.create();

            // create the beans of state for the worker.
            DynaBean state = (DynaBean) stateBeanFactory.create();

            // create the beans of argument for the worker.
            DynaBean argument = (DynaBean) argumentBeanFactory.create();

            // build the parameter for the worker.
            state.set("result", result);
            state.set("param", getParam());
            argument.set("job", jobClosure);
            argument.set("state", state);
            argument.set("count", counter.incrementAndGet());

            // set the argument object for the worker.
            Runnable worker = (Runnable) context.getBean(workerBeanId, argument);

            // add the worker to the list.
            workerList.add(worker);
        }

        // run the all of the worker object.
        for (int i = 0; i < workerList.size(); i++) {
            executor.execute(workerList.get(i));
        }

        stopWatch.stop();

        LOG.info("execute time: " + stopWatch.getTime() + " msec");
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade end.");

    } catch (Exception e) {
        LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< facade error.");
        LOG.error("exception occurred. " + e.getMessage());

        // TODO: final strategy of the error!
        throw new RuntimeException(e);
    }
}

From source file:org.forgerock.openam.cts.reaper.CTSReaper.java

/**
 * Performs the query against the directory by selecting the Token IDs for all Tokens
 * that have expired. These Token IDs are then scheduled for deletion. The task will
 * not complete until all of the delete operations have returned.
 *//* www  . j  ava 2s . c  om*/
public void run() {
    // Timers for debugging
    StopWatch query = new StopWatch();
    StopWatch waiting = new StopWatch();

    // Latches will track each page of results
    List<CountDownLatch> latches = new ArrayList<CountDownLatch>();

    // Create the query against the directory
    calendar.setTimeInMillis(System.currentTimeMillis());
    Filter expired = factory.createFilter().and().beforeDate(calendar).build();
    QueryBuilder queryBuilder = factory.createInstance().withFilter(expired)
            .returnTheseAttributes(CoreTokenField.TOKEN_ID);
    QueryPageIterator iterator = new QueryPageIterator(queryBuilder, config.getCleanupPageSize());

    query.start();
    long total = 0;

    try {
        // Iterate over the result pages
        while (iterator.hasNext()) {
            Collection<Entry> entries = iterator.next();
            total += entries.size();

            // If the thread has been interrupted, exit all processing.
            if (Thread.interrupted()) {
                return;
            }

            // Latch will track the deletions of the page
            CountDownLatch latch = new CountDownLatch(entries.size());
            DeleteComplete complete = new DeleteComplete(latch);
            latches.add(latch);

            // Delete the tokens.
            try {
                tokenDeletion.deleteBatch(entries, complete);
            } catch (ErrorResultException e) {
                debug.error("Failed to get a connection, will retry later", e);
                return;
            }

            if (debug.messageEnabled()) {
                debug.message(MessageFormat
                        .format(CoreTokenConstants.DEBUG_HEADER + "Reaper: Queried {0} Tokens", total));
            }
        }

        query.stop();
        waiting.start();

        if (debug.messageEnabled()) {
            debug.message(MessageFormat.format(
                    CoreTokenConstants.DEBUG_HEADER + "Reaper: Expired Token Query Time: {0}ms",
                    query.getTime()));
        }

        // Wait stage
        for (CountDownLatch latch : latches) {
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        waiting.stop();

        if (debug.messageEnabled()) {
            debug.message(MessageFormat.format(
                    CoreTokenConstants.DEBUG_HEADER + "Reaper: Worker threads Time: {0}ms", waiting.getTime()));
        }
    } finally {
        // Once all latches are complete, close the TokenDeletion
        IOUtils.closeIfNotNull(tokenDeletion);
    }
}

From source file:org.grouter.common.logging.MethodLogger.java

private Object log(ProceedingJoinPoint joinPoint) throws Throwable {
    log.info("Starting stopwatch");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from  ww w  .  j a  v  a 2 s .  c  om

    Object[] args = joinPoint.getArgs();
    // E.g. public abstract org.grouter.domain.entities.User org.grouter.domain.service.UserService.findById(java.lang.Long)
    String name = joinPoint.getSignature().toLongString();
    StringBuffer sb = new StringBuffer(name + " called with: [");
    for (int i = 0; i < args.length; i++) {
        Object o = args[i];
        sb.append(o);
        sb.append((i == args.length - 1) ? "]" : ", ");
    }
    log.info(sb);
    Object retVal = joinPoint.proceed();
    stopWatch.stop();

    log.info(" return: " + retVal + ", time: " + stopWatch.getTime());
    return retVal;
}

From source file:org.hippoecm.hst.demo.components.ExampleProfilingHstComponentAspect.java

public Object profile(ProceedingJoinPoint pjp) throws Throwable {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from  w  ww .jav  a2s  .  c  o m*/

    final HstResponse hstResponse = (HstResponse) pjp.getArgs()[1];
    final String compNamespace = hstResponse.getNamespace();

    Object retVal = pjp.proceed();

    stopWatch.stop();
    log.info("Example profiling for '{}': {}ms.", compNamespace, stopWatch.getTime());

    return retVal;
}

From source file:org.hydracache.concurrent.SimpleResultFutureTest.java

@Test
public void shouldGetBeAbleToTimeout() throws Exception {
    SimpleResultFuture<Object> responses = new SimpleResultFuture<Object>();

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*  w  w w .j  a  v a  2  s  .  c  om*/

    results = responses.get(TIMEOUT, TimeUnit.MILLISECONDS);

    stopWatch.stop();

    assertTrue("Timeout period is too short", stopWatch.getTime() > TIMEOUT);

    assertNotNull("Results should not be null", results);
    assertTrue("Results should be empty", results.isEmpty());
}

From source file:org.hydracache.concurrent.SimpleResultFutureTest.java

private void concurrentGet(final SimpleResultFuture<Object> future) {
    new Thread() {
        @Override/*from w w  w  .  j  a v  a  2s . c  o  m*/
        public void run() {
            try {
                StopWatch stopWatch = new StopWatch();
                stopWatch.start();
                results = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
                stopWatch.stop();
                System.out.println("Took [" + stopWatch.getTime() + "]ms to get concurrently");

                assertTrue("Get took too long in a ideal case", stopWatch.getTime() < TIMEOUT);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}

From source file:org.hydracache.server.BasicIntegrationTest.java

@Test
public void testBasicOperations() throws Exception {
    StopWatch stopwatch = new StopWatch();

    stopwatch.start();//from ww w . java2 s.  c  o m

    String testKey = createTestKey();

    assertPutAndGet(testKey);

    assertDeletion(testKey);

    stopwatch.stop();

    log.info("Took [" + stopwatch.getTime() + "]ms to perform a put and get pair + one deletion");
}