@Override public void markReloaded() { lastReloaded.set(DateUtil.now()); LOGGER.trace("Marked reloaded on {}.", this); }
private boolean needsToForceMarketplaceCheck() { return lastSuccessfulMarketplaceCheck.get() .plus(FORCED_MARKETPLACE_CHECK_PERIOD) .isBefore(DateUtil.now()); }
@Override public void markReloaded(final T newValue) { final Duration newReload = reloadFunction.apply(newValue); lastReloaded.set(DateUtil.now()); reloadAfter.set(newReload); LOGGER.trace("Marked reloaded on {}, will be reloaded after {}.", this, newReload); }
@Override public boolean getAsBoolean() { final Instant lastReloadedInstant = lastReloaded.get(); return lastReloadedInstant == null || lastReloadedInstant.plus(reloadAfter.get()).isBefore(DateUtil.now()); }
@Override public boolean getAsBoolean() { final Instant lastReloadedInstant = lastReloaded.get(); return lastReloadedInstant == null || lastReloadedInstant.plus(reloadAfter).isBefore(DateUtil.now()); }
private static boolean isExpired(final Tuple2<Loan, Instant> p) { final Instant now = DateUtil.now(); final Instant expiration = p._2().plus(EVICT_AFTER); return expiration.isBefore(now); }
private static boolean isExpired(final Tuple2<Loan, Instant> p) { final Instant now = DateUtil.now(); final Instant expiration = p._2().plus(EVICT_AFTER); return expiration.isBefore(now); }
private void addLoan(final int loanId, final Loan loan) { storage.put(loanId, Tuple.of(loan, DateUtil.now())); }
private void addLoan(final int loanId, final Loan loan) { runLocked(() -> cache.get().put(loanId, Tuple.of(loan, DateUtil.now()))); }
private static String process(final Configuration configuration, final String embeddedTemplate, final Map<String, Object> embeddedData) throws IOException, TemplateException { final Map<String, Object> data = Maps.ofEntries( entry("timestamp", Date.from(DateUtil.now())), entry("robozonkyUrl", Defaults.ROBOZONKY_URL), entry("embed", embeddedTemplate), entry("data", embeddedData)); final Template template = configuration.getTemplate("core.ftl"); final StringWriter sw = new StringWriter(); template.process(data, sw); return sw.toString().trim(); }
private Collection<Investment> invest(final S strategy) { final MarketplaceAccessor<T> marketplaceAccessor = operationDescriptor.newMarketplaceAccessor(tenant); if (skipStrategyEvaluation(marketplaceAccessor)) { return Collections.emptyList(); } final Collection<T> marketplace = marketplaceAccessor.getMarketplace(); if (marketplace.isEmpty()) { logger.debug("Marketplace is empty."); return Collections.emptyList(); } logger.trace("Processing {} items from the marketplace.", marketplace.size()); final Collection<Investment> result = operationDescriptor.getOperation().apply(tenant, marketplace, strategy); lastSuccessfulMarketplaceCheck.set(DateUtil.now()); logger.trace("Marketplace processing complete."); return result; }
private static String process(final Configuration configuration, final String embeddedTemplate, final Map<String, Object> embeddedData) throws IOException, TemplateException { final Map<String, Object> data = Maps.ofEntries( entry("timestamp", Date.from(DateUtil.now())), entry("robozonkyUrl", Defaults.ROBOZONKY_URL), entry("embed", embeddedTemplate), entry("data", embeddedData)); final Template template = configuration.getTemplate("core.ftl"); final StringWriter sw = new StringWriter(); template.process(data, sw); return sw.toString().trim(); }
@Override public Either<Throwable, T> get() { Duration backoffTime = Duration.ZERO; final Instant startedOn = DateUtil.now(); do { wait(backoffTime); final Either<Throwable, T> result = execute(operation); if (result.isRight()) { LOGGER.trace("Success."); return Either.right(result.get()); } else if (startedOn.plus(cancelAfter).isBefore(DateUtil.now())) { LOGGER.trace("Expired."); return Either.left(result.getLeft()); } // need to try again backoffTime = backoffTimeCalculator.apply(backoffTime); } while (true); }
@Override public Either<Throwable, T> get() { Duration backoffTime = Duration.ZERO; final Instant startedOn = DateUtil.now(); do { wait(backoffTime); final Either<Throwable, T> result = execute(operation); if (result.isRight()) { LOGGER.trace("Success."); return Either.right(result.get()); } else if (startedOn.plus(cancelAfter).isBefore(DateUtil.now())) { LOGGER.trace("Expired."); return Either.left(result.getLeft()); } // need to try again backoffTime = backoffTimeCalculator.apply(backoffTime); } while (true); }
private static ZonkyApiToken getTokenExpiringIn(final Duration duration) { return new ZonkyApiToken(UUID.randomUUID().toString(), UUID.randomUUID().toString(), OffsetDateTime.ofInstant(DateUtil.now().minus(Duration.ofMinutes(5)).plus(duration), Defaults.ZONE_ID)); }
protected void skipAheadBy(final Duration duration) { final Instant next = DateUtil.now().plus(duration); setClock(Clock.fixed(next, Defaults.ZONE_ID)); }
@Test void replacesWithSynthetic() { SoftAssertions.assertSoftly(softly -> { softly.assertThat(DateUtil.now()).isEqualTo(INSTANT); softly.assertThat(DateUtil.localNow()).isEqualTo(LocalDateTime.ofInstant(INSTANT, Defaults.ZONE_ID)); softly.assertThat(DateUtil.offsetNow()).isEqualTo(OffsetDateTime.ofInstant(INSTANT, Defaults.ZONE_ID)); softly.assertThat(DateUtil.zonedNow()).isEqualTo(ZonedDateTime.ofInstant(INSTANT, Defaults.ZONE_ID)); }); }