List of usage examples for com.google.common.base Stopwatch Stopwatch
Stopwatch()
From source file:org.sonatype.nexus.maven.staging.ProgressMonitorImpl.java
public ProgressMonitorImpl() { this.logger = LoggerFactory.getLogger(getClass()); this.stopwatch = new Stopwatch(); }
From source file:com.dvdprime.server.mobile.servlet.GCMServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse res) { Stopwatch sw = new Stopwatch().start(); logger.log(Level.INFO, "Start GCM: {0}ms", sw.elapsed(TimeUnit.MILLISECONDS)); Notification.getNotificationList(); logger.log(Level.INFO, "End GCM: {0}ms", sw.elapsed(TimeUnit.MILLISECONDS)); }
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();//from w w w .j a v a 2s.c om OrcsTypesIndex index = null; try { index = createIndex(); } finally { logger.trace("Created OrcsTypesIndex in [%s]", Lib.getElapseString(stopwatch.elapsedMillis())); stopwatch.stop(); } return index; }
From source file:com.springer.omelet.driver.DriverUtility.java
/*** * Generic waitFor Function which waits for condition to be successful else * return null/*from ww w .ja v a 2 s .co m*/ * * @param expectedCondition * :ExpectedCondition<T> * @param driver * :WebDriver * @param timeout * in seconds * @return <T> or null */ public static <T> T waitFor(ExpectedCondition<T> expectedCondition, WebDriver driver, int timeOutInSeconds) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { T returnValue = new WebDriverWait(driver, timeOutInSeconds).pollingEvery(500, TimeUnit.MILLISECONDS) .until(expectedCondition); return returnValue; } catch (TimeoutException e) { LOGGER.error(e); return null; } finally { driver.manage().timeouts().implicitlyWait(Driver.getBrowserConf().getDriverTimeOut(), TimeUnit.SECONDS); stopwatch.stop(); LOGGER.debug("Time Taken for waitFor method for Expected Condition is:" + stopwatch.elapsedTime(TimeUnit.SECONDS)); } }
From source file:co.cask.cdap.test.messaging.MessagingApp.java
/** * Fetch and block until it get a message. *//*w ww. j a va2 s.c o m*/ private static Message fetchMessage(MessageFetcher fetcher, String namespace, String topic, @Nullable String afterMessageId, long timeout, TimeUnit unit) throws Exception { CloseableIterator<Message> iterator = fetcher.fetch(namespace, topic, 1, afterMessageId); Stopwatch stopwatch = new Stopwatch().start(); try { while (!iterator.hasNext() && stopwatch.elapsedTime(unit) < timeout) { TimeUnit.MILLISECONDS.sleep(100); iterator = fetcher.fetch(namespace, topic, 1, afterMessageId); } if (!iterator.hasNext()) { throw new TimeoutException("Failed to get any messages from " + topic + " in " + timeout + " " + unit.name().toLowerCase()); } // The payload contains the message to publish in next step return iterator.next(); } finally { iterator.close(); } }
From source file:algores.holonet.core.Progress.java
public Progress(String description, final long iterations) { this.description = description; this.stopwatch = new Stopwatch(); this.iterations = iterations; long divider = 1; while (divider * WIDTH * WIDTH < iterations) { divider *= 2;//from w w w . ja va 2 s . c o m } this.divider = divider; this.silent = iterations <= SILENT; }
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();/*from w w w . j a va2s .c o m*/ 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(); 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.caleydo.view.tourguide.internal.compute.ComputeAllOfJob.java
@Override protected IStatus run(IProgressMonitor monitor) { Stopwatch w = new Stopwatch().start(); log.info("compute the data for datadomain: %s", query.getLabel()); progress(0.0f, "Preparing Data"); boolean creating = !query.isInitialized(); List<AScoreRow> data = query.getOrCreate(); BitSet mask = query.getRawMask(); System.out.println("done in " + w); progress(0.0f, "Computing Scores"); IStatus result = runImpl(monitor, data, mask); if (creating) EventPublisher.trigger(new InitialScoreQueryReadyEvent(query).to(receiver)); else//from ww w .ja va 2 s. c om EventPublisher.trigger(new ScoreQueryReadyEvent(null).to(receiver)); return result; }
From source file:com.Grande.GSM.BACCWS_WAR.WS.REST.EOS.SNMPEndpoint.java
@GET public String fetchModemByMac(@QueryParam("mac") final String strMac) { // <editor-fold defaultstate="collapsed" desc="****** Method vars ******"> final Stopwatch timer = new Stopwatch(); final QueryResponse qRes = new QueryResponse(); String strResponse = null;/*from ww w .j a v a 2s. c o m*/ Map mapModem = null; // start the execution timer timer.start(); // </editor-fold> try { qRes.vSetNode(java.net.InetAddress.getLocalHost().getHostName()); mapModem = this.bacEJB.mapFetchModemByMac(strMac); qRes.vSetSuccessFlag(true); qRes.vAddResult(mapModem); } catch (Exception e) { // <editor-fold defaultstate="collapsed" desc="****** Handle failures ******"> qRes.vSetSuccessFlag(false); // handle NPE differently since getMessage() is null if (e instanceof NullPointerException) { qRes.vSetMessage("NPE occured when serializing result to JSON! " + "File: " + e.getStackTrace()[0].getFileName() + ", " + "Method: " + e.getStackTrace()[0].getMethodName() + ", " + "Line: " + e.getStackTrace()[0].getLineNumber()); } else { qRes.vSetMessage(e.getMessage()); } SimpleLogging.vLogException(this.strThreadId, e); // </editor-fold> } finally { // <editor-fold defaultstate="collapsed" desc="****** Stop timer, convert response to JSON ******"> timer.stop(); qRes.vSetRoundTrip(String.valueOf(timer.elapsedTime(TimeUnit.SECONDS)) + "." + String.valueOf(timer.elapsedTime(TimeUnit.MILLISECONDS))); strResponse = this.trnBN.strQueryResponseToJSON(qRes); SimpleLogging.vLogEvent(this.strThreadId + "|" + qRes.strGetRoundTripInSeconds() + "s", "retrieved " + qRes.intGetDataCount() + " records"); // </editor-fold> } return strResponse; }
From source file:com.Grande.GSM.BACCWS_WAR.WS.REST.EOS.DHCPEndpoint.java
@GET public String fetchDHCPInfoByMAC(@QueryParam("mac") final String strMac) { // <editor-fold defaultstate="collapsed" desc="****** Method vars ******"> final Stopwatch timer = new Stopwatch(); final QueryResponse qRes = new QueryResponse(); String strResponse = null;//from ww w .j a v a 2s .c o m Map mapModem = null; // start the execution timer timer.start(); // </editor-fold> try { qRes.vSetNode(java.net.InetAddress.getLocalHost().getHostName()); mapModem = this.bacEJB.mapFetchDHCPByMac(strMac); qRes.vSetSuccessFlag(true); qRes.vAddResult(mapModem); } catch (Exception e) { // <editor-fold defaultstate="collapsed" desc="****** Handle failures ******"> qRes.vSetSuccessFlag(false); // handle NPE differently since getMessage() is null if (e instanceof NullPointerException) { qRes.vSetMessage("NPE occured when serializing result to JSON! " + "File: " + e.getStackTrace()[0].getFileName() + ", " + "Method: " + e.getStackTrace()[0].getMethodName() + ", " + "Line: " + e.getStackTrace()[0].getLineNumber()); } else { qRes.vSetMessage(e.getMessage()); } SimpleLogging.vLogException(this.strThreadId, e); // </editor-fold> } finally { // <editor-fold defaultstate="collapsed" desc="****** Stop timer, convert response to JSON ******"> timer.stop(); qRes.vSetRoundTrip(String.valueOf(timer.elapsedTime(TimeUnit.SECONDS)) + "." + String.valueOf(timer.elapsedTime(TimeUnit.MILLISECONDS))); strResponse = this.trnBN.strQueryResponseToJSON(qRes); SimpleLogging.vLogEvent(this.strThreadId + "|" + qRes.strGetRoundTripInSeconds() + "s", "retrieved " + qRes.intGetDataCount() + " records"); // </editor-fold> } return strResponse; }