Example usage for com.google.common.base Stopwatch start

List of usage examples for com.google.common.base Stopwatch start

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch start.

Prototype

public Stopwatch start() 

Source Link

Document

Starts the stopwatch.

Usage

From source file:org.eclipse.osee.orcs.core.internal.types.impl.CreateOrcsTypesIndexCallable.java

@Override
public OrcsTypesIndex call() throws Exception {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    OrcsTypesIndex index = null;//ww  w.  ja  v  a2 s.  co m
    try {
        index = createIndex();
    } finally {
        logger.trace("Created OrcsTypesIndex in [%s]", Lib.getElapseString(stopwatch.elapsedMillis()));
        stopwatch.stop();
    }
    return index;
}

From source file:pro.foundev.examples.spark_streaming.java.interactive.smartconsumer.DeduplicatingRabbitMQConsumer.java

public void run() {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost");
    try {//w  w  w . jav  a 2 s  .c o  m
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(EXCHANGE_NAME, true, consumer);
        Set<String> messages = new HashSet<>();
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.start();
        while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            String message = new String(delivery.getBody());
            messages.add(message);

            if (stopwatch.elapsed(TimeUnit.MILLISECONDS) > 1000l) {
                System.out.println("it should be safe to submit messages now");
                for (String m : messages) {
                    //notifying user interface
                    System.out.println(m);
                }
                stopwatch.stop();
                stopwatch.reset();
                messages.clear();
            }
            if (messages.size() > 100000000) {
                System.out.println("save off to file system and clear before we lose everything");
                messages.clear();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.omid.tso.MonitoringContextImpl.java

public void timerStart(String name) {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    timers.put(name, stopwatch);
}

From source file:org.apache.drill.exec.physical.impl.sort.SortTemplate.java

@Override
public void sort(SelectionVector4 vector4, VectorContainer container) {
    Stopwatch watch = new Stopwatch();
    watch.start();
    QuickSort qs = new QuickSort();
    qs.sort(this, 0, vector4.getTotalCount());
    logger.debug("Took {} us to sort {} records", watch.elapsed(TimeUnit.MICROSECONDS),
            vector4.getTotalCount());/* w  w  w.jav a 2s . c o  m*/
}

From source file:org.apache.tephra.visibility.DefaultFenceWait.java

@Override
public void await(long timeout, TimeUnit timeUnit)
        throws TransactionFailureException, InterruptedException, TimeoutException {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    long sleepTimeMicros = timeUnit.toMicros(timeout) / 10;
    // Have sleep time to be within 1 microsecond and 500 milliseconds
    sleepTimeMicros = Math.max(Math.min(sleepTimeMicros, 500 * 1000), 1);
    while (stopwatch.elapsedTime(timeUnit) < timeout) {
        txContext.start();//from w  w w.ja va2  s  .  c  o  m
        try {
            txContext.finish();
            return;
        } catch (TransactionFailureException e) {
            LOG.error("Got exception waiting for fence. Sleeping for {} microseconds", sleepTimeMicros, e);
            txContext.abort();
            TimeUnit.MICROSECONDS.sleep(sleepTimeMicros);
        }
    }
    throw new TimeoutException("Timeout waiting for fence");
}

From source file:org.apache.drill.exec.physical.impl.xsort.SingleBatchSorterTemplate.java

@Override
public void sort(SelectionVector2 vector2) {
    QuickSort qs = new QuickSort();
    Stopwatch watch = new Stopwatch();
    watch.start();
    if (vector2.getCount() > 0) {
        qs.sort(this, 0, vector2.getCount());
    }/*  w w w . j a v  a2 s  .  c  o  m*/
    logger.debug("Took {} us to sort {} records", watch.elapsed(TimeUnit.MICROSECONDS), vector2.getCount());
}

From source file:de.blizzy.documentr.access.BCryptPasswordEncoder.java

@Override
public String encodePassword(String rawPass, Object salt) {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    String encPass = encoder.encode(rawPass);
    stopwatch.stop();//from  w w  w. ja  v  a2 s . com
    if (log.isTraceEnabled()) {
        log.trace("time taken to encode password: {} ms", stopwatch.elapsedMillis()); //$NON-NLS-1$
    }
    return encPass;
}

From source file:de.blizzy.documentr.access.BCryptPasswordEncoder.java

@Override
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    boolean valid = encoder.matches(rawPass, encPass);
    stopwatch.stop();/*from www  .  j  a  v a  2  s  .co  m*/
    if (log.isTraceEnabled()) {
        log.trace("time taken to verify password: {} ms", stopwatch.elapsedMillis()); //$NON-NLS-1$
    }
    return valid;
}

From source file:co.cask.tigon.internal.app.queue.TimeTrackingQueueReader.java

@Override
public final InputDatum<T> dequeue(long timeout, TimeUnit timeoutUnit)
        throws IOException, InterruptedException {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();
    long sleepNano = computeSleepNano(timeout, timeoutUnit);
    long timeoutNano = timeoutUnit.toNanos(timeout);

    InputDatum<T> result = tryDequeue(timeout, timeoutUnit);
    while (!result.needProcess()) {
        if (timeoutNano <= 0) {
            break;
        }//from   w w w. j a v  a 2 s . c om

        long elapsedNano = stopwatch.elapsedTime(TimeUnit.NANOSECONDS);
        if (elapsedNano + sleepNano >= timeoutNano) {
            break;
        }
        TimeUnit.NANOSECONDS.sleep(sleepNano);
        result = tryDequeue(timeoutNano - elapsedNano, TimeUnit.NANOSECONDS);
    }
    return result;
}

From source file:org.openqa.selenium.internal.selenesedriver.ScriptExecutor.java

@SuppressWarnings({ "unchecked" })
private <T> T evaluateScript(String script) {
    Stopwatch stopWatch = new Stopwatch();
    stopWatch.start();
    String result = selenium.getEval(script);
    stopWatch.stop();//  w  w w .  j  av  a2  s .  c o  m

    Response response = new JsonToBeanConverter().convert(Response.class, result);
    new ErrorHandler().throwIfResponseFailed(response, stopWatch.elapsed(MILLISECONDS));
    return (T) response.getValue();
}