Example usage for java.time Duration compareTo

List of usage examples for java.time Duration compareTo

Introduction

In this page you can find the example usage for java.time Duration compareTo.

Prototype

@Override
public int compareTo(Duration otherDuration) 

Source Link

Document

Compares this duration to the specified Duration .

Usage

From source file:nu.yona.server.analysis.service.ActivityUpdateService.java

private ZonedDateTime ensureMinimumDurationOneMinute(ActivityPayload payload) {
    Duration duration = Duration.between(payload.startTime, payload.endTime);
    if (duration.compareTo(ONE_MINUTE) < 0) {
        return payload.startTime.plus(ONE_MINUTE);
    }/*w w w . ja  va  2 s  .  c o  m*/
    return payload.endTime;
}

From source file:com.teradata.benchto.driver.listeners.BenchmarkServiceExecutionListener.java

private void checkClocksSync() {
    long timeBefore = System.currentTimeMillis();
    long serviceTime = benchmarkServiceClient.getServiceCurrentTime().toEpochMilli();
    long timeAfter = System.currentTimeMillis();

    long driftApproximation = Math.abs(LongMath.mean(timeBefore, timeAfter) - serviceTime);
    long approximationPrecision = timeAfter - LongMath.mean(timeBefore, timeAfter);

    Duration driftLowerBound = Duration.of(driftApproximation - approximationPrecision, ChronoUnit.MILLIS);

    if (driftLowerBound.compareTo(MAX_CLOCK_DRIFT) > 1) {
        throw new RuntimeException(
                format("Detected driver and service clocks drift of at least %s, assumed sane maximum is %s",
                        driftLowerBound, MAX_CLOCK_DRIFT));
    }//  w  w  w  .  j  a  v a  2s. c  om
}

From source file:org.janusgraph.graphdb.log.StandardTransactionLogProcessor.java

public StandardTransactionLogProcessor(StandardJanusGraph graph, Instant startTime) {
    Preconditions.checkArgument(graph != null && graph.isOpen());
    Preconditions.checkArgument(startTime != null);
    Preconditions.checkArgument(graph.getConfiguration().hasLogTransactions(),
            "Transaction logging must be enabled for recovery to work");
    Duration maxTxLength = graph.getConfiguration().getMaxCommitTime();
    if (maxTxLength.compareTo(MIN_TX_LENGTH) < 0)
        maxTxLength = MIN_TX_LENGTH;//w  ww.java  2 s  .com
    Preconditions.checkArgument(maxTxLength != null && !maxTxLength.isZero(),
            "Max transaction time cannot be 0");
    this.graph = graph;
    this.serializer = graph.getDataSerializer();
    this.times = graph.getConfiguration().getTimestampProvider();
    this.txLog = graph.getBackend().getSystemTxLog();
    this.persistenceTime = graph.getConfiguration().getMaxWriteTime();
    this.verboseLogging = graph.getConfiguration().getConfiguration()
            .get(GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY);
    this.txCache = CacheBuilder.newBuilder().concurrencyLevel(2).initialCapacity(100)
            .expireAfterWrite(maxTxLength.toNanos(), TimeUnit.NANOSECONDS)
            .removalListener(new RemovalListener<StandardTransactionId, TxEntry>() {
                @Override
                public void onRemoval(RemovalNotification<StandardTransactionId, TxEntry> notification) {
                    RemovalCause cause = notification.getCause();
                    Preconditions.checkArgument(cause == RemovalCause.EXPIRED,
                            "Unexpected removal cause [%s] for transaction [%s]", cause, notification.getKey());
                    TxEntry entry = notification.getValue();
                    if (entry.status == LogTxStatus.SECONDARY_FAILURE
                            || entry.status == LogTxStatus.PRIMARY_SUCCESS) {
                        failureTxCounter.incrementAndGet();
                        fixSecondaryFailure(notification.getKey(), entry);
                    } else {
                        successTxCounter.incrementAndGet();
                    }
                }
            }).build();

    ReadMarker start = ReadMarker.fromTime(startTime);
    this.txLog.registerReader(start, new TxLogMessageReader());

    cleaner = new BackgroundCleaner();
    cleaner.start();
}