private void tick() { currentInstant = currentInstant.plus( tickDuration ); } }
/** * @since 7.6 */ public static Instant addDays(Instant instant, int numberOfDays) { return instant.plus(numberOfDays, ChronoUnit.DAYS); }
/** * Adds a number of days to a date returning a new object. * The original date object is unchanged. * * @param date the date, not null * @param numberOfDays the amount to add, may be negative * @return the new date object with the amount added */ public static Date addDays(Date date, int numberOfDays) { return Date.from(date.toInstant().plus(numberOfDays, ChronoUnit.DAYS)); }
public void removeExpiredSessions(Instant now) { if (sessions.isEmpty()) { return; } if (this.lock.tryLock()) { try { Iterator<InMemoryWebSession> iterator = sessions.values().iterator(); while (iterator.hasNext()) { InMemoryWebSession session = iterator.next(); if (session.isExpired(now)) { iterator.remove(); session.invalidate(); } } } finally { this.checkTime = now.plus(CHECK_PERIOD, ChronoUnit.MILLIS); this.lock.unlock(); } } } }
private void countBytesWritten(int byteCount) { this.byteCount += byteCount; Instant now = instantSupplier.get(); if (previousCallback.plus(delayBetweenCallbacks).isBefore(now)) { callByteCountConsumer(now); } }
@Override protected void waitCondition() throws InterruptedException { if (lastInvocation!=null) times.sleepPast(lastInvocation.plus(CLEAN_SLEEP_TIME)); }
private void cleanUp() { Instant now = Instant.now(); if (lastCleanup.plus(cleanupInterval).isAfter(now)) { return; } lastCleanup = now; for (Entry<String, NotificationFilter> entry : getNotificationFilters().entrySet()) { if (entry.getValue() instanceof ExpiringNotificationFilter && ((ExpiringNotificationFilter) entry.getValue()).isExpired()) { LOGGER.debug("Expired filter '{}' removed", entry); filters.remove(entry.getKey()); } } }
private boolean lockLocally(KeyColumn lockID, StoreTransaction tx) { return lockLocally(lockID, times.getTime().plus(lockExpire), tx); }
/** * Wait until allocations are at 0, or the given duration elapses. */ protected void waitForDataBufferRelease(Duration duration) throws InterruptedException { Instant start = Instant.now(); while (Instant.now().isBefore(start.plus(duration))) { try { verifyAllocations(); break; } catch (AssertionError ex) { // ignore; } Thread.sleep(50); } }
private void sleepAndConvertInterrupts(Duration d) throws BackendException { try { times.sleepPast(times.getTime().plus(d)); } catch (InterruptedException e) { throw new PermanentBackendException(e); } }
/** * @param timeCtx the time context to use for time-based operations * @param maxDuration the maximum duration */ public TimeBoundedRetry(TimeContext timeCtx, Duration maxDuration) { mClock = timeCtx.getClock(); mSleeper = timeCtx.getSleeper(); mMaxDuration = maxDuration; mStartTime = mClock.instant(); mEndTime = mStartTime.plus(mMaxDuration); }
public static OAuth2AccessToken scopes(String... scopes) { return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "scopes", Instant.now(), Instant.now().plus(Duration.ofDays(1)), new HashSet<>(Arrays.asList(scopes))); } }
protected Mono<Void> sendReminders() { Instant now = Instant.now(); return Flux.fromIterable(this.reminders.values()) .filter(reminder -> reminder.getLastNotification().plus(reminderPeriod).isBefore(now)) .flatMap(reminder -> delegate.notify(reminder.getEvent()) .doOnSuccess(signal -> reminder.setLastNotification(now))) .then(); }
OpenState(CircuitBreakerStateMachine stateMachine, CircuitBreakerMetrics circuitBreakerMetrics) { super(stateMachine); final Duration waitDurationInOpenState = stateMachine.getCircuitBreakerConfig().getWaitDurationInOpenState(); this.retryAfterWaitDuration = Instant.now().plus(waitDurationInOpenState); this.circuitBreakerMetrics = circuitBreakerMetrics; if (stateMachine.getCircuitBreakerConfig().isAutomaticTransitionFromOpenToHalfOpenEnabled()) { AutoTransitioner.scheduleAutoTransition(stateMachine::transitionToHalfOpenState, waitDurationInOpenState); } }
public static OAuth2AccessToken noScopes() { return new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, "no-scopes", Instant.now(), Instant.now().plus(Duration.ofDays(1))); }
@Test public void validateWhenIssuedAt1minAheadAnd0minClockSkewThenHasErrors() { this.issuedAt = Instant.now().plus(Duration.ofMinutes(1)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(60)); this.clockSkew = Duration.ofMinutes(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.IAT)); }
@Test public void validateWhenExpiredAnd60secClockSkewThenNoErrors() { this.issuedAt = Instant.now().minus(Duration.ofSeconds(60)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(30)); this.clockSkew = Duration.ofSeconds(60); assertThat(this.validateIdToken()).isEmpty(); }
@Test public void validateWhenExpiredAnd0secClockSkewThenHasErrors() { this.issuedAt = Instant.now().minus(Duration.ofSeconds(60)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(30)); this.clockSkew = Duration.ofSeconds(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.EXP)); }
@Test public void validateWhenExpiresAtBeforeNowThenHasErrors() { this.issuedAt = Instant.now().minus(Duration.ofSeconds(10)); this.expiresAt = this.issuedAt.plus(Duration.ofSeconds(5)); this.clockSkew = Duration.ofSeconds(0); assertThat(this.validateIdToken()) .hasSize(1) .extracting(OAuth2Error::getDescription) .allMatch(msg -> msg.contains(IdTokenClaimNames.EXP)); }