APISonar


java.time.Duration.toNanos

> java > time > Duration > toNanos
java APIs time APIs Duration APIs toNanos APIs

Example 1
public void test_toNanos() {
        Duration test = Duration.ofSeconds(321, 123456789);
        assertEquals(test.toNanos(), 321123456789L);
    }
Example 2
public String toString(Duration value) {
		if ( value == null ) {
			return null;
		}
		return String.valueOf( value.toNanos() );
	}
Example 3
static boolean checkEpsilon(Duration d1, Duration d2, Duration epsilon) {
        if (d1.toNanos() <= d2.toNanos()) {
            return true;
        }
        Duration diff = d1.minus(d2).abs();
        return diff.compareTo(epsilon) <= 0;
    }
Example 4
public Duration createDelay(long attempt) {
        long value = randomBetween(base, Math.max(base, prevDelay * 3));
        Duration delay = applyBounds(Duration.ofNanos(targetTimeUnit.toNanos(value)), lower, upper);
        prevDelay = delay.toNanos();
        return delay;
    }
Example 5
private final Duration duration;

    public String toString() {
        if (duration.compareTo(Duration.ofMillis(1)) < 0) {
            return duration.toNanos() + " nanoseconds";
        } else {
            return dtf.format(this).trim();
        }
    }
Example 6
private final Duration reapingInterval;

    public void start()
    {
        if (scheduledExecutorService != null) {
            scheduledExecutorService.scheduleAtFixedRate(this::run, reapingInterval.toNanos(), reapingInterval.toNanos(), NANOSECONDS);
        }
    }
Example 7
public static LongSupplier nanosStartingFromNow(Duration timeout) {
    long end = System.nanoTime() + timeout.toNanos();
    return () -> end - System.nanoTime();
  }
Example 8
private void invokeFail(Object messageId, String streamId, Duration failLatency) {
    // delegate to user-defined methods
    spout.fail(messageId);

    // Invoke user-defined task hooks
    helper.getTopologyContext().invokeHookSpoutFail(messageId, failLatency);

    // Update metrics
    spoutMetrics.failedTuple(streamId, failLatency.toNanos());
  }
Example 9
public Mono<Void> rateLimitFor(Duration duration) {
        return Mono.fromRunnable(() -> {
            limitedUntil = System.nanoTime() + duration.toNanos();
        });
    }
Example 10
public boolean hasTimedOut( Duration timeout )
    {
        return elapsed( NANOSECONDS ) >= timeout.toNanos();
    }
Example 11
public final boolean awaitAndShutdown(Duration timeout) {
		long nanos = -1;
		if (!timeout.isNegative()) {
			nanos = timeout.toNanos();
		}
		try {
			shutdown();
			return executor.awaitTermination(nanos, TimeUnit.NANOSECONDS);
		} catch (InterruptedException ie) {
			Thread.currentThread().interrupt();
			return false;
		}
	}
Example 12
private Duration totalDuration = Duration.ZERO;

    private void printDuration(PrintStream out) {
        out.print(String.format("%dm", (totalDuration.toNanos() / ONE_MINUTE)));
        DecimalFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(locale));
        out.println(format.format(((double) (totalDuration.toNanos() % ONE_MINUTE) / ONE_SECOND)) + "s");
    }
Example 13
private void sleepFor(Duration duration) throws InterruptedException {
        if (shuttingDown.await(duration.toNanos(), TimeUnit.NANOSECONDS)) {
            throw new InterruptedException();
        }
    }
Example 14
static long toNanosSaturated(Duration duration) {
    // Using a try/catch seems lazy, but the catch block will rarely get invoked (except for
    // durations longer than approximately +/- 292 years).
    try {
      return duration.toNanos();
    } catch (ArithmeticException tooBig) {
      return duration.isNegative() ? Long.MIN_VALUE : Long.MAX_VALUE;
    }
  }
Example 15
private final Duration upper;

    public Duration createDelay(long attempt) {

        long upperTarget = targetTimeUnit.convert(upper.toNanos(), TimeUnit.NANOSECONDS);
        long temp = Math.min(upperTarget, base * calculatePowerOfTwo(attempt));
        long delay = temp / 2 + randomBetween(0, temp / 2);
        return applyBounds(Duration.ofNanos(targetTimeUnit.toNanos(delay)));
    }
Example 16
public DistributionStatisticConfigFilter setMaximumExpectedDuration(Duration maximumExpectedDuration) {
        this.maximumExpectedValue = maximumExpectedDuration.toNanos();
        return this;
    }
Example 17
public DistributionStatisticConfigFilter setMinimumExpectedDuration(Duration minimumExpectedDuration) {
        this.minimumExpectedValue = minimumExpectedDuration.toNanos();
        return this;
    }
Example 18
public FakeClock forward( Duration delta )
    {
        return forward( delta.toNanos(), TimeUnit.NANOSECONDS );
    }
Example 19
private final Duration              delay;

    protected boolean matchesSafely(Iterable<A> xs) {
        xs.forEach(__ -> clock.saveLastInstant());

        Boolean enoughDelay = all(d -> d.toNanos() > delay.toNanos(), map(boundaries -> {
            Iterator<Instant> it = boundaries.iterator();
            Instant first = it.next();
            Instant second = it.next();
            return between(first, second);
        }, slide(2, map(instants -> instants.iterator().next(), inGroupsOf(limit.intValue(), clock.instants())))));

        Boolean sameElements = all(Eq.<A>eq().uncurry(), zip(elements, xs));

        return enoughDelay && sameElements;
    }
Example 20
public final CompletionStage<V> getOrTimeout(Duration timeout, ScheduledExecutorService timeoutExecutor) {

        if (GATE_UPDATER.get(this) == GATE_OPEN && timeoutScheduleFuture == null) {
            this.timeoutScheduleFuture = timeoutExecutor.schedule(this::emit, timeout.toNanos(), TimeUnit.NANOSECONDS);
        }

        return selfFuture;
    }
Example 21
private Future<?> schedule(Map.Entry<T, Instant> entry) {
        Duration delay = Duration.between(Instant.now(), entry.getValue());
        long nanos = !delay.isNegative() ? delay.toNanos() : 0;
        try {
            return this.executor.schedule(this, nanos, TimeUnit.NANOSECONDS);
        } catch (RejectedExecutionException e) {
            return null;
        }
    }
Example 22
private final Duration timeout;

  private void onWriteComplete(Future<? super Void> future) {
    if (future.isSuccess()) {
      LOG.debug("[{}] Successfully wrote {}, waiting for response", logPrefix, this);
      if (timeout.toNanos() > 0) {
        timeoutFuture =
            channel
                .eventLoop()
                .schedule(this::fireTimeout, timeout.toNanos(), TimeUnit.NANOSECONDS);
        timeoutFuture.addListener(UncaughtExceptions::log);
      }
    } else {
      setFinalError(future.cause());
    }
  }
Example 23
private Duration delay;

  public RetryPolicy<R> withMaxDuration(Duration maxDuration) {
    Assert.notNull(maxDuration, "maxDuration");
    Assert.state(maxDuration.toNanos() > delay.toNanos(), "maxDuration must be greater than the delay");
    this.maxDuration = maxDuration;
    return this;
  }
Example 24
private Timeout scheduleTimeout(Duration timeoutDuration) {
    if (timeoutDuration.toNanos() > 0) {
      return this.timer.newTimeout(
          (Timeout timeout1) -> {
            setFinalError(new DriverTimeoutException("Query timed out after " + timeoutDuration));
            if (initialCallback != null) {
              initialCallback.cancel();
            }
          },
          timeoutDuration.toNanos(),
          TimeUnit.NANOSECONDS);
    } else {
      return null;
    }
  }
Example 25
protected boolean isFailure(ExecutionResult result) {
    long elapsedNanos = execution.getElapsedAttemptTime().toNanos();
    Duration timeout = policy.getTimeout();
    boolean timeoutExceeded = timeout != null && elapsedNanos >= timeout.toNanos();
    return timeoutExceeded || super.isFailure(result);
  }