/** * Schedule the given {@link Runnable}, starting as soon as possible and invoking it with * the given delay between the completion of one execution and the start of the next. * <p>Execution will end once the scheduler shuts down or the returned * {@link ScheduledFuture} gets cancelled. * @param task the Runnable to execute whenever the trigger fires * @param delay the delay between the completion of one execution and the start of the next * @return a {@link ScheduledFuture} representing pending completion of the task * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress) * @since 5.0 * @see #scheduleWithFixedDelay(Runnable, long) */ default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay) { return scheduleWithFixedDelay(task, delay.toMillis()); }
/** * Schedule the given {@link Runnable}, starting as soon as possible and * invoking it with the given period. * <p>Execution will end once the scheduler shuts down or the returned * {@link ScheduledFuture} gets cancelled. * @param task the Runnable to execute whenever the trigger fires * @param period the interval between successive executions of the task * @return a {@link ScheduledFuture} representing pending completion of the task * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress) * @since 5.0 * @see #scheduleAtFixedRate(Runnable, long) */ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) { return scheduleAtFixedRate(task, period.toMillis()); }
/** * Get a timer which is bound to this time instance and expires after the given timeout */ default Timer timer(Duration timeout) { return timer(timeout.toMillis()); } }
/** * Schedule the given {@link Runnable}, invoking it at the specified execution time * and subsequently with the given period. * <p>Execution will end once the scheduler shuts down or the returned * {@link ScheduledFuture} gets cancelled. * @param task the Runnable to execute whenever the trigger fires * @param startTime the desired first execution time for the task * (if this is in the past, the task will be executed immediately, i.e. as soon as possible) * @param period the interval between successive executions of the task * @return a {@link ScheduledFuture} representing pending completion of the task * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress) * @since 5.0 * @see #scheduleAtFixedRate(Runnable, Date, long) */ default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) { return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis()); }
/** * Schedule the given {@link Runnable}, invoking it at the specified execution time * and subsequently with the given delay between the completion of one execution * and the start of the next. * <p>Execution will end once the scheduler shuts down or the returned * {@link ScheduledFuture} gets cancelled. * @param task the Runnable to execute whenever the trigger fires * @param startTime the desired first execution time for the task * (if this is in the past, the task will be executed immediately, i.e. as soon as possible) * @param delay the delay between the completion of one execution and the start of the next * @return a {@link ScheduledFuture} representing pending completion of the task * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress) * @since 5.0 * @see #scheduleWithFixedDelay(Runnable, Date, long) */ default ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay) { return scheduleWithFixedDelay(task, Date.from(startTime), delay.toMillis()); }
private static long parseDelayAsLong(String value) throws RuntimeException { if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) { return Duration.parse(value).toMillis(); } return Long.parseLong(value); }
public LockManagerImpl( RagManager ragManager, Config config, Clock clock ) { this.ragManager = ragManager; this.clock = clock; this.lockAcquisitionTimeoutMillis = config.get( GraphDatabaseSettings.lock_acquisition_timeout ).toMillis(); }
/** * Sets the default connect timeout for new connections. A value of 0 means no timeout, * otherwise values must be between 1 and {@link Integer#MAX_VALUE} when converted to * milliseconds. * * <p>The connect timeout is applied when connecting a TCP socket to the target host. * The default value is 10 seconds. */ @IgnoreJRERequirement public Builder connectTimeout(Duration duration) { connectTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; }
/** * Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise * values must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds. * * <p>The write timeout is applied for individual write IO operations. * The default value is 10 seconds. * * @see Sink#timeout() */ @IgnoreJRERequirement public Builder writeTimeout(Duration duration) { writeTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; }
/** * Sets the default timeout for complete calls. A value of 0 means no timeout, otherwise values * must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds. * * <p>The call timeout spans the entire call: resolving DNS, connecting, writing the request * body, server processing, and reading the response body. If the call requires redirects or * retries all must complete within one timeout period. * * <p>The default value is 0 which imposes no timeout. */ @IgnoreJRERequirement public Builder callTimeout(Duration duration) { callTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; }
/** * Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise * values must be between 1 and {@link Integer#MAX_VALUE} when converted to milliseconds. * * <p>The read timeout is applied to both the TCP socket and for individual read IO operations * including on {@link Source} of the {@link Response}. The default value is 10 seconds. * * @see Socket#setSoTimeout(int) * @see Source#timeout() */ @IgnoreJRERequirement public Builder readTimeout(Duration duration) { readTimeout = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; }
/** * Sets the interval between HTTP/2 and web socket pings initiated by this client. Use this to * automatically send ping frames until either the connection fails or it is closed. This keeps * the connection alive and may detect connectivity failures. * * <p>If the server does not respond to each ping with a pong within {@code interval}, this * client will assume that connectivity has been lost. When this happens on a web socket the * connection is canceled and its listener is {@linkplain WebSocketListener#onFailure notified * of the failure}. When it happens on an HTTP/2 connection the connection is closed and any * calls it is carrying {@linkplain java.io.IOException will fail with an IOException}. * * <p>The default value of 0 disables client-initiated pings. */ @IgnoreJRERequirement public Builder pingInterval(Duration duration) { pingInterval = checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; }
private static long parseDelayAsLong(String value) throws RuntimeException { if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) { return Duration.parse(value).toMillis(); } return Long.parseLong(value); }
private void tryAcquire() throws InterruptedException, TimeoutException { if (!semaphore.tryAcquire(config.getMaxConcurrentRequestsTimeout().toMillis(), TimeUnit.MILLISECONDS)) { throw new TimeoutException( String.format( "Failed to acquire 1 permit of %d to send value in %s.", config.getMaxConcurrentRequests(), config.getMaxConcurrentRequestsTimeout() ) ); } }
private void waitForJobTermination( final RestClusterClient<ApplicationId> restClusterClient, final JobID jobId) throws Exception { stopJobSignal.signal(); final CompletableFuture<JobResult> jobResult = restClusterClient.requestJobResult(jobId); jobResult.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); }
protected static void waitUntilCondition(SupplierWithException<Boolean, Exception> condition, Deadline timeout) throws Exception { while (timeout.hasTimeLeft() && !condition.get()) { Thread.sleep(Math.min(RETRY_TIMEOUT, timeout.timeLeft().toMillis())); } if (!timeout.hasTimeLeft()) { throw new TimeoutException("Condition was not met in given timeout."); } }
@Test public void shouldWaitForRequestedVersion() throws Exception { // given long version = 5L; // when transactionIdTracker.awaitUpToDate( version, DEFAULT_DURATION ); // then verify( transactionIdStore ).awaitClosedTransactionId( version, DEFAULT_DURATION.toMillis() ); }
@Test void shouldParseTransactionTimeoutCorrectly() throws Throwable { // Given Map<String,Object> msgMetadata = map( "tx_timeout", 123456L ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When RunMessage runMessage = new RunMessage( "RETURN 1", EMPTY_MAP, meta ); // Then assertThat( runMessage.transactionTimeout().toMillis(), equalTo( 123456L ) ); } }
@Test void hasDefaultBookmarkAwaitTimeout() { Config config = Config.defaults(); long bookmarkReadyTimeoutMs = config.get( GraphDatabaseSettings.bookmark_ready_timeout ).toMillis(); assertEquals( TimeUnit.SECONDS.toMillis( 30 ), bookmarkReadyTimeoutMs ); }
@Test public void maxAge() { Duration maxAge = Duration.ofDays(365); String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis()); expires = expires.substring(0, expires.indexOf(":") + 1); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); }