/** * Set a new time for the renewal. * It can only be called when the action is not in the queue or any * collection because the hashCode may change * @param newTime the new time */ private void updateRenewalTime(long delay) { renewalTime = Time.now() + delay - delay/10; }
Call(int id, int retryCount, RPC.RpcKind kind, byte[] clientId, TraceScope traceScope, CallerContext callerContext) { this.callId = id; this.retryCount = retryCount; this.timestamp = Time.now(); this.rpcKind = kind; this.clientId = clientId; this.traceScope = traceScope; this.callerContext = callerContext; }
/** * Current system time. Do not use this to calculate a duration or interval * to sleep, because it will be broken by settimeofday. Instead, use * monotonicNow. * @return current time in msec. */ public long now() { return Time.now(); }
/** * This is the constructor with the signature needed by * {@link FileSystem#createFileSystem(URI, Configuration)} * * After this constructor is called initialize() is called. * @throws IOException */ public ViewFileSystem() throws IOException { ugi = UserGroupInformation.getCurrentUser(); creationTime = Time.now(); }
/** Get the delay until this event should happen. */ @Override public long getDelay(final TimeUnit unit) { final long millisLeft = renewalTime - Time.now(); return unit.convert(millisLeft, TimeUnit.MILLISECONDS); }
/** Update lastActivity with the current time. */ private void touch() { lastActivity.set(Time.now()); }
/** * Cause the current thread to sleep as close as possible to the provided * number of milliseconds. This method will log and ignore any * {@link InterruptedException} encountered. * * @param millis the number of milliseconds for the current thread to sleep */ public static void sleepAtLeastIgnoreInterrupts(long millis) { long start = Time.now(); while (Time.now() - start < millis) { long timeToSleep = millis - (Time.now() - start); try { Thread.sleep(timeToSleep); } catch (InterruptedException ie) { LOG.warn("interrupted while sleeping", ie); } } }
/** * @param parent {@link MetricsCollector} using this record builder * @param info metrics information * @param rf * @param mf * @param acceptable */ MetricsRecordBuilderImpl(MetricsCollector parent, MetricsInfo info, MetricsFilter rf, MetricsFilter mf, boolean acceptable) { this.parent = parent; timestamp = Time.now(); recInfo = info; metrics = Lists.newArrayList(); tags = Lists.newArrayList(); recordFilter = rf; metricFilter = mf; this.acceptable = acceptable; }
public ProtobufRpcEngineCallbackImpl() { this.server = currentCallInfo.get().server; this.call = Server.getCurCall().get(); this.methodName = currentCallInfo.get().methodName; this.setupTime = Time.now(); }
/** * puts selector back at the end of LRU list of free selectos. * Also invokes trimIdleSelectors(). * * @param info */ private synchronized void release(SelectorInfo info) { long now = Time.now(); trimIdleSelectors(now); info.lastActivityTime = now; info.queue.addLast(info); }
private synchronized void sendPing() throws IOException { long curTime = Time.now(); if ( curTime - lastActivity.get() >= pingInterval) { lastActivity.set(curTime); synchronized (ipcStreams.out) { ipcStreams.sendRequest(pingRequest); ipcStreams.flush(); } } }
@Override public void error(Throwable t) { long processingTime = Time.now() - setupTime; String detailedMetricsName = t.getClass().getSimpleName(); server.updateDeferredMetrics(detailedMetricsName, processingTime); call.setDeferredError(t); } }
private synchronized void removeExpiredKeys() { long now = Time.now(); for (Iterator<Map.Entry<Integer, DelegationKey>> it = allKeys.entrySet() .iterator(); it.hasNext();) { Map.Entry<Integer, DelegationKey> e = it.next(); if (e.getValue().getExpiryDate() < now) { it.remove(); // ensure the tokens generated by this current key can be recovered // with this current key after this current key is rolled if(!e.getValue().equals(currentKey)) removeStoredMasterKey(e.getValue()); } } }
/** Remove expired delegation tokens from cache */ private void removeExpiredToken() throws IOException { long now = Time.now(); Set<TokenIdent> expiredTokens = new HashSet<TokenIdent>(); synchronized (this) { Iterator<Map.Entry<TokenIdent, DelegationTokenInformation>> i = currentTokens.entrySet().iterator(); while (i.hasNext()) { Map.Entry<TokenIdent, DelegationTokenInformation> entry = i.next(); long renewDate = entry.getValue().getRenewDate(); if (renewDate < now) { expiredTokens.add(entry.getKey()); i.remove(); } } } // don't hold lock on 'this' to avoid edit log updates blocking token ops logExpireTokens(expiredTokens); }
@Override public void setResponse(Message message) { long processingTime = Time.now() - setupTime; call.setDeferredResponse(RpcWritable.wrap(message)); server.updateDeferredMetrics(methodName, processingTime); }
Connection register(SocketChannel channel) { if (isFull()) { return null; } Connection connection = new Connection(channel, Time.now()); add(connection); if (LOG.isDebugEnabled()) { LOG.debug("Server connection from " + connection + "; # active connections: " + size() + "; # queued calls: " + callQueue.size()); } return connection; }
public static void waitFor(Supplier<Boolean> check, int checkEveryMillis, int waitForMillis) throws TimeoutException, InterruptedException { long st = Time.now(); do { boolean result = check.get(); if (result) { return; } Thread.sleep(checkEveryMillis); } while (Time.now() - st < waitForMillis); throw new TimeoutException("Timed out waiting for condition. " + "Thread diagnostics:\n" + TimedOutTestsListener.buildThreadDiagnosticString()); }
synchronized void closeIdle(boolean scanAll) { long minLastContact = Time.now() - maxIdleTime; // concurrent iterator might miss new connections added // during the iteration, but that's ok because they won't // be idle yet anyway and will be caught on next scan int closed = 0; for (Connection connection : connections) { // stop if connections dropped below threshold unless scanning all if (!scanAll && size() < idleScanThreshold) { break; } // stop if not scanning all and max connections are closed if (connection.isIdle() && connection.getLastContact() < minLastContact && close(connection) && !scanAll && (++closed == maxIdleToClose)) { break; } } }
/** * Update the current master key for generating delegation tokens * It should be called only by tokenRemoverThread. */ void rollMasterKey() throws IOException { synchronized (this) { removeExpiredKeys(); /* set final expiry date for retiring currentKey */ currentKey.setExpiryDate(Time.now() + tokenMaxLifetime); /* * currentKey might have been removed by removeExpiredKeys(), if * updateMasterKey() isn't called at expected interval. Add it back to * allKeys just in case. */ updateDelegationKey(currentKey); } updateCurrentKey(); }
private void reloginFromKeytab(boolean checkTGT) throws IOException { if (!shouldRelogin() || !isFromKeytab()) { return; } HadoopLoginContext login = getLogin(); if (login == null) { throw new KerberosAuthException(MUST_FIRST_LOGIN_FROM_KEYTAB); } if (checkTGT) { KerberosTicket tgt = getTGT(); if (tgt != null && !shouldRenewImmediatelyForTests && Time.now() < getRefreshTime(tgt)) { return; } } relogin(login); }