Java Code Examples for java.time.Duration#multipliedBy()

The following examples show how to use java.time.Duration#multipliedBy() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static Duration getNextAttemptDelay(Duration firstBackoff, Duration maxBackoff, int iteration) {
    Duration nextBackoff;
    try {
        nextBackoff = firstBackoff.multipliedBy((long) Math.pow(2, iteration));
        if (nextBackoff.compareTo(maxBackoff) > 0) {
            nextBackoff = maxBackoff;
        }
    } catch (ArithmeticException overflow) {
        nextBackoff = maxBackoff;
    }
    return nextBackoff;
}
 
Example 2
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 3
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 4
static Duration computeBackoff(long iteration, Duration minBackoff, Duration maxBackoff) {
    Duration nextBackoff;
    try {
        nextBackoff = minBackoff.multipliedBy((long) Math.pow(2, iteration));
        if (nextBackoff.compareTo(maxBackoff) > 0) {
            nextBackoff = maxBackoff;
        }
    } catch (ArithmeticException overflow) {
        nextBackoff = maxBackoff;
    }
    return nextBackoff;
}
 
Example 5
Source Project: ditto   File: BackOffActor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void backOff(final BackOffWithAnswer<?> backOffWithAnswer) {
    final Duration backOffTimeout = this.retryTimeoutStrategy.getNextTimeout();
    final Duration resetBackOffTimeout = backOffTimeout.multipliedBy(2L);

    log.debug("Going to back off for <{}> until sending answer: <{}>", backOffTimeout, backOffWithAnswer.getAnswer());

    this.getTimers().startSingleTimer(InternalTimers.BACK_OFF, new BackOffWithSender<>(getSender(), backOffWithAnswer), backOffTimeout);
    this.getTimers().startSingleTimer(InternalTimers.RESET_BACK_OFF, RESET_BACK_OFF, resetBackOffTimeout);
}
 
Example 6
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 7
Source Project: vespa   File: DelaySupplier.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Duration getDelay(int executionCount) {
    Duration nextDelay = startDelay;
    for (int i = 1; i < executionCount; ++i) {
        nextDelay = nextDelay.multipliedBy(2);
    }
    return maxDelay.compareTo(nextDelay) > 0 ? nextDelay : maxDelay;
}
 
Example 8
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("provider_multipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 9
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 10
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 11
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 12
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 13
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 14
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 15
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 16
Source Project: teku   File: Waiter.java    License: Apache License 2.0 4 votes vote down vote up
private static Duration nextPollInterval(final Duration duration) {
  final Duration nextInterval = duration.multipliedBy(2);
  return nextInterval.compareTo(MAX_POLL_INTERVAL) <= 0 ? nextInterval : MAX_POLL_INTERVAL;
}
 
Example 17
Source Project: hottub   File: TCKDuration.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 18
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 19
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 20
Source Project: groovy   File: DateTimeExtensions.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Supports the multiplication operator; equivalent to calling the {@link Duration#multipliedBy(long)} method.
 *
 * @param self   a Duration
 * @param scalar the value to multiply by
 * @return a Duration
 * @since 2.5.0
 */
public static Duration multiply(final Duration self, long scalar) {
    return self.multipliedBy(scalar);
}