@Override public int getMaxInactiveInterval() { return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS); }
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); long timeout = command.getTimeout().get(ChronoUnit.SECONDS); Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection()) ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)) : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))) .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new); return mappedMono.map(value -> new PopResponse(command, value)); })); }
@Override public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getDestination(), "Destination key must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination()) .map(value -> new ByteBufferResponse<>(command, value)); })); }
@JsonIgnore public synchronized String getSpeed() { if (startMoment != null) { long duration = Duration.between(startMoment, Instant.now()).get(ChronoUnit.SECONDS); return String.format("%d quads/s", duration > 0 ? numberOfTriplesProcessed / duration : numberOfTriplesProcessed); } return ""; } }
public ZonkyApiTokenSupplier(final ZonkyScope scope, final ApiProvider apis, final SecretProvider secrets, final Duration refreshAfter) { this.scope = scope; this.apis = apis; this.secrets = secrets; // fit refresh interval between 1 and 4 minutes final long refreshSeconds = Math.min(240, Math.max(60, refreshAfter.get(ChronoUnit.SECONDS) - 60)); LOGGER.debug("Token refresh may be attempted any time past {} seconds before expiration.", refreshSeconds); refresh = Duration.ofSeconds(refreshSeconds); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull public static String format (final @Nonnull Duration duration) { final long s = duration.get(ChronoUnit.SECONDS); final long hours = s / 3600; final long minutes = (s / 60) % 60; final long seconds = s % 60; return (hours == 0) ? String.format("%02d:%02d", minutes, seconds) : String.format("%02d:%02d:%02d", hours, minutes, seconds); }
@Override public long get(TemporalUnit temporalUnit) { return toJavaDuration().get(temporalUnit); }
private static Long parseTimeout(Object timeout) { if (timeout == null) { return null; } if (timeout instanceof String) { Duration duration = Duration.parse((CharSequence) timeout); return duration.get(ChronoUnit.SECONDS); } throw new IllegalArgumentException("Invalid process timeout value type: expected an ISO-8601 value, got: " + timeout); } }
java.time.Duration d = java.time.Duration.parse("PT1H2M34S"); System.out.println("Duration in seconds: " + d.get(java.time.temporal.ChronoUnit.SECONDS));
public FileDownloadEntity(SearchResultEntity searchResult, FileDownloadAccessType nzbAccessType, SearchSource accessSource, FileDownloadStatus status, String error) { this.searchResult = searchResult; this.nzbAccessType = nzbAccessType; this.accessSource = accessSource; this.status = status; this.time = Instant.now(); this.username = SessionStorage.username.get(); this.userAgent = SessionStorage.userAgent.get(); this.ip = SessionStorage.IP.get(); this.age = (int) (Duration.between(searchResult.getPubDate(), searchResult.getFirstFound()).get(ChronoUnit.SECONDS) / (24 * 60 * 60)); setError(error); }
@Override public long get(final TemporalUnit unit) { return period.getUnits().contains(unit) ? period.get(unit) : duration.get(unit); }
@Override public int getMaxInactiveInterval() { return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS); }
@Override public int getMaxInactiveInterval() { return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS); }
/** * If protected by CAPTCHA, gives the first instant when the CAPTCHA protection is over. * @return Present if loan protected by CAPTCHA, otherwise empty. */ public Optional<OffsetDateTime> getLoanCaptchaProtectionEndDateTime() { final Duration captchaDelay = loan.getRating().getCaptchaDelay(); if (captchaDelay.get(ChronoUnit.SECONDS) == 0) { return Optional.empty(); } else { return Optional.of(loan.getDatePublished().plus(captchaDelay)); } }
/** * If protected by CAPTCHA, gives the first instant when the CAPTCHA protection is over. * @return Present if loan protected by CAPTCHA, otherwise empty. */ public Optional<OffsetDateTime> getLoanCaptchaProtectionEndDateTime() { final Duration captchaDelay = loan.getRating().getCaptchaDelay(); if (captchaDelay.get(ChronoUnit.SECONDS) == 0) { return Optional.empty(); } else { return Optional.of(loan.getDatePublished().plus(captchaDelay)); } }
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); long timeout = command.getTimeout().get(ChronoUnit.SECONDS); Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection()) ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)) : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))) .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new); return mappedMono.map(value -> new PopResponse(command, value)); })); }
@Override public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKeys(), "Keys must not be null!"); Assert.notNull(command.getDirection(), "Direction must not be null!"); long timeout = command.getTimeout().get(ChronoUnit.SECONDS); Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection()) ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)) : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))) .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new); return mappedMono.map(value -> new PopResponse(command, value)); })); }
private void setFields(Duration duration, TextField textField, ComboBox<ChronoUnit> comboBox) { if (duration != null) { textField.setText(String.valueOf(duration.get(ChronoUnit.SECONDS))); comboBox.setValue(ChronoUnit.SECONDS); } else { textField.setText(null); comboBox.setValue(null); } }
@Override public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getDestination(), "Destination key must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination()) .map(value -> new ByteBufferResponse<>(command, value)); })); }
@Override public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) { return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> { Assert.notNull(command.getKey(), "Key must not be null!"); Assert.notNull(command.getDestination(), "Destination key must not be null!"); Assert.notNull(command.getTimeout(), "Timeout must not be null!"); return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination()) .map(value -> new ByteBufferResponse<>(command, value)); })); }