/** @see #makeTimeString(long, boolean) */ public static String makeTimeStringExact(long t) { return makeTimeString(t, false); } /** @see #makeTimeString(long, boolean) */
/** @see #makeTimeString(long, boolean) */ public static String makeTimeStringRounded(long t) { return makeTimeString(t, true); } /** @see #makeTimeString(long, boolean) */
/** @see #makeTimeString(long, boolean) */ public static String makeTimeStringRoundedSince(long utc) { return makeTimeString(System.currentTimeMillis() - utc, true); } /** @see #makeTimeString(long, boolean) */
public HttpPollValue(HttpResponse response, long startTime) { this.response = response; this.startTime = startTime; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().getContentLength(); durationMillisOfFirstResponse = System.currentTimeMillis() - startTime; ByteStreams.copy(response.getEntity().getContent(), out); content = out.toByteArray(); response.getEntity().getContentLength(); durationMillisOfFullContent = System.currentTimeMillis() - startTime; if (log.isTraceEnabled()) log.trace("HttpPollValue latency "+Time.makeTimeString(durationMillisOfFirstResponse)+" / "+Time.makeTimeString(durationMillisOfFullContent)+", content size "+content.length); } catch (IOException e) { throw Throwables.propagate(e); } }
/** * This method must only be used for testing. If required in production, then revisit implementation! */ @VisibleForTesting public void waitForWriteCompleted(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { // Every time we finish writing, we increment a counter. We note the current val, and then // wait until we can guarantee that a complete additional write has been done. Not sufficient // to wait for `writeCount > origWriteCount` because we might have read the value when it was // almost finished a write. long startTime = System.currentTimeMillis(); long maxEndtime = (timeout > 0) ? (startTime + unit.toMillis(timeout)) : Long.MAX_VALUE; long origModCount = modCount.get(); while (true) { if (modCount.get() > (origModCount+1)) { return; } else if (requireWrite.get() != null) { // must continue waiting for mods+1 } else if (executing.get()) { // must wait for either this invocation to complete, or mods+1 (because might have already updated) } else { return; } if (System.currentTimeMillis() > maxEndtime) { throw new TimeoutException("Timeout waiting for pending complete of rebind-periodic-delta, after "+Time.makeTimeString(timeout, unit)); } Thread.sleep(10); } }
/** * This method must only be used for testing. If required in production, then revisit implementation! */ @VisibleForTesting public void waitForPendingComplete(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { // Every time we finish writing, we increment a counter. We note the current val, and then // wait until we can guarantee that a complete additional write has been done. Not sufficient // to wait for `writeCount > origWriteCount` because we might have read the value when almost // finished a write. long startTime = System.currentTimeMillis(); long maxEndtime = (timeout > 0) ? (startTime + unit.toMillis(timeout)) : Long.MAX_VALUE; long origWriteCount = writeCount.get(); while (true) { if (!isActive()) { return; // no pending activity; } else if (writeCount.get() > (origWriteCount+1)) { return; } if (System.currentTimeMillis() > maxEndtime) { throw new TimeoutException("Timeout waiting for pending complete of rebind-periodic-delta, after "+Time.makeTimeString(timeout, unit)); } Thread.sleep(1); } }
String msg = String.format("%s: unsatisfied during iteration %s %s", description, iterations, (iterationLimit > 0 ? "(max "+iterationLimit+" attempts)" : "") + (endTime > 0 ? "("+Time.makeTimeString(endTime - System.currentTimeMillis())+" remaining)" : "")); if (iterations == 1) { log.debug(msg); if (System.currentTimeMillis() > endTime) { if (log.isDebugEnabled()) log.debug("{}: condition not satisfied and deadline {} passed", description, Time.makeTimeString(endTime - System.currentTimeMillis())); if (rethrowException && lastError != null) { log.error("{}: error caught checking condition: {}", description, lastError.getMessage());
new Object[] {Time.makeTimeString(timeout), context, command, stdout, stderr}); String msg = String.format("Command timed out after %s: %s (details logged)", Time.makeTimeString(timeout), command); throw new IllegalStateException(msg);