/** * Updates the uptime history with the current uptime. Package access for testing. * * @param currentUptime the current uptime in seconds */ void updateUptimeHistory(long currentUptime) { String[] uptimes = ApplicationSettings.UPTIME_HISTORY.get(); // The first update in each session should append to the array if (firstUptimeUpdate.getAndSet(false)) uptimes = appendToHistory(uptimes, Long.toString(currentUptime)); else uptimes = updateHistory(uptimes, Long.toString(currentUptime)); ApplicationSettings.UPTIME_HISTORY.set(uptimes); }
@Override public void initialize() { // Increment the session counter int sessions = ApplicationSettings.SESSIONS.getValue(); ApplicationSettings.SESSIONS.setValue(sessions + 1); // Record the time between sessions long lastShutdown = ApplicationSettings.LAST_SHUTDOWN_TIME.getValue(); long downtime; if (lastShutdown == 0) downtime = DEFAULT_DOWNTIME; else downtime = Math.max(0, (clock.now() - lastShutdown) / 1000); // If the number of downtimes is greater that the number of uptimes, // the last session must have ended without recording the uptime or // shutdown time. To avoid double-counting the downtime we should // overwrite the last downtime instead of appending. String[] downtimes = ApplicationSettings.DOWNTIME_HISTORY.get(); String[] uptimes = ApplicationSettings.UPTIME_HISTORY.get(); if (downtimes.length > uptimes.length) downtimes = updateHistory(downtimes, Long.toString(downtime)); else downtimes = appendToHistory(downtimes, Long.toString(downtime)); ApplicationSettings.DOWNTIME_HISTORY.set(downtimes); // Measure the time between refreshes lastUpdateTime = clock.now(); }