public long getUptime() { if (leaderStartTime > 0) { return Time.currentElapsedTime() - leaderStartTime; } return 0; }
/** * Generates an initial sessionId. High order byte is serverId, next 5 * 5 bytes are from timestamp, and low order 2 bytes are 0s. */ public static long initializeNextSession(long id) { long nextSid; nextSid = (Time.currentElapsedTime() << 24) >>> 8; nextSid = nextSid | (id <<56); if (nextSid == EphemeralType.CONTAINER_EPHEMERAL_OWNER) { ++nextSid; // this is an unlikely edge case, but check it just in case } return nextSid; }
public long getUptime() { return Time.currentElapsedTime() - startTime; }
void updateNow() { now = Time.currentElapsedTime(); }
/** * @return milliseconds until next expiration time, or 0 if has already past */ public long getWaitTime() { long now = Time.currentElapsedTime(); long expirationTime = nextExpirationTime.get(); return now < expirationTime ? (expirationTime - now) : 0L; }
WorkerSender(int attempts) { super("WorkerSender"); maxAttempts = attempts; rand = new Random(java.lang.Thread.currentThread().getId() + Time.currentElapsedTime()); }
@Override public void doWork() throws Exception { long startTime = Time.currentElapsedTime(); listener.processDeadWatchers(snapshot); long latency = Time.currentElapsedTime() - startTime; LOG.info("Takes {} to process {} watches", latency, total); totalDeadWatchers.addAndGet(-total); synchronized(processingCompletedEvent) { processingCompletedEvent.notifyAll(); } } });
/** * This is to convert the elapsedTime to a Date. * @return A date object indicated by the elapsedTime. */ public static Date elapsedTimeToDate(long elapsedTime) { long wallTime = currentWallTime() + elapsedTime - currentElapsedTime(); return new Date(wallTime); } }
public ExpiryQueue(int expirationInterval) { this.expirationInterval = expirationInterval; nextExpirationTime.set(roundToNextInterval(Time.currentElapsedTime())); }
private static void waitByYielding(long delay) { long t0 = Time.currentElapsedTime(); while (Time.currentElapsedTime() < t0 + delay) { Thread.yield(); } }
private boolean hasSufficientTimeElapsed() { long now = Time.currentElapsedTime(); if (now - getLastLogin() < MIN_TIME_BEFORE_RELOGIN ) { LOG.warn("Not attempting to re-login since the last re-login was " + "attempted less than {} seconds before.", (MIN_TIME_BEFORE_RELOGIN / 1000)); return false; } // register most recent relogin attempt setLastLogin(now); return true; }
private static long discrepancy() { return (System.currentTimeMillis() - mt0) - (Time.currentElapsedTime() - nt0); }
synchronized public void waitForSyncConnected(long timeout) throws InterruptedException, TimeoutException { long expire = Time.currentElapsedTime() + timeout; long left = timeout; while(!syncConnected && left > 0) { wait(left); left = expire - Time.currentElapsedTime(); } if (!syncConnected) { throw new TimeoutException("Failed to connect to read-write ZooKeeper server."); } } synchronized public void waitForReadOnlyConnected(long timeout)
synchronized public void waitForDisconnected(long timeout) throws InterruptedException, TimeoutException { long expire = Time.currentElapsedTime() + timeout; long left = timeout; while(connected && left > 0) { wait(left); left = expire - Time.currentElapsedTime(); } if (connected) { throw new TimeoutException("Did not disconnect"); } } }
public void reportLookingSid(long sid) { if (maxTimeToWaitForEpoch < 0 || timeStartWaitForEpoch < 0 || !waitingForNewEpoch) { return; } if (voteSet == null || !voteSet.hasSid(sid)) { return; } if (Time.currentElapsedTime() - timeStartWaitForEpoch > maxTimeToWaitForEpoch) { quitLeading(); } }
/** check to see if a command needs to be executed and execute if needed */ protected void run() throws IOException { if (lastTime + interval > Time.currentElapsedTime()) return; exitCode = ExitCode.EXECUTION_FINISHED.getValue(); // reset for next run runCommand(); }
private void updateStats(Request request, String lastOp, long lastZxid) { if (request.cnxn == null) { return; } long currentTime = Time.currentElapsedTime(); zks.serverStats().updateLatency(request, currentTime); request.cnxn.updateStatsForResponse(request.cxid, lastZxid, lastOp, request.createTime, currentTime); } }
@Test public void testElapsedTimeToDate() throws Exception { long walltime = Time.currentWallTime(); long elapsedTime = Time.currentElapsedTime(); Thread.sleep(200); Calendar cal = Calendar.getInstance(); cal.setTime(Time.elapsedTimeToDate(elapsedTime)); int calculatedDate = cal.get(Calendar.HOUR_OF_DAY); cal.setTime(new Date(walltime)); int realDate = cal.get(Calendar.HOUR_OF_DAY); Assert.assertEquals(calculatedDate, realDate); } }
@Test public void testNextDoesNotSleepForZero() { byte size = 2; HostProvider hostProvider = getHostProvider(size); while (size > 0) { hostProvider.next(0); --size; } long start = Time.currentElapsedTime(); hostProvider.next(0); long stop = Time.currentElapsedTime(); assertTrue(5 > stop - start); }
@Test public void testNextGoesRoundAndSleeps() { byte size = 2; HostProvider hostProvider = getHostProvider(size); while (size > 0) { hostProvider.next(0); --size; } long start = Time.currentElapsedTime(); hostProvider.next(1000); long stop = Time.currentElapsedTime(); assertTrue(900 <= stop - start); }