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

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

Introduction

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

Prototype

@CheckReturnValue
public long elapsed(TimeUnit desiredUnit) 

Source Link

Document

Returns the current elapsed time shown on this stopwatch, expressed in the desired time unit, with any fraction rounded down.

Usage

From source file:qa.qcri.nadeef.core.pipeline.UpdateExecutor.java

public void run() {
    Stopwatch sw = Stopwatch.createStarted();
    updateFlow.reset();//from   w ww  .j a v a  2  s  .co  m
    updateFlow.start();
    updateFlow.waitUntilFinish();

    PerfReport.appendMetric(PerfReport.Metric.EQTime, sw.elapsed(TimeUnit.MILLISECONDS));
    sw.stop();
}

From source file:org.apache.geode.internal.process.lang.AvailablePid.java

/**
 * Returns randomly unused pid between {@code lowerBound} (inclusive) and {@code upperBound}
 * (inclusive)./*from  w  w w.j  ava  2  s . c o  m*/
 */
public int findAvailablePid() throws TimeoutException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    int pid = random();
    while (isProcessAlive(pid)) {
        if (stopwatch.elapsed(MILLISECONDS) > timeoutMillis) {
            throw new TimeoutException("Failed to find available pid within " + timeoutMillis + " millis.");
        }
        pid = random();
    }
    return pid;
}

From source file:com.twitter.distributedlog.limiter.ChainedRequestLimiter.java

public void apply(Request request) throws OverCapacityException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {/* w  ww.  j a  va  2  s . com*/
        for (RequestLimiter<Request> limiter : limiters) {
            limiter.apply(request);
        }
    } finally {
        applyTime.registerSuccessfulEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS));
    }
}

From source file:com.abiquo.apiclient.TemplatesApi.java

public VirtualMachineTemplateDto waitWhileInProgress(final VirtualMachineTemplateDto vmt,
        final int pollInterval, final int maxWait, final TimeUnit timeUnit) {
    Stopwatch watch = Stopwatch.createStarted();
    while (watch.elapsed(timeUnit) < maxWait) {
        VirtualMachineTemplateDto refreshed = client.refresh(vmt);
        if (!VMTemplateState.IN_PROGRESS.equals(refreshed.getState())) {
            return refreshed;
        }//ww w.j  a va  2s.  c  om

        Uninterruptibles.sleepUninterruptibly(pollInterval, timeUnit);
    }

    throw new RuntimeException(
            "Virtual machine template did not reach the desired state in the configured timeout");
}

From source file:org.apache.distributedlog.limiter.ChainedRequestLimiter.java

public void apply(Request request) throws OverCapacityException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {// www. j  av  a  2s .c om
        for (RequestLimiter<Request> limiter : limiters) {
            limiter.apply(request);
        }
    } finally {
        applyTime.registerSuccessfulEvent(stopwatch.elapsed(TimeUnit.MICROSECONDS), TimeUnit.MICROSECONDS);
    }
}

From source file:org.opendaylight.controller.cluster.datastore.IntegrationTestKit.java

public void waitForMembersUp(String... otherMembers) {
    Set<String> otherMembersSet = Sets.newHashSet(otherMembers);
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
        CurrentClusterState state = Cluster.get(getSystem()).state();
        for (Member m : state.getMembers()) {
            if (m.status() == MemberStatus.up() && otherMembersSet.remove(m.getRoles().iterator().next())
                    && otherMembersSet.isEmpty()) {
                return;
            }//from ww  w  .j a v  a 2s  . co  m
        }

        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    }

    fail("Member(s) " + otherMembersSet + " are not Up");
}

From source file:com.minestellar.core.MinestellarCore.java

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
    Stopwatch stopwatch = Stopwatch.createStarted();

    MinestellarCore.proxy.postInit(event);

    log.info("PostInitialization Completed in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");
}

From source file:io.druid.segment.LoggingProgressIndicator.java

@Override
public void stopSection(String section) {
    Stopwatch sectionWatch = sections.remove(section);
    if (sectionWatch == null) {
        throw new ISE("[%s]: Cannot stop progress tracker for [%s]. Nothing started.", progressName, section);
    }/*from  ww w.  j  a v a 2 s .  com*/
    long time = sectionWatch.elapsed(TimeUnit.MILLISECONDS);
    sectionWatch.stop();

    log.info("[%s]: [%s] has completed. Elapsed time: [%,d] millis", progressName, section, time);
}

From source file:com.teradata.tempto.internal.hadoop.hdfs.DefaultHdfsDataSourceWriter.java

private boolean isDataUpToDate(String dataSourcePath, DataSource dataSource) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    Optional<String> storedRevisionMarker = revisionStorage.get(dataSourcePath);
    LOGGER.debug("revisionMarker.get(\"{}\") took {}ms", dataSourcePath,
            stopwatch.elapsed(TimeUnit.MILLISECONDS));
    if (storedRevisionMarker.isPresent()) {
        if (storedRevisionMarker.get().equals(dataSource.revisionMarker())) {
            LOGGER.debug("Directory {} ({}) already exists, skipping generation of data", dataSourcePath,
                    storedRevisionMarker.get());
            return true;
        } else {//from ww w.j a  v  a 2  s .c  o  m
            LOGGER.info(
                    "Directory {} ({}) already exists, but has different revision marker than expected: {}, so data will be regenerated",
                    dataSourcePath, storedRevisionMarker.get(), dataSource.revisionMarker());
        }
    }
    return false;
}

From source file:net.sf.lucis.core.LucisQuery.java

public static <T> LucisQuery<Page<T>> page(final Query query, final Filter filter, final Sort sort,
        final DocMapper<T> mapper, final int first, final int pageSize, final Highlight highlight) {
    return new LucisQuery<Page<T>>() {
        public Page<T> perform(LucisSearcher searcher) {
            Stopwatch w = Stopwatch.createStarted();
            int total = first + pageSize;
            Query rewritten = searcher.rewrite(query);
            TopDocs docs = getTopDocs(searcher, rewritten, filter, sort, total);
            if (docs.totalHits > 0) {
                int n = Math.min(total, docs.scoreDocs.length);
                float score = docs.getMaxScore();
                if (n > first) {
                    final List<T> items = Lists.newArrayListWithCapacity(n - first);
                    HighlightedQuery highlighted = MoreObjects.firstNonNull(highlight, Highlight.no())
                            .highlight(rewritten);
                    for (int i = first; i < n; i++) {
                        ScoreDoc sd = docs.scoreDocs[i];
                        Document doc = searcher.doc(sd.doc);
                        T item = mapper.map(sd.doc, score, doc, highlighted.getFragments(doc));
                        items.add(item);
                    }/*from   ww  w. java 2  s  .c  o  m*/
                    return new Page<T>(docs.totalHits, score, w.elapsed(TimeUnit.MILLISECONDS), first, items);
                } else {
                    return new Page<T>(docs.totalHits, score, w.elapsed(TimeUnit.MILLISECONDS), first, null);
                }
            } else {
                return new Page<T>(docs.totalHits, 0.0f, w.elapsed(TimeUnit.MILLISECONDS), first, null);
            }
        }
    };
}