public boolean hasLostContact() { return (clock.currentTimeMillis() - lastPingTime) >= (pingInterval * 2); }
@Override public String lookup(String key) { String staticResult = staticLookup.lookup(key); if(staticResult != null) { return staticResult; } if(key.equals("date")) { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(clock.currentTime()); } return null; }
public boolean hasExpired() { return expiryTime != null && expiryTime.isBefore(clock.currentDateTime()); }
public void readToEnd() { while (!completed) { try { clock.sleepForMillis(100); } catch (InterruptedException ignored) { } } }
public void setTimeout(Timeout timeout) { this.expiryTime = timeout == Timeout.NEVER ? null : clock.timeoutTime(timeout); }
public void perform(String url, FetchHandler handler) throws InterruptedException { int retryCount = 0; while (true) { retryCount++; String message = ""; try { int rc = download(httpService, url, handler); if (handler.handleResult(rc, goPublisher)) { return; } message = String.format("Unsuccessful response '%s' from the server", rc); } catch (Exception e) { message = String.format("Caught an exception '%s'", e.getMessage()); } if (retryCount > 3) { message = String.format("Giving up fetching resource '%s'. Tried 4 times and failed.", url); LOG.error(message); throw new RuntimeException(message); } long backout = Math.round(backout(retryCount)); publishDownloadError(url, message, backout); clock.sleepForSeconds(backout); } }
private int download(HttpService httpService, String url, FetchHandler handler) throws Exception { int returnCode = httpService.download(url, handler); while (returnCode == HttpServletResponse.SC_ACCEPTED) { clock.sleepForMillis(DOWNLOAD_SLEEP_MILLIS); returnCode = httpService.download(url, handler); } return returnCode; }
private void setTimeout(long milliSeconds) { this.expiryTime = milliSeconds == Timeout.NEVER.inMillis() ? null : clock.timeoutTime(milliSeconds); }
public void pingSuccess() { this.lastPingTime = clock.currentTimeMillis(); }
/** * @deprecated the JobInstance should not have a timeProvider. * Please pass in the date and remove this method */ public void changeState(JobState newState) { changeState(newState, timeProvider.currentTime()); }
public VersionInfo versionInfoForUpdate() { synchronized (VERSION_INFO_MUTEX) { if (isDevelopmentServer() || isVersionInfoUpdatedToday() || isUpdateInProgress()) return null; versionInfoUpdatingFrom = clock.currentDateTime(); LOGGER.info("[Go Update Check] Starting update check at: {}", new Date()); return this.serverVersionInfo; } }
private void start() { startTime = clock.currentTimeMillis(); }
public void completing(JobResult result) { completing(result, timeProvider.currentTime()); }
public Stage(String name, JobInstances jobInstances, String approvedBy, String cancelledBy, String approvalType, boolean fetchMaterials, boolean cleanWorkingDir, final Clock clock) { this.name = name; this.jobInstances = jobInstances; this.approvedBy = approvedBy; this.cancelledBy = cancelledBy; this.approvalType = approvalType; this.fetchMaterials = fetchMaterials; this.cleanWorkingDir = cleanWorkingDir; this.createdTime = new Timestamp(clock.currentTimeMillis()); }
public void schedule() { this.scheduledDate = timeProvider.currentTime(); changeState(JobState.Scheduled, this.scheduledDate); }
private void updateLastChangedTime() { LOGGER.info("[Configuration Changed] Security Configuration is changed. Updating the last changed time."); lastChangedTime = clock.currentTimeMillis(); }
private Long elapsedSeconds() { if (state.isCompleted()) { return durationOfCompletedBuildInSeconds(); } Date buildingDate = getStartedDateFor(JobState.Building); if (buildingDate != null) { long elapsed = timeProvider.currentTime().getTime() - buildingDate.getTime(); return (long) Math.round(elapsed / 1000); } else { return 0L; } }
private Long timeSinceLastLine(TimeUnit unit) { long now = clock.currentTimeMillis(); return unit.convert(now - lastHeard, TimeUnit.MILLISECONDS); }
public void fail() { Date completionDate = timeProvider.currentTime(); completing(JobResult.Failed, completionDate); completed(completionDate); }
private boolean isReportingInProgress() { if (reportingStartedTime == null) { return false; } DateTime halfHourAgo = new DateTime(clock.currentTimeMillis() - 30 * 60 * 1000); return reportingStartedTime.isAfter(halfHourAgo); }