@Override public long getTime() { return Time.monotonicNow(); } }
RetryInfo(long delay, RetryAction action, long expectedFailoverCount, Exception failException) { this.delay = delay; this.retryTime = Time.monotonicNow() + delay; this.action = action; this.expectedFailoverCount = expectedFailoverCount; this.failException = failException; }
/** * Current time from some arbitrary time base in the past, counting in * milliseconds, and not affected by settimeofday or similar system clock * changes. This is appropriate to use when computing how much longer to * wait for an interval to expire. * @return a monotonic clock that counts in milliseconds. */ public long monotonicNow() { return Time.monotonicNow(); }
public LoadBalancingKMSClientProvider(URI providerUri, KMSClientProvider[] providers, Configuration conf) { this(providerUri, providers, Time.monotonicNow(), conf); }
synchronized private boolean isExpired() { return Time.monotonicNow() - lastUpdateTime > timeout; }
@VisibleForTesting long now() { return Time.monotonicNow(); }
/** Is the queue empty for more than the given time in millisecond? */ boolean isEmpty(long time) { return Time.monotonicNow() - emptyStartTime.get() > time && queue.isEmpty(); }
void checkEmpty() { if (queue.isEmpty()) { emptyStartTime.set(Time.monotonicNow()); } } }
/** Check to see if a command needs to be executed and execute if needed. */ protected void run() throws IOException { if (lastTime + interval > Time.monotonicNow()) { return; } exitCode = 0; // reset for next run if (Shell.MAC) { System.setProperty("jdk.lang.Process.launchMechanism", "POSIX_SPAWN"); } runCommand(); }
@Override public void login() throws LoginException { synchronized(getSubjectLock()) { MutableRate metric = metrics.loginFailure; long start = Time.monotonicNow(); try { super.login(); isLoggedIn.set(true); metric = metrics.loginSuccess; } finally { metric.add(Time.monotonicNow() - start); } } }
synchronized private void loadFullGroupMap() throws IOException { BiMap<Integer, String> gMap = HashBiMap.create(); if (OS.startsWith("Mac")) { updateMapInternal(gMap, "group", MAC_GET_ALL_GROUPS_CMD, "\\s+", staticMapping.gidMapping); } else { updateMapInternal(gMap, "group", GET_ALL_GROUPS_CMD, ":", staticMapping.gidMapping); } gidNameMap = gMap; lastUpdateTime = Time.monotonicNow(); }
synchronized private void loadFullUserMap() throws IOException { BiMap<Integer, String> uMap = HashBiMap.create(); if (OS.startsWith("Mac")) { updateMapInternal(uMap, "user", MAC_GET_ALL_USERS_CMD, "\\s+", staticMapping.uidMapping); } else { updateMapInternal(uMap, "user", GET_ALL_USERS_CMD, ":", staticMapping.uidMapping); } uidNameMap = uMap; lastUpdateTime = Time.monotonicNow(); }
@VisibleForTesting synchronized public void clearNameMaps() { uidNameMap.clear(); gidNameMap.clear(); lastUpdateTime = Time.monotonicNow(); }
/** * Log the current thread stacks at INFO level. * @param log the logger that logs the stack trace * @param title a descriptive title for the call stacks * @param minInterval the minimum time from the last */ public static void logThreadInfo(Log log, String title, long minInterval) { boolean dumpStack = false; if (log.isInfoEnabled()) { synchronized (ReflectionUtils.class) { long now = Time.monotonicNow(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title); log.info(buffer.toString(Charset.defaultCharset().name())); } catch (UnsupportedEncodingException ignored) { } } } }
/** * Log the current thread stacks at INFO level. * @param log the logger that logs the stack trace * @param title a descriptive title for the call stacks * @param minInterval the minimum time from the last */ public static void logThreadInfo(Logger log, String title, long minInterval) { boolean dumpStack = false; if (log.isInfoEnabled()) { synchronized (ReflectionUtils.class) { long now = Time.monotonicNow(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title); log.info(buffer.toString(Charset.defaultCharset().name())); } catch (UnsupportedEncodingException ignored) { } } } }
@Override CallReturn processWaitTimeAndRetryInfo() { final Long waitTime = getWaitTime(Time.monotonicNow()); LOG.trace("#{} processRetryInfo: waitTime={}", getCallId(), waitTime); if (waitTime != null && waitTime > 0) { return CallReturn.WAIT_RETRY; } processRetryInfo(); return CallReturn.RETRY; }
/** * Publish a metrics snapshot to all the sinks * @param buffer the metrics snapshot to publish * @param immediate indicates that we should publish metrics immediately * instead of using a separate thread. */ synchronized void publishMetrics(MetricsBuffer buffer, boolean immediate) { int dropped = 0; for (MetricsSinkAdapter sa : sinks.values()) { long startTime = Time.monotonicNow(); boolean result; if (immediate) { result = sa.putMetricsImmediate(buffer); } else { result = sa.putMetrics(buffer, logicalTime); } dropped += result ? 0 : 1; publishStat.add(Time.monotonicNow() - startTime); } droppedPubAll.incr(dropped); }
private void snapshotMetrics(MetricsSourceAdapter sa, MetricsBufferBuilder bufferBuilder) { long startTime = Time.monotonicNow(); bufferBuilder.add(sa.name(), sa.getMetrics(collector, true)); collector.clear(); snapshotStat.add(Time.monotonicNow() - startTime); LOG.debug("Snapshotted source "+ sa.name()); }
long checkCalls() { final long startTime = Time.monotonicNow(); long minWaitTime = Processor.MAX_WAIT_PERIOD; for (final Iterator<AsyncCall> i = queue.iterator(); i.hasNext();) { final AsyncCall c = i.next(); if (c.isDone()) { i.remove(); // the call is done, remove it from the queue. queue.checkEmpty(); } else { final Long waitTime = c.getWaitTime(startTime); if (waitTime != null && waitTime > 0 && waitTime < minWaitTime) { minWaitTime = waitTime; } } } return minWaitTime; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { long startTime = 0; if (LOG.isDebugEnabled()) { startTime = Time.monotonicNow(); } // if Tracing is on then start a new span for this rpc. // guard it in the if statement to make sure there isn't // any extra string manipulation. Tracer tracer = Tracer.curThreadTracer(); TraceScope traceScope = null; if (tracer != null) { traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method)); } ObjectWritable value; try { value = (ObjectWritable) client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args), remoteId, fallbackToSimpleAuth); } finally { if (traceScope != null) traceScope.close(); } if (LOG.isDebugEnabled()) { long callTime = Time.monotonicNow() - startTime; LOG.debug("Call: " + method.getName() + " " + callTime); } return value.get(); }